Skip to content

Commit

Permalink
data-source/alicloud_ess_scaling_configurations: support attribute of…
Browse files Browse the repository at this point in the history
… instance_pattern_info.
  • Loading branch information
fuliu-zln committed Dec 25, 2024
1 parent ddcaa0e commit 2e7927e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 27 deletions.
41 changes: 41 additions & 0 deletions alicloud/data_source_alicloud_ess_scaling_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,46 @@ func dataSourceAlicloudEssScalingConfigurations() *schema.Resource {
},
Computed: true,
},
"instance_pattern_info": {
Computed: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_family_level": {
Type: schema.TypeString,
Computed: true,
},
"burstable_performance": {
Type: schema.TypeString,
Computed: true,
},
"excluded_instance_types": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"architectures": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
},
"cores": {
Type: schema.TypeInt,
Computed: true,
},
"memory": {
Type: schema.TypeFloat,
Computed: true,
},
"max_price": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -277,6 +317,7 @@ func scalingConfigurationsDescriptionAttribute(d *schema.ResourceData, scalingCo
"host_name": scalingConfiguration.HostName,
"spot_strategy": scalingConfiguration.SpotStrategy,
"spot_price_limit": essService.flattenSpotPriceLimitMappings(scalingConfiguration.SpotPriceLimit.SpotPriceModel),
"instance_pattern_info": essService.flattenInstancePatternInfoMappings(scalingConfiguration.InstancePatternInfos.InstancePatternInfo),
}
ids = append(ids, scalingConfiguration.ScalingConfigurationId)
names = append(names, scalingConfiguration.ScalingConfigurationName)
Expand Down
65 changes: 42 additions & 23 deletions alicloud/data_source_alicloud_ess_scaling_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,38 @@ func TestAccAlicloudEssScalingconfigurationsDataSource(t *testing.T) {

var existEssScalingconfigurationsMapFunc = func(rand int) map[string]string {
return map[string]string{
"ids.#": "1",
"names.#": "1",
"configurations.#": "1",
"configurations.0.name": fmt.Sprintf("tf-testAccDataSourceEssScalingRules-%d", rand),
"configurations.0.scaling_group_id": CHECKSET,
"configurations.0.image_id": CHECKSET,
"configurations.0.instance_type": CHECKSET,
"configurations.0.security_group_id": CHECKSET,
"configurations.0.creation_time": CHECKSET,
"configurations.0.system_disk_category": CHECKSET,
"configurations.0.system_disk_size": CHECKSET,
"configurations.0.system_disk_performance_level": "PL1",
"configurations.0.internet_max_bandwidth_in": CHECKSET,
"configurations.0.internet_max_bandwidth_out": CHECKSET,
"configurations.0.internet_charge_type": CHECKSET,
"configurations.0.data_disks.#": "0",
"configurations.0.instance_name": "instance_name",
"configurations.0.host_name": "hostname",
"configurations.0.spot_strategy": "SpotWithPriceLimit",
"configurations.0.spot_price_limit.#": "1",
"configurations.0.spot_price_limit.0.instance_type": CHECKSET,
"configurations.0.spot_price_limit.0.price_limit": "2.2",
"ids.#": "1",
"names.#": "1",
"configurations.#": "1",
"configurations.0.name": fmt.Sprintf("tf-testAccDataSourceEssScalingRules-%d", rand),
"configurations.0.scaling_group_id": CHECKSET,
"configurations.0.image_id": CHECKSET,
"configurations.0.instance_type": CHECKSET,
"configurations.0.security_group_id": CHECKSET,
"configurations.0.creation_time": CHECKSET,
"configurations.0.system_disk_category": CHECKSET,
"configurations.0.system_disk_size": CHECKSET,
"configurations.0.system_disk_performance_level": "PL1",
"configurations.0.internet_max_bandwidth_in": CHECKSET,
"configurations.0.internet_max_bandwidth_out": CHECKSET,
"configurations.0.internet_charge_type": CHECKSET,
"configurations.0.data_disks.#": "0",
"configurations.0.instance_name": "instance_name",
"configurations.0.host_name": "hostname",
"configurations.0.spot_strategy": "SpotWithPriceLimit",
"configurations.0.spot_price_limit.#": "1",
"configurations.0.spot_price_limit.0.instance_type": CHECKSET,
"configurations.0.spot_price_limit.0.price_limit": "2.2",
"configurations.0.instance_pattern_info.#": "1",
"configurations.0.instance_pattern_info.0.instance_family_level": "EntryLevel",
"configurations.0.instance_pattern_info.0.cores": "2",
"configurations.0.instance_pattern_info.0.memory": "8",
"configurations.0.instance_pattern_info.0.max_price": "2.2",
"configurations.0.instance_pattern_info.0.burstable_performance": "Include",
"configurations.0.instance_pattern_info.0.architectures.#": "1",
"configurations.0.instance_pattern_info.0.architectures.0": "X86",
"configurations.0.instance_pattern_info.0.excluded_instance_types.#": "1",
"configurations.0.instance_pattern_info.0.excluded_instance_types.0": CHECKSET,
}
}

Expand Down Expand Up @@ -122,7 +132,7 @@ resource "alicloud_ess_scaling_configuration" "default"{
image_id = "${data.alicloud_images.default.images.0.id}"
instance_type = "${data.alicloud_instance_types.default.instance_types.0.id}"
security_group_id = "${alicloud_security_group.default.id}"
system_disk_category = "cloud_essd"
system_disk_category = "cloud_ssd"
system_disk_performance_level = "PL1"
force_delete = true
instance_name = "instance_name"
Expand All @@ -132,6 +142,15 @@ resource "alicloud_ess_scaling_configuration" "default"{
instance_type = "${data.alicloud_instance_types.default.instance_types.0.id}"
price_limit = 2.2
}
instance_pattern_info {
instance_family_level = "EntryLevel"
cores = 2
memory = 8.0
max_price = 2.2
burstable_performance = "Include"
architectures = ["X86"]
excluded_instance_types = ["${data.alicloud_instance_types.default.instance_types.1.id}"]
}
}
data "alicloud_ess_scaling_configurations" "default"{
Expand Down
11 changes: 7 additions & 4 deletions alicloud/service_alicloud_ess.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,13 @@ func (s *EssService) flattenInstancePatternInfoMappings(list []ess.InstancePatte
memeory, _ := strconv.ParseFloat(strconv.FormatFloat(i.Memory, 'f', 2, 64), 64)
maxPrice, _ := strconv.ParseFloat(strconv.FormatFloat(i.MaxPrice, 'f', 2, 64), 64)
l := map[string]interface{}{
"instance_family_level": i.InstanceFamilyLevel,
"memory": memeory,
"cores": i.Cores,
"max_price": maxPrice,
"instance_family_level": i.InstanceFamilyLevel,
"memory": memeory,
"cores": i.Cores,
"max_price": maxPrice,
"burstable_performance": i.BurstablePerformance,
"architectures": i.Architectures.Architecture,
"excluded_instance_types": i.ExcludedInstanceTypes.ExcludedInstanceType,
}
result = append(result, l)
}
Expand Down
10 changes: 10 additions & 0 deletions website/docs/d/ess_scaling_configurations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |-

This data source provides available scaling configuration resources.

-> **NOTE:** Available since v1.239.0+

## Example Usage

```terraform
Expand Down Expand Up @@ -69,3 +71,11 @@ The following attributes are exported in addition to the arguments listed above:
* `spot_price_limit` - (Optional, Available in 1.151.0+) The maximum price hourly for instance types.
* `instance_type` - Resource type of an ECS instance.
* `price_limit` - Price limit hourly of instance type.
* `instance_pattern_info` - (Optional, Available since v1.239.0+) intelligent configuration mode. In this mode, you only need to specify the number of vCPUs, memory size, instance family, and maximum price. The system selects an instance type that is provided at the lowest price based on your configurations to create ECS instances. This mode is available only for scaling groups that reside in virtual private clouds (VPCs). This mode helps reduce the failures of scale-out activities caused by insufficient inventory of instance types.
* `cores` - The number of vCPUs that are specified for an instance type in instancePatternInfo.
* `instance_family_level` - The instance family level in instancePatternInfo.
* `max_price` - The maximum hourly price for a pay-as-you-go instance or a preemptible instance in instancePatternInfo.
* `memory` - The memory size that is specified for an instance type in instancePatternInfo.
* `burstable_performance` - Specifies whether to include burstable instance types. Valid values: Exclude, Include, Required.
* `excluded_instance_types` - Instance type N that you want to exclude. You can use wildcard characters, such as an asterisk (*), to exclude an instance type or an instance family.
* `architectures` - Architecture N of instance type N. Valid values: X86, Heterogeneous, BareMetal, Arm, SuperComputeCluster.

0 comments on commit 2e7927e

Please sign in to comment.