Skip to content

Commit

Permalink
enhancement(is_region): made name as optional in ibm_is_region dataso…
Browse files Browse the repository at this point in the history
…urce
  • Loading branch information
uibm committed Mar 3, 2022
1 parent 7cfc9b6 commit d174b47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package vpc

import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -27,7 +28,7 @@ func DataSourceIBMISRegion() *schema.Resource {

isRegionName: {
Type: schema.TypeString,
Required: true,
Optional: true,
},

isRegionStatus: {
Expand All @@ -41,6 +42,13 @@ func DataSourceIBMISRegion() *schema.Resource {
func dataSourceIBMISRegionRead(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)

if name == "" {
bmxSess, err := meta.(conns.ClientSession).BluemixSession()
if err != nil {
return err
}
name = bmxSess.Config.Region
}
return regionGet(d, meta, name)
}

Expand Down
6 changes: 5 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestAccIBMISRegionDataSource_basic(t *testing.T) {
Config: testAccCheckIBMISRegionDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ibm_is_region.testacc_ds_region", "name", acc.RegionName),
resource.TestCheckResourceAttr("data.ibm_is_region.testacc_default_region", "name", acc.RegionName),
),
},
},
Expand All @@ -33,6 +34,9 @@ func testAccCheckIBMISRegionDataSourceConfig() string {
data "ibm_is_region" "testacc_ds_region" {
name = "%s"
}`, acc.RegionName)
}
data "ibm_is_region" "testacc_default_region" {
}
`, acc.RegionName)

}
10 changes: 9 additions & 1 deletion website/docs/d/is_region.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ data "ibm_is_region" "example" {
}
```

```terraform
data "ibm_is_region" "default_region" {
}
```

## Argument reference
Review the argument references that you can specify for your data source.

- `name` - (Required, String) The name of the region.
- `name` - (Optional, String) The name of the region. If no `name` is provided then default region `name` is taken from the provider block.

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

0 comments on commit d174b47

Please sign in to comment.