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 26, 2024
1 parent 25f7256 commit a72b929
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 34 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 @@ -504,10 +504,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
100 changes: 93 additions & 7 deletions website/docs/d/ess_scaling_configurations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,95 @@ description: |-

This data source provides available scaling configuration resources.

-> **NOTE:** Available since v1.240.0

## Example Usage

```terraform
variable "name" {
default = "terraform-example"
}
resource "random_integer" "default" {
min = 10000
max = 99999
}
locals {
name = "${var.name}-${random_integer.default.result}"
}
data "alicloud_zones" "default" {
available_disk_category = "cloud_efficiency"
available_resource_creation = "VSwitch"
}
data "alicloud_instance_types" "default" {
availability_zone = data.alicloud_zones.default.zones[0].id
cpu_core_count = 2
memory_size = 4
}
data "alicloud_images" "default" {
name_regex = "^ubuntu_18.*64"
most_recent = true
owners = "system"
}
resource "alicloud_vpc" "default" {
vpc_name = local.name
cidr_block = "172.16.0.0/16"
}
resource "alicloud_vswitch" "default" {
vpc_id = alicloud_vpc.default.id
cidr_block = "172.16.0.0/24"
zone_id = data.alicloud_zones.default.zones[0].id
vswitch_name = local.name
}
resource "alicloud_security_group" "default" {
security_group_name = local.name
vpc_id = alicloud_vpc.default.id
}
resource "alicloud_security_group_rule" "default" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "22/22"
priority = 1
security_group_id = alicloud_security_group.default.id
cidr_ip = "172.16.0.0/24"
}
resource "alicloud_ess_scaling_group" "default" {
min_size = 1
max_size = 1
scaling_group_name = local.name
removal_policies = ["OldestInstance", "NewestInstance"]
vswitch_ids = [alicloud_vswitch.default.id]
}
resource "alicloud_ess_scaling_configuration" "default" {
scaling_group_id = alicloud_ess_scaling_group.default.id
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
force_delete = true
active = true
scaling_configuration_name = "scaling_configuration_name"
}
data "alicloud_ess_scaling_configurations" "scalingconfigurations_ds" {
scaling_group_id = "scaling_group_id"
ids = ["scaling_configuration_id1", "scaling_configuration_id2"]
scaling_group_id = alicloud_ess_scaling_group.default.id
ids = [alicloud_ess_scaling_configuration.default.id]
name_regex = "scaling_configuration_name"
}
output "first_scaling_rule" {
value = "${data.alicloud_ess_scaling_configurations.scalingconfigurations_ds.configurations.0.id}"
value = data.alicloud_ess_scaling_configurations.scalingconfigurations_ds.configurations.0.id
}
```

Expand Down Expand Up @@ -63,9 +141,17 @@ The following attributes are exported in addition to the arguments listed above:
* `performance_level` - The performance level of the ESSD used as data disk.
* `lifecycle_state` - Lifecycle state of the scaling configuration.
* `creation_time` - Creation time of the scaling configuration.
* `instance_name` - (Optional,Available in 1.143.0+) InstanceName of an ECS instance.
* `host_name` - (Optional,Available in 1.143.0+) Hostname of an ECS instance.
* `spot_strategy` - (Optional, Available in 1.151.0+) The spot strategy for a Pay-As-You-Go instance.
* `spot_price_limit` - (Optional, Available in 1.151.0+) The maximum price hourly for instance types.
* `instance_name` - (Optional,Available since v1.143.0) InstanceName of an ECS instance.
* `host_name` - (Optional,Available since v1.143.0) Hostname of an ECS instance.
* `spot_strategy` - (Optional, Available since v1.151.0) The spot strategy for a Pay-As-You-Go instance.
* `spot_price_limit` - (Optional, Available since v1.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.240.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 a72b929

Please sign in to comment.