Skip to content

Commit

Permalink
Resource Group Support Added
Browse files Browse the repository at this point in the history
  • Loading branch information
SunithaGudisagarIBM1 committed Oct 7, 2024
1 parent aa757c5 commit 046ac2b
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 3 deletions.
4 changes: 1 addition & 3 deletions 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 Expand Up @@ -245,5 +245,3 @@ exclude (
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/client-go v12.0.0+incompatible
)

replace github.com/IBM/vpc-go-sdk v0.55.0 => ./common/github.com/IBM/vpc-go-sdk
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
34 changes: 34 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 @@ -25,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 Down Expand Up @@ -134,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 Down Expand Up @@ -188,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
33 changes: 33 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpc_routing_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,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 @@ -348,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
32 changes: 32 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 @@ -174,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 @@ -287,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
32 changes: 32 additions & 0 deletions ibm/service/vpc/resource_ibm_is_subnet_routing_table_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ func ResourceIBMISSubnetRoutingTableAttachment() *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 @@ -224,6 +248,14 @@ func resourceIBMISSubnetRoutingTableAttachmentRead(context context.Context, d *s
routes = append(routes, route)
}
d.Set(rtRoutes, routes)

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

return nil
}

Expand Down
51 changes: 51 additions & 0 deletions ibm/service/vpc/resource_ibm_is_vpc_routing_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
rtNextHop = "next_hop"
rtZone = "zone"
rtOrigin = "origin"
rtResourceGroup = "resource_group"
rtResourceGroupHref = "href"
rtResourceGroupId = "id"
rtResourceGroupName = "name"
)

func ResourceIBMISVPCRoutingTable() *schema.Resource {
Expand Down Expand Up @@ -162,6 +166,30 @@ func ResourceIBMISVPCRoutingTable() *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 @@ -313,9 +341,32 @@ func resourceIBMISVPCRoutingTableRead(d *schema.ResourceData, meta interface{})

d.Set(rtSubnets, subnets)

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

return nil
}

func routingTableResourceGroupToMap(resourceGroupItem vpcv1.ResourceGroupReference) (resourceGroupMap map[string]interface{}) {
resourceGroupMap = map[string]interface{}{}

if resourceGroupItem.Href != nil {
resourceGroupMap[isVolumesResourceGroupHref] = resourceGroupItem.Href
}
if resourceGroupItem.ID != nil {
resourceGroupMap[isVolumesResourceGroupId] = resourceGroupItem.ID
}
if resourceGroupItem.Name != nil {
resourceGroupMap[isVolumesResourceGroupName] = resourceGroupItem.Name
}

return resourceGroupMap
}

func resourceIBMISVPCRoutingTableUpdate(d *schema.ResourceData, meta interface{}) error {
sess, err := vpcClient(meta)
if err != nil {
Expand Down

0 comments on commit 046ac2b

Please sign in to comment.