Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(routine-table): added support for crn in routing table #374

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7
github.com/IBM/vmware-go-sdk v0.1.2
github.com/IBM/vpc-beta-go-sdk v0.8.0
github.com/IBM/vpc-go-sdk v0.58.0
github.com/IBM/vpc-go-sdk v0.60.0
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5J
github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE=
github.com/IBM/vpc-go-sdk v0.58.0 h1:Slk1jkcV7tPnf0iECQV2Oja7W8Bom0z7k9M4fMBY4bI=
github.com/IBM/vpc-go-sdk v0.58.0/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
github.com/IBM/vpc-go-sdk v0.60.0 h1:4MD9dTmg+alJivsAEPmKE4qx59nv0Gsweju/XF+Z2jo=
github.com/IBM/vpc-go-sdk v0.60.0/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
github.com/Jeffail/gabs v1.1.1 h1:V0uzR08Hj22EX8+8QMhyI9sX2hwRu+/RJhJUmnwda/E=
github.com/Jeffail/gabs v1.1.1/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func DataSourceIBMISSubnet() *schema.Resource {
Computed: true,
Description: "The user-defined name for this routing table.",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "The crn for this routing table.",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -354,6 +359,9 @@ func dataSourceSubnetRoutingTableToMap(routingTableItem vpcv1.RoutingTableRefere
if routingTableItem.Name != nil {
routingTableMap["name"] = routingTableItem.Name
}
if routingTableItem.CRN != nil {
routingTableMap["crn"] = routingTableItem.CRN
}
if routingTableItem.ResourceType != nil {
routingTableMap["resource_type"] = routingTableItem.ResourceType
}
Expand Down
5 changes: 5 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func DataSourceIBMISSubnets() *schema.Resource {
Computed: true,
Description: "The user-defined name for this routing table.",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "The crn for this routing table.",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Expand Down
41 changes: 41 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpc_default_routing_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const (
isDefaultRoutingTableID = "default_routing_table"
isDefaultRoutingTableHref = "href"
isDefaultRoutingTableCrn = "crn"
isDefaultRoutingTableName = "name"
isDefaultRoutingTableResourceType = "resource_type"
isDefaultRoutingTableCreatedAt = "created_at"
Expand All @@ -24,6 +25,10 @@ const (
isDefaultRTTransitGatewayIngress = "route_transit_gateway_ingress"
isDefaultRTVPCZoneIngress = "route_vpc_zone_ingress"
isDefaultRTDefault = "is_default"
isDefaultRTResourceGroup = "resource_group"
isDefaultRTResourceGroupHref = "href"
isDefaultRTResourceGroupId = "id"
isDefaultRTResourceGroupName = "name"
)

func DataSourceIBMISVPCDefaultRoutingTable() *schema.Resource {
Expand All @@ -50,6 +55,11 @@ func DataSourceIBMISVPCDefaultRoutingTable() *schema.Resource {
Computed: true,
Description: "Default Routing table Name",
},
isDefaultRoutingTableCrn: {
Type: schema.TypeString,
Computed: true,
Description: "Default Routing table Crn",
},
isDefaultRoutingTableResourceType: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -128,6 +138,30 @@ func DataSourceIBMISVPCDefaultRoutingTable() *schema.Resource {
},
},
},
isDefaultRTResourceGroup: {
Type: schema.TypeList,
Computed: true,
Description: "The resource group for this volume.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isDefaultRTResourceGroupHref: {
Type: schema.TypeString,
Computed: true,
Description: "The URL for this resource group.",
},
isDefaultRTResourceGroupId: {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this resource group.",
},
isDefaultRTResourceGroupName: {
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this resource group.",
},
},
},
},
},
}
}
Expand All @@ -150,6 +184,7 @@ func dataSourceIBMISVPCDefaultRoutingTableGet(d *schema.ResourceData, meta inter
d.Set(isDefaultRoutingTableID, *result.ID)
d.Set(isDefaultRoutingTableHref, *result.Href)
d.Set(isDefaultRoutingTableName, *result.Name)
d.Set(isDefaultRoutingTableCrn, *result.CRN)
d.Set(isDefaultRoutingTableResourceType, *result.ResourceType)
createdAt := *result.CreatedAt
d.Set(isDefaultRoutingTableCreatedAt, createdAt.String())
Expand Down Expand Up @@ -181,6 +216,12 @@ func dataSourceIBMISVPCDefaultRoutingTableGet(d *schema.ResourceData, meta inter
}
}
d.Set(isDefaultRoutingTableRoutesList, routesInfo)
resourceGroupList := []map[string]interface{}{}
if result.ResourceGroup != nil {
resourceGroupMap := routingTableResourceGroupToMap(*result.ResourceGroup)
resourceGroupList = append(resourceGroupList, resourceGroupMap)
}
d.Set(isDefaultRTResourceGroup, resourceGroupList)
d.Set(isDefaultRTVpcID, vpcID)
d.SetId(*result.ID)
return nil
Expand Down
44 changes: 43 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_vpc_routing_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func DataSourceIBMIBMIsVPCRoutingTable() *schema.Resource {
Optional: true,
Description: "The routing table identifier.",
},

