From 2e7927e1c7b85e11550a8b6d8eb23d013795b921 Mon Sep 17 00:00:00 2001 From: wb-zln530580 Date: Wed, 11 Dec 2024 17:17:18 +0800 Subject: [PATCH] data-source/alicloud_ess_scaling_configurations: support attribute of instance_pattern_info. --- ...rce_alicloud_ess_scaling_configurations.go | 41 ++++++++++++ ...licloud_ess_scaling_configurations_test.go | 65 ++++++++++++------- alicloud/service_alicloud_ess.go | 11 ++-- .../ess_scaling_configurations.html.markdown | 10 +++ 4 files changed, 100 insertions(+), 27 deletions(-) diff --git a/alicloud/data_source_alicloud_ess_scaling_configurations.go b/alicloud/data_source_alicloud_ess_scaling_configurations.go index 63b0959b9cc5..5980619a21a5 100644 --- a/alicloud/data_source_alicloud_ess_scaling_configurations.go +++ b/alicloud/data_source_alicloud_ess_scaling_configurations.go @@ -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, + }, + }, + }, + }, }, }, }, @@ -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) diff --git a/alicloud/data_source_alicloud_ess_scaling_configurations_test.go b/alicloud/data_source_alicloud_ess_scaling_configurations_test.go index 27c05b362fd9..d57793c588aa 100644 --- a/alicloud/data_source_alicloud_ess_scaling_configurations_test.go +++ b/alicloud/data_source_alicloud_ess_scaling_configurations_test.go @@ -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, } } @@ -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" @@ -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"{ diff --git a/alicloud/service_alicloud_ess.go b/alicloud/service_alicloud_ess.go index 8f3474b9e3a4..a4f4f719311c 100644 --- a/alicloud/service_alicloud_ess.go +++ b/alicloud/service_alicloud_ess.go @@ -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) } diff --git a/website/docs/d/ess_scaling_configurations.html.markdown b/website/docs/d/ess_scaling_configurations.html.markdown index 4d67b25d9147..b02f3764efdb 100644 --- a/website/docs/d/ess_scaling_configurations.html.markdown +++ b/website/docs/d/ess_scaling_configurations.html.markdown @@ -11,6 +11,8 @@ description: |- This data source provides available scaling configuration resources. +-> **NOTE:** Available since v1.239.0+ + ## Example Usage ```terraform @@ -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.