From b6b9c90a1f95f91eb68fa606c92afa437e78f2aa Mon Sep 17 00:00:00 2001 From: sreekarbvibm <139211144+sreekarbvibm@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:31:30 +0530 Subject: [PATCH] add support for 4th zone (#5644) Co-authored-by: Ujjwal Kumar --- ibm/service/vpc/data_source_ibm_is_zone.go | 17 +++++++++ .../vpc/data_source_ibm_is_zone_test.go | 2 + ibm/service/vpc/data_source_ibm_is_zones.go | 38 +++++++++++++++++++ website/docs/d/is_zone.html.markdown | 2 + website/docs/d/is_zones.html.markdown | 6 +++ 5 files changed, 65 insertions(+) diff --git a/ibm/service/vpc/data_source_ibm_is_zone.go b/ibm/service/vpc/data_source_ibm_is_zone.go index fe89424be4..cf72e45143 100644 --- a/ibm/service/vpc/data_source_ibm_is_zone.go +++ b/ibm/service/vpc/data_source_ibm_is_zone.go @@ -14,6 +14,9 @@ const ( isZoneName = "name" isZoneRegion = "region" isZoneStatus = "status" + + isZoneDataCenter = "data_center" + isZoneUniversalName = "universal_name" ) func DataSourceIBMISZone() *schema.Resource { @@ -36,6 +39,14 @@ func DataSourceIBMISZone() *schema.Resource { Type: schema.TypeString, Computed: true, }, + isZoneDataCenter: { + Type: schema.TypeString, + Computed: true, + }, + isZoneUniversalName: { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -65,5 +76,11 @@ func zoneGet(d *schema.ResourceData, meta interface{}, regionName, zoneName stri d.Set(isZoneName, *zone.Name) d.Set(isZoneRegion, *zone.Region.Name) d.Set(isZoneStatus, *zone.Status) + if zone.DataCenter != nil { + d.Set(isZoneDataCenter, *zone.DataCenter) + } + if zone.UniversalName != nil { + d.Set(isZoneUniversalName, *zone.UniversalName) + } return nil } diff --git a/ibm/service/vpc/data_source_ibm_is_zone_test.go b/ibm/service/vpc/data_source_ibm_is_zone_test.go index cf7823abe7..6c064551fc 100644 --- a/ibm/service/vpc/data_source_ibm_is_zone_test.go +++ b/ibm/service/vpc/data_source_ibm_is_zone_test.go @@ -23,6 +23,8 @@ func TestAccIBMISZoneDataSource_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.ibm_is_zone.testacc_ds_zone", "name", acc.ISZoneName), resource.TestCheckResourceAttr("data.ibm_is_zone.testacc_ds_zone", "region", acc.RegionName), + resource.TestCheckResourceAttr("data.ibm_is_zone.testacc_ds_zone", "data_center", "DAL10"), + resource.TestCheckResourceAttr("data.ibm_is_zone.testacc_ds_zone", "universal_name", "us-south-dal10-a"), ), }, }, diff --git a/ibm/service/vpc/data_source_ibm_is_zones.go b/ibm/service/vpc/data_source_ibm_is_zones.go index 0772cb4108..0ce5d842f5 100644 --- a/ibm/service/vpc/data_source_ibm_is_zones.go +++ b/ibm/service/vpc/data_source_ibm_is_zones.go @@ -12,6 +12,7 @@ import ( const ( isZoneNames = "zones" + isZonesInfo = "zone_info" ) func DataSourceIBMISZones() *schema.Resource { @@ -35,6 +36,31 @@ func DataSourceIBMISZones() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + isZonesInfo: { + Type: schema.TypeList, + Computed: true, + Description: "The zones information in the region", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + isZoneName: { + Type: schema.TypeString, + Computed: true, + }, + isZoneUniversalName: { + Type: schema.TypeString, + Computed: true, + }, + isZoneDataCenter: { + Type: schema.TypeString, + Computed: true, + }, + isZoneStatus: { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, } } @@ -59,13 +85,25 @@ func zonesList(d *schema.ResourceData, meta interface{}, regionName string) erro } names := make([]string, 0) status := d.Get(isZoneStatus).(string) + zonesList := make([]map[string]interface{}, 0) for _, zone := range availableZones.Zones { + zoneInfo := map[string]interface{}{} if status == "" || *zone.Status == status { names = append(names, *zone.Name) + zoneInfo[isZoneName] = *zone.Name + zoneInfo[isZoneStatus] = *zone.Status + if zone.DataCenter != nil { + zoneInfo[isZoneDataCenter] = *zone.DataCenter + } + if zone.UniversalName != nil { + zoneInfo[isZoneUniversalName] = *zone.UniversalName + } } + zonesList = append(zonesList, zoneInfo) } d.SetId(dataSourceIBMISZonesId(d)) d.Set(isZoneNames, names) + d.Set(isZonesInfo, zonesList) return nil } diff --git a/website/docs/d/is_zone.html.markdown b/website/docs/d/is_zone.html.markdown index 68790a88fc..ee547e134f 100644 --- a/website/docs/d/is_zone.html.markdown +++ b/website/docs/d/is_zone.html.markdown @@ -41,3 +41,5 @@ Review the argument references that you can specify for your data source. In addition to all argument reference list, you can access the following attribute references after your data source is created. - `status` - (String) The status of the zone. +- `data_center` - (String) The physical data center assigned to this logical zone. If absent, no physical data center has been assigned. +- `universal_name` - (String) The universal name for this zone. Will be absent if this zone has a status of unassigned. diff --git a/website/docs/d/is_zones.html.markdown b/website/docs/d/is_zones.html.markdown index 057f859e6a..d23589d5e2 100644 --- a/website/docs/d/is_zones.html.markdown +++ b/website/docs/d/is_zones.html.markdown @@ -38,3 +38,9 @@ Review the argument references that you can specify for your data source. In addition to all argument reference list, you can access the following attribute references after your data source is created. - `zones` - (String) The list of zones in an IBM Cloud region. For example, **us-south-1**,**us-south-2**. +- `zone_info` - (List) Collection of zones. + Nested schema for **zone_info**: + - `data_center` - (String) The physical data center assigned to this logical zone. If absent, no physical data center has been assigned. + - `name` - (String) The name of the zone. + - `status` - (String) The status of the zone. + - `universal_name` - (String) The universal name for this zone. Will be absent if this zone has a status of unassigned.