rtCrn: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The routing table CRN.",
},
"advertise_routes_to": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -194,6 +198,30 @@ func DataSourceIBMIBMIsVPCRoutingTable() *schema.Resource {
},
},
},
rtResourceGroup: {
Type: schema.TypeList,
Computed: true,
Description: "The resource group for this volume.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
rtResourceGroupHref: {
Type: schema.TypeString,
Computed: true,
Description: "The URL for this resource group.",
},
rtResourceGroupId: {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this resource group.",
},
rtResourceGroupName: {
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this resource group.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -311,6 +339,11 @@ func dataSourceIBMIBMIsVPCRoutingTableRead(context context.Context, d *schema.Re
if err = d.Set("advertise_routes_to", routingTable.AdvertiseRoutesTo); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting value of advertise_routes_to: %s", err))
}

if err = d.Set(rtCrn, routingTable.CRN); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting value of crn: %s", err))
}

routes := []map[string]interface{}{}
if routingTable.Routes != nil {
for _, modelItem := range routingTable.Routes {
Expand Down Expand Up @@ -339,6 +372,15 @@ func dataSourceIBMIBMIsVPCRoutingTableRead(context context.Context, d *schema.Re
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subnets %s", err))
}

resourceGroupList := []map[string]interface{}{}
if routingTable.ResourceGroup != nil {
resourceGroupMap := routingTableResourceGroupToMap(*routingTable.ResourceGroup)
resourceGroupList = append(resourceGroupList, resourceGroupMap)
}
if err = d.Set(rtResourceGroup, resourceGroupList); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource group %s", err))
}

return nil
}

Expand Down
41 changes: 41 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpc_routing_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
isRoutingTableAcceptRoutesFrom = "accept_routes_from"
isRoutingTableID = "routing_table"
isRoutingTableCrn = "routing_table_crn"
SunithaGudisagarIBM1 marked this conversation as resolved.
Show resolved Hide resolved
isRoutingTableHref = "href"
isRoutingTableName = "name"
isRoutingTableResourceType = "resource_type"
Expand Down Expand Up @@ -72,6 +73,11 @@ func DataSourceIBMISVPCRoutingTables() *schema.Resource {
Computed: true,
Description: "Routing Table ID",
},
isRoutingTableCrn: {
Type: schema.TypeString,
Computed: true,
Description: "The crn of routing table",
},
"advertise_routes_to": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -168,6 +174,30 @@ func DataSourceIBMISVPCRoutingTables() *schema.Resource {
},
},
},
rtResourceGroup: {
Type: schema.TypeList,
Computed: true,
Description: "The resource group for this volume.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
rtResourceGroupHref: {
Type: schema.TypeString,
Computed: true,
Description: "The URL for this resource group.",
},
rtResourceGroupId: {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this resource group.",
},
rtResourceGroupName: {
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this resource group.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -222,6 +252,9 @@ func dataSourceIBMISVPCRoutingTablesList(d *schema.ResourceData, meta interface{
if routingTable.ID != nil {
rtable[isRoutingTableID] = *routingTable.ID
}
if routingTable.CRN != nil {
rtable[isRoutingTableCrn] = *routingTable.CRN
}
if routingTable.Href != nil {
rtable[isRoutingTableHref] = *routingTable.Href
}
Expand Down Expand Up @@ -278,6 +311,14 @@ func dataSourceIBMISVPCRoutingTablesList(d *schema.ResourceData, meta interface{
}
}
rtable[isRoutingTableRoutesList] = routesInfo

resourceGroupList := []map[string]interface{}{}
if routingTable.ResourceGroup != nil {
resourceGroupMap := routingTableResourceGroupToMap(*routingTable.ResourceGroup)
resourceGroupList = append(resourceGroupList, resourceGroupMap)
}
rtable[rtResourceGroup] = resourceGroupList

vpcRoutingTables = append(vpcRoutingTables, rtable)
}

Expand Down
46 changes: 38 additions & 8 deletions ibm/service/vpc/resource_ibm_is_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
isSubnetDeleting = "deleting"
isSubnetDeleted = "done"
isSubnetRoutingTableID = "routing_table"
isSubnetRoutingTableCrn = "routing_table_crn"
isSubnetInUse = "resources_attached"
isSubnetAccessTags = "access_tags"
isUserTagType = "user"
Expand Down Expand Up @@ -183,13 +184,21 @@ func ResourceIBMISSubnet() *schema.Resource {
Description: "The resource group for this subnet",
},
isSubnetRoutingTableID: {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
Computed: true,
Description: "routing table id that is associated with the subnet",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{isSubnetRoutingTableCrn},
Computed: true,
Description: "routing table id that is associated with the subnet",
},
isSubnetRoutingTableCrn: {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Optional: true,
ConflictsWith: []string{isSubnetRoutingTableID},
Description: "routing table crn that is associated with the subnet.",
},

flex.ResourceControllerURL: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -309,15 +318,20 @@ func resourceIBMISSubnetCreate(d *schema.ResourceData, meta interface{}) error {
rtID = rt.(string)
}

err := subnetCreate(d, meta, name, vpc, zone, ipv4cidr, acl, gw, rtID, ipv4addrcount64)
rtCrn := ""
if rtcrn, ok := d.GetOk(isSubnetRoutingTableCrn); ok {
rtCrn = rtcrn.(string)
}

err := subnetCreate(d, meta, name, vpc, zone, ipv4cidr, acl, gw, rtID, rtCrn, ipv4addrcount64)
if err != nil {
return err
}

return resourceIBMISSubnetRead(d, meta)
}

func subnetCreate(d *schema.ResourceData, meta interface{}, name, vpc, zone, ipv4cidr, acl, gw, rtID string, ipv4addrcount64 int64) error {
func subnetCreate(d *schema.ResourceData, meta interface{}, name, vpc, zone, ipv4cidr, acl, gw, rtID, rtCrn string, ipv4addrcount64 int64) error {

sess, err := vpcClient(meta)
if err != nil {
Expand Down Expand Up @@ -355,6 +369,12 @@ func subnetCreate(d *schema.ResourceData, meta interface{}, name, vpc, zone, ipv
ID: &rt,
}
}
if rtCrn != "" {
subnetTemplate.RoutingTable = &vpcv1.RoutingTableIdentity{
CRN: &rtCrn,
}
}

rg := ""
if grp, ok := d.GetOk(isSubnetResourceGroup); ok {
rg = grp.(string)
Expand Down Expand Up @@ -474,8 +494,10 @@ func subnetGet(d *schema.ResourceData, meta interface{}, id string) error {
}
if subnet.RoutingTable != nil {
d.Set(isSubnetRoutingTableID, *subnet.RoutingTable.ID)
d.Set(isSubnetRoutingTableCrn, *subnet.RoutingTable.CRN)
} else {
d.Set(isSubnetRoutingTableID, nil)
d.Set(isSubnetRoutingTableCrn, nil)
}
d.Set(isSubnetStatus, *subnet.Status)
d.Set(isSubnetZone, *subnet.Zone.Name)
Expand Down Expand Up @@ -613,6 +635,14 @@ func subnetUpdate(d *schema.ResourceData, meta interface{}, id string) error {
return err
}*/
}
if d.HasChange(isSubnetRoutingTableCrn) {
SunithaGudisagarIBM1 marked this conversation as resolved.
Show resolved Hide resolved
hasChanged = true
rtCrn := d.Get(isSubnetRoutingTableCrn).(string)
// Construct an instance of the RoutingTableIdentityByCRN model
routingTableIdentityModel := new(vpcv1.RoutingTableIdentityByCRN)
routingTableIdentityModel.CRN = &rtCrn
subnetPatchModel.RoutingTable = routingTableIdentityModel
}
if hasChanged {
subnetPatch, err := subnetPatchModel.AsPatch()
if err != nil {
Expand Down
Loading
Loading