Skip to content

Commit

Permalink
add support for 4th zone
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Sep 18, 2024
1 parent 2aa2176 commit c5cf48a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6
github.com/IBM/vmware-go-sdk v0.1.2
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.57.0
github.com/IBM/vpc-go-sdk v0.58.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
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,14 @@ github.com/IBM/scc-go-sdk/v5 v5.4.1 h1:RXIuxOo9/hxkWyHCI69ae+KIJgSbXcAkJwTEl+fO3
github.com/IBM/scc-go-sdk/v5 v5.4.1/go.mod h1:2xQTDgNXG5QMEfQxBDKB067z+5ha6OgcaKCTcdGDAo8=
github.com/IBM/schematics-go-sdk v0.2.3 h1:lgTt0Sbudii3cuSk1YSQgrtiZAXDbBABAoVj3eQuBrU=
github.com/IBM/schematics-go-sdk v0.2.3/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5 h1:VMc/Zd6RzB8j60CqZekkwYT2wQsCfrkGV2n01Gviuaw=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5/go.mod h1:5kUgJ1dG9cdiAcPDqVz46m362bPnoqZQSth24NiowSg=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6 h1:bF6bAdI4wDZSje6+Yx1mJxvirboxO+uMuKhzgfRCNxE=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6/go.mod h1:XWYnbcc5vN1RnKwk/fCzfD8aZd7At/Y1/b6c+oDyliU=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
github.com/IBM/vpc-beta-go-sdk v0.6.0/go.mod h1:fzHDAQIqH/5yJmYsKodKHLcqxMDT+yfH6vZjdiw8CQA=
github.com/IBM/vpc-go-sdk v0.57.0 h1:E8CPDpUE4z0cvvmFZzqUthMtGJx71Fne6vdvkjZdXfg=
github.com/IBM/vpc-go-sdk v0.57.0/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
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/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
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 c5cf48a

Please sign in to comment.