diff --git a/alicloud/resource_alicloud_ess_scaling_configuration.go b/alicloud/resource_alicloud_ess_scaling_configuration.go index 26cc910d4078..5bd026c16d52 100644 --- a/alicloud/resource_alicloud_ess_scaling_configuration.go +++ b/alicloud/resource_alicloud_ess_scaling_configuration.go @@ -135,7 +135,7 @@ func resourceAlicloudEssScalingConfiguration() *schema.Resource { "internet_max_bandwidth_in": { Type: schema.TypeInt, Optional: true, - Computed: true, + ForceNew: true, }, "spot_duration": { Type: schema.TypeInt, @@ -425,6 +425,37 @@ func resourceAlicloudEssScalingConfiguration() *schema.Resource { }, }, }, + "network_interfaces": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: StringInSlice([]string{"Primary", "Secondary"}, false), + }, + "network_interface_traffic_mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: StringInSlice([]string{"Standard", "HighPerformance"}, false), + }, + "ipv6_address_count": { + Type: schema.TypeInt, + Optional: true, + }, + "security_group_ids": { + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + }, + }, + }, + }, }, } } @@ -683,6 +714,27 @@ func resourceAliyunEssScalingConfigurationCreate(d *schema.ResourceData, meta in } request["InstancePatternInfo"] = instancePatternInfosMaps } + + if v, ok := d.GetOk("network_interfaces"); ok { + networkInterfacesMaps := make([]map[string]interface{}, 0) + networkInterfaces := v.(*schema.Set).List() + for _, rew := range networkInterfaces { + networkInterfacesMap := make(map[string]interface{}) + item := rew.(map[string]interface{}) + + if instanceType, ok := item["instance_type"].(string); ok && instanceType != "" { + networkInterfacesMap["InstanceType"] = instanceType + } + if networkInterfaceTrafficMode, ok := item["network_interface_traffic_mode"].(string); ok && networkInterfaceTrafficMode != "" { + networkInterfacesMap["NetworkInterfaceTrafficMode"] = networkInterfaceTrafficMode + } + networkInterfacesMap["Ipv6AddressCount"] = item["ipv6_address_count"].(int) + networkInterfacesMap["SecurityGroupIds"] = item["security_group_ids"] + networkInterfacesMaps = append(networkInterfacesMaps, networkInterfacesMap) + } + request["NetworkInterfaces"] = networkInterfacesMaps + } + request["IoOptimized"] = string(IOOptimized) if d.Get("is_outdated").(bool) == true { @@ -1000,6 +1052,28 @@ func modifyEssScalingConfiguration(d *schema.ResourceData, meta interface{}) err } update = true } + + if d.HasChange("network_interfaces") { + v, ok := d.GetOk("network_interfaces") + if ok { + networkInterfaces := make([]map[string]interface{}, 0) + for _, e := range v.(*schema.Set).List() { + pack := e.(map[string]interface{}) + securityGroupIdsFormat := pack["security_group_ids"] + securityGroupIds := toStringArray(securityGroupIdsFormat) + networkInterface := map[string]interface{}{ + "InstanceType": pack["instance_type"].(string), + "NetworkInterfaceTrafficMode": pack["network_interface_traffic_mode"].(string), + "Ipv6AddressCount": strconv.Itoa(pack["ipv6_address_count"].(int)), + "SecurityGroupIds": &securityGroupIds, + } + networkInterfaces = append(networkInterfaces, networkInterface) + } + request["NetworkInterfaces"] = networkInterfaces + } + update = true + } + if d.HasChange("tags") { if v, ok := d.GetOk("tags"); ok { tags := "{" @@ -1344,6 +1418,28 @@ func resourceAliyunEssScalingConfigurationRead(d *schema.ResourceData, meta inte } } + if v := response["NetworkInterfaces"]; v != nil { + result := make([]map[string]interface{}, 0) + for _, i := range v.(map[string]interface{})["NetworkInterface"].([]interface{}) { + r := i.(map[string]interface{}) + var arr1 []string + if r["SecurityGroupIds"] != nil { + j := r["SecurityGroupIds"].(map[string]interface{}) + arr1 = toStringArray(j["SecurityGroupId"]) + } + l := map[string]interface{}{ + "instance_type": r["InstanceType"], + "network_interface_traffic_mode": r["NetworkInterfaceTrafficMode"], + "ipv6_address_count": r["Ipv6AddressCount"], + "security_group_ids": &arr1, + } + result = append(result, l) + } + err := d.Set("network_interfaces", result) + if err != nil { + return WrapError(err) + } + } return nil } diff --git a/alicloud/resource_alicloud_ess_scaling_configuration_test.go b/alicloud/resource_alicloud_ess_scaling_configuration_test.go index 3bdf6f24cda8..36270afb5aef 100644 --- a/alicloud/resource_alicloud_ess_scaling_configuration_test.go +++ b/alicloud/resource_alicloud_ess_scaling_configuration_test.go @@ -459,16 +459,18 @@ func TestAccAliCloudEssScalingConfiguration_Update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccConfig(map[string]interface{}{ - "scaling_group_id": "${alicloud_ess_scaling_group.default.id}", - "image_name": "${data.alicloud_images.default1.images.0.name}", - "instance_type": "${data.alicloud_instance_types.c6.instance_types.0.id}", - "security_group_id": "${alicloud_security_group.default.id}", - "force_delete": "true", + "scaling_group_id": "${alicloud_ess_scaling_group.default.id}", + "image_name": "${data.alicloud_images.default1.images.0.name}", + "instance_type": "${data.alicloud_instance_types.c6.instance_types.0.id}", + "security_group_id": "${alicloud_security_group.default.id}", + "force_delete": "true", + "internet_max_bandwidth_in": "200", //"password": "123-abcABC", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ - "password_inherit": "false", + "password_inherit": "false", + "internet_max_bandwidth_in": "200", }), ), }, @@ -608,16 +610,6 @@ func TestAccAliCloudEssScalingConfiguration_Update(t *testing.T) { }), ), }, - { - Config: testAccConfig(map[string]interface{}{ - "internet_max_bandwidth_in": "200", - }), - Check: resource.ComposeTestCheckFunc( - testAccCheck(map[string]string{ - "internet_max_bandwidth_in": "200", - }), - ), - }, { Config: testAccConfig(map[string]interface{}{ "tags": map[string]string{ @@ -1265,7 +1257,7 @@ func TestAccAliCloudEssScalingConfiguration_Multi(t *testing.T) { testAccCheck := rac.resourceAttrMapUpdateSet() name := fmt.Sprintf("tf-testAccEssScalingConfiguration-%d", rand) - testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceEssScalingConfigurationConfigDependence) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceEssScalingConfigurationConfigMutilDependence) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -1389,6 +1381,81 @@ func resourceEssScalingConfigurationConfigDependence(name string) string { }`, EcsInstanceCommonTestCase, name) } +func resourceEssScalingConfiguration_NetworkInterfaces(name string) string { + return fmt.Sprintf(` + %s + + variable "name" { + default = "%s" + } + + resource "alicloud_vpc" "vpc" { + cidr_block = "192.168.0.0/16" + vpc_name = var.name + ipv6_isp = "BGP" + enable_ipv6 = "true" + } + + resource "alicloud_vswitch" "vswtich" { + vpc_id = "${alicloud_vpc.vpc.id}" + zone_id = "cn-hangzhou-k" + vswitch_name = var.name + cidr_block = "192.168.10.0/24" + ipv6_cidr_block_mask = "8" + } + + resource "alicloud_security_group" "default1" { + name = "${var.name}" + vpc_id = "${alicloud_vpc.vpc.id}" + } + + data "alicloud_images" "default1" { + name_regex = "^aliyun.*vhd" + most_recent = true + owners = "system" + } + data "alicloud_instance_types" "c6" { + instance_type_family = "ecs.g7h" + } + resource "alicloud_ess_scaling_group" "default" { + min_size = 1 + max_size = 1 + scaling_group_name = "${var.name}" + removal_policies = ["OldestInstance", "NewestInstance"] + vswitch_ids = ["${alicloud_vswitch.vswtich.id}"] + }`, EcsInstanceCommonTestCase, name) +} + +func resourceEssScalingConfigurationConfigMutilDependence(name string) string { + return fmt.Sprintf(` + %s + + variable "name" { + default = "%s" + } + + resource "alicloud_security_group" "default1" { + name = "${var.name}" + vpc_id = "${alicloud_vpc.default.id}" + } + + data "alicloud_images" "default1" { + name_regex = "^centos.*_64" + most_recent = true + owners = "system" + } + data "alicloud_instance_types" "c6" { + availability_zone = "${data.alicloud_zones.default.zones.0.id}" + } + resource "alicloud_ess_scaling_group" "default" { + min_size = 1 + max_size = 1 + scaling_group_name = "${var.name}" + removal_policies = ["OldestInstance", "NewestInstance"] + vswitch_ids = ["${alicloud_vswitch.default.id}"] + }`, EcsInstanceCommonTestCase, name) +} + func TestAccAliCloudEssScalingConfiguration_InstancePatternInfo(t *testing.T) { rand := acctest.RandIntRange(1000, 999999) var v ess.ScalingConfiguration @@ -1585,6 +1652,114 @@ func TestAccAliCloudEssScalingConfiguration_InstancePatternInfo(t *testing.T) { }) } +func TestAccAliCloudEssScalingConfiguration_NetworkInterfaces(t *testing.T) { + rand := acctest.RandIntRange(1000, 999999) + var v ess.ScalingConfiguration + resourceId := "alicloud_ess_scaling_configuration.ipi" + checkoutSupportedRegions(t, true, connectivity.MetaTagSupportRegions) + + basicMap := map[string]string{ + "scaling_group_id": CHECKSET, + "instance_type": CHECKSET, + "security_group_id": CHECKSET, + "image_id": REGEXMATCH + "^aliyun.*vhd", + "override": "false", + } + ra := resourceAttrInit(resourceId, basicMap) + rc := resourceCheckInit(resourceId, &v, func() interface{} { + return &EssService{testAccProvider.Meta().(*connectivity.AliyunClient)} + }) + rac := resourceAttrCheckInit(rc, ra) + + testAccCheck := rac.resourceAttrMapUpdateSet() + name := fmt.Sprintf("tf-testAccEssScalingConfiguration-%d", rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceEssScalingConfiguration_NetworkInterfaces) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + + // module name + IDRefreshName: resourceId, + + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "scaling_group_id": "${alicloud_ess_scaling_group.default.id}", + "image_id": "${data.alicloud_images.default1.images.0.id}", + "instance_type": "ecs.g8i.12xlarge", + "security_group_id": "${alicloud_security_group.default1.id}", + "force_delete": "true", + "system_disk_category": "cloud_essd", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "password_inherit": "false", + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_delete", "instance_type", "security_group_id"}, + }, + { + Config: testAccConfig(map[string]interface{}{ + "active": "true", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "active": "true", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "network_interfaces": []map[string]interface{}{ + { + "instance_type": "Primary", + "ipv6_address_count": "4", + "network_interface_traffic_mode": "Standard", + "security_group_ids": []string{"${alicloud_security_group.default1.id}"}, + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "network_interfaces.#": "1", + }), + ), + }, + + { + Config: testAccConfig(map[string]interface{}{ + "instance_pattern_info": []map[string]interface{}{ + { + "instance_type": "Primary", + "ipv6_address_count": "4", + "network_interface_traffic_mode": "Standard", + "security_group_ids": []string{"${alicloud_security_group.default1.id}"}, + }, + { + "instance_type": "Secondary", + "network_interface_traffic_mode": "HighPerformance", + "security_group_ids": []string{"${alicloud_security_group.default1.id}"}, + }, + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "network_interfaces.#": "2", + }), + ), + }, + }, + }) +} + func TestAccAliCloudEssScalingConfiguration_InstanceTypeOverride(t *testing.T) { rand := acctest.RandIntRange(1000, 999999) var v ess.ScalingConfiguration diff --git a/website/docs/r/ess_scaling_configuration.html.markdown b/website/docs/r/ess_scaling_configuration.html.markdown index 90cb80701c03..2964fa15827c 100644 --- a/website/docs/r/ess_scaling_configuration.html.markdown +++ b/website/docs/r/ess_scaling_configuration.html.markdown @@ -124,7 +124,7 @@ The following arguments are supported: * `security_group_ids` - (Optional, Available since v1.43.0) List IDs of the security group used to create new instances. It is conflict with `security_group_id`. * `scaling_configuration_name` - (Optional) Name shown for the scheduled task. which must contain 2-64 characters (English or Chinese), starting with numbers, English letters or Chinese characters, and can contain number, underscores `_`, hypens `-`, and decimal point `.`. If this parameter value is not specified, the default value is ScalingConfigurationId. * `internet_charge_type` - (Optional) Network billing type, Values: PayByBandwidth or PayByTraffic. Default to `PayByBandwidth`. -* `internet_max_bandwidth_in` - (Optional) Maximum incoming bandwidth from the public network, measured in Mbps (Mega bit per second). The value range is [1,200]. +* `internet_max_bandwidth_in` - (Optional, ForceNew) Maximum incoming bandwidth from the public network, measured in Mbps (Mega bit per second). The value range is [1,200]. * `internet_max_bandwidth_out` - (Optional, Available since v1.214.0) Maximum outgoing bandwidth from the public network, measured in Mbps (Mega bit per second). The value range for PayByBandwidth is [0,1024]. * `credit_specification` - (Optional, Available since v1.98.0) Performance mode of the t5 burstable instance. Valid values: 'Standard', 'Unlimited'. * `system_disk_category` - (Optional) Category of the system disk. The parameter value options are `ephemeral_ssd`, `cloud_efficiency`, `cloud_ssd`, `cloud_essd` and `cloud`. `cloud` only is used to some no I/O optimized instance. Default to `cloud_efficiency`.