Skip to content

Commit

Permalink
datasource/alicloud_slb_zones: Supports new output parameters address…
Browse files Browse the repository at this point in the history
…_type and address_ip_version
  • Loading branch information
xiaozhu36 committed Jan 28, 2022
1 parent 63484cf commit 375b50c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
43 changes: 33 additions & 10 deletions alicloud/data_source_alicloud_slb_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func dataSourceAlicloudSlbZones() *schema.Resource {
Optional: true,
},
"enable_details": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeBool,
Optional: true,
Default: false,
Deprecated: "The parameter enable_details has been deprecated from version v1.154.0+",
},
"ids": {
Type: schema.TypeList,
Expand All @@ -54,6 +55,22 @@ func dataSourceAlicloudSlbZones() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"supported_resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address_type": {
Type: schema.TypeString,
Computed: true,
},
"address_ip_version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -81,13 +98,22 @@ func dataSourceAlicloudSlbZonesRead(d *schema.ResourceData, meta interface{}) er
}
addDebug(request.GetActionName(), raw, request.RpcRequest, request)
response, _ := raw.(*slb.DescribeAvailableResourceResponse)
supportedResources := make(map[string][]map[string]interface{})
for _, resource := range response.AvailableResources.AvailableResource {
slaveIds := slaveZones[resource.MasterZoneId]
slaveIds = append(slaveIds, resource.SlaveZoneId)
if len(slaveIds) > 0 {
sort.Strings(slaveIds)
}
slaveZones[resource.MasterZoneId] = slaveIds
supportedResourceList := make([]map[string]interface{}, 0)
for _, v := range resource.SupportResources.SupportResource {
supportedResourceList = append(supportedResourceList, map[string]interface{}{
"address_type": v.AddressType,
"address_ip_version": v.AddressIPVersion,
})
}
supportedResources[resource.MasterZoneId] = supportedResourceList
}

var ids []string
Expand All @@ -100,13 +126,10 @@ func dataSourceAlicloudSlbZonesRead(d *schema.ResourceData, meta interface{}) er

var s []map[string]interface{}
for _, zoneId := range ids {
mapping := map[string]interface{}{"id": zoneId}
if len(slaveZones) > 0 {
mapping["slb_slave_zone_ids"] = slaveZones[zoneId]
}
if !d.Get("enable_details").(bool) {
s = append(s, mapping)
continue
mapping := map[string]interface{}{
"id": zoneId,
"slb_slave_zone_ids": slaveZones[zoneId],
"supported_resources": supportedResources[zoneId],
}
s = append(s, mapping)
}
Expand Down
9 changes: 6 additions & 3 deletions alicloud/data_source_alicloud_slb_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ func TestAccAlicloudSlbZonesDataSource_basic(t *testing.T) {

var existSlbZonesMapFunc = func(rand int) map[string]string {
return map[string]string{
"ids.#": CHECKSET,
"zones.#": CHECKSET,
"zones.0.slb_slave_zone_ids.#": CHECKSET,
"ids.#": CHECKSET,
"zones.#": CHECKSET,
"zones.0.slb_slave_zone_ids.#": CHECKSET,
"zones.0.supported_resources.#": CHECKSET,
"zones.0.supported_resources.0.address_type": CHECKSET,
"zones.0.supported_resources.0.address_ip_version": CHECKSET,
}
}

Expand Down
11 changes: 9 additions & 2 deletions website/docs/d/slb_zones.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ data "alicloud_slb_zones" "zones_ids" {}
The following arguments are supported:

* `output_file` - (Optional) File name where to save data source results (after running `terraform plan`).
* `enable_details` - (Optional) Default to false and only output `id` in the `zones` block. Set it to true can output more details.
* `available_slb_address_type` - (Optional) Filter the results by a slb instance address type. Can be either `Vpc`, `classic_internet` or `classic_intranet`
* `enable_details` - (Deprecated from v1.154.0+) Default to false and only output `id` in the `zones` block. Set it to true can output more details.
* `available_slb_address_type` - (Optional) Filter the results by a slb instance network type. Valid values:
* vpc: an internal SLB instance that is deployed in a virtual private cloud (VPC).
* classic_internet: a public-facing SLB instance.
* classic_intranet: an internal SLB instance that is deployed in a classic network.

* `available_slb_address_ip_version` - (Optional) Filter the results by a slb instance address version. Can be either `ipv4`, or `ipv6`.

## Attributes Reference
Expand All @@ -37,4 +41,7 @@ The following attributes are exported in addition to the arguments listed above:
* `zones` - A list of availability zones. Each element contains the following attributes:
* `id` - ID of the zone.
* `slb_slave_zone_ids` - A list of slb slave zone ids in which the slb master zone.
* `supported_resources` - (Available in 1.154.0+)A list of available resource which the slb master zone supported.
* `address_type` - The type of network.
* `address_ip_version` - The type of IP address.

0 comments on commit 375b50c

Please sign in to comment.