Skip to content

Commit

Permalink
add support for 4th zone (IBM-Cloud#5644)
Browse files Browse the repository at this point in the history
Co-authored-by: Ujjwal Kumar <ujjwal.kumar1@ibm.com>
  • Loading branch information
2 people authored and Ramya-c4 committed Sep 26, 2024
1 parent e96fad0 commit 1638e41
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const (
isZoneName = "name"
isZoneRegion = "region"
isZoneStatus = "status"

isZoneDataCenter = "data_center"
isZoneUniversalName = "universal_name"
)

func DataSourceIBMISZone() *schema.Resource {
Expand All @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
38 changes: 38 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const (
isZoneNames = "zones"
isZonesInfo = "zone_info"
)

func DataSourceIBMISZones() *schema.Resource {
Expand All @@ -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,
},
},
},
},
},
}
}
Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/is_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 6 additions & 0 deletions website/docs/d/is_zones.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 1638e41

Please sign in to comment.