Skip to content

Commit

Permalink
feat(routing-table-crn): UI 37487 routing table crn and SDK migration…
Browse files Browse the repository at this point in the history
… PR (#5708)

* SDK updated

* Development Resources

* Development Datasource

* datasource documentation

* resources documentation

* Added test case

* Added maturity

* RT issue

* Resource Group Support Added

* Removed SDK

---------

Co-authored-by: Ujjwal Kumar <[email protected]>
  • Loading branch information
SunithaGudisagarIBM1 and ujjwal-ibm authored Oct 18, 2024
1 parent 3c3af9b commit 2263156
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 20 deletions.
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"
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) {
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

0 comments on commit 2263156

Please sign in to comment.