Skip to content

Commit

Permalink
VPC ID Filter is added when Subnet Name is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
SunithaGudisagarIBM1 committed Oct 24, 2023
1 parent 1868057 commit ab78b73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ibm/service/vpc/data_source_ibm_is_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func DataSourceIBMISSubnet() *schema.Resource {
ValidateFunc: validate.InvokeDataSourceValidator("ibm_is_subnet", "identifier"),
},

// "vpc_id": {
// Type: schema.TypeString,
// Optional: true,
// RequiredWith: []string{isSubnetName},
// ValidateFunc: validate.InvokeDataSourceValidator("ibm_is_subnet", "identifier"),
// },

isSubnetIpv4CidrBlock: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -87,8 +94,11 @@ func DataSourceIBMISSubnet() *schema.Resource {
},

isSubnetVPC: {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
RequiredWith: []string{isSubnetName},
ValidateFunc: validate.InvokeDataSourceValidator("ibm_is_subnet", "identifier"),
},

isSubnetVPCName: {
Expand Down Expand Up @@ -229,11 +239,14 @@ func subnetGetByNameOrID(d *schema.ResourceData, meta interface{}) error {
start := ""
allrecs := []vpcv1.Subnet{}
getSubnetsListOptions := &vpcv1.ListSubnetsOptions{}

for {
if start != "" {
getSubnetsListOptions.Start = &start
}
if vpcIdOk, ok := d.GetOk(isSubnetVPC); ok {
vpcIDOk := vpcIdOk.(string)
getSubnetsListOptions.VPCID = &vpcIDOk
}
subnetsCollection, response, err := sess.ListSubnets(getSubnetsListOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error Fetching subnets List %s\n%s", err, response)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/is_subnet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Review the argument references that you can specify for your data source.

- `identifier` - (Optional, String) The ID of the subnet,`name` and `identifier` are mutually exclusive.
- `name` - (Optional, String) The name of the subnet,`name` and `identifier` are mutually exclusive.
- `vpc` - (Optional, String) Filters the collection to resources with a vpc property matching the specified identifier. Subnet `name` must be specified with `vpc` filter.

## Attribute reference
In addition to all argument reference list, you can access the following attribute references after your data source is created.
Expand Down

0 comments on commit ab78b73

Please sign in to comment.