From f81a24d52e885b1fe70bb995d156bb307650fcb0 Mon Sep 17 00:00:00 2001 From: hellertang Date: Tue, 25 Jan 2022 19:26:12 +0800 Subject: [PATCH] update scale config --- tencentcloud/extension_as.go | 10 +++ tencentcloud/resource_tc_as_scaling_config.go | 79 ++++++++++++++++++- .../docs/r/as_scaling_config.html.markdown | 7 ++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/tencentcloud/extension_as.go b/tencentcloud/extension_as.go index 578e06a65b..d97d3506cf 100644 --- a/tencentcloud/extension_as.go +++ b/tencentcloud/extension_as.go @@ -59,6 +59,16 @@ var SCALING_DISK_TYPE_ALLOW_POLICY = []string{ SCALING_DISK_TYPE_POLICY_AUTOMATIC, } +const ( + INSTANCE_NAME_ORIGINAL = "ORIGINAL" + INSTANCE_NAME_UNIQUE = "UNIQUE" +) + +var INSTANCE_NAME_STYLE = []string{ + INSTANCE_NAME_ORIGINAL, + INSTANCE_NAME_UNIQUE, +} + const ( SCALING_GROUP_ADJUSTMENT_TYPE_CHANGE_IN_CAPACITY = "CHANGE_IN_CAPACITY" SCALING_GROUP_ADJUSTMENT_TYPE_EXACT_CAPACITY = "EXACT_CAPACITY" diff --git a/tencentcloud/resource_tc_as_scaling_config.go b/tencentcloud/resource_tc_as_scaling_config.go index 4a18980ba8..5fbeeb015a 100644 --- a/tencentcloud/resource_tc_as_scaling_config.go +++ b/tencentcloud/resource_tc_as_scaling_config.go @@ -204,7 +204,33 @@ func resourceTencentCloudAsScalingConfig() *schema.Resource { ValidateFunc: validateAllowedStringValue(SCALING_DISK_TYPE_ALLOW_POLICY), Description: "Policy of cloud disk type. Valid values: `ORIGINAL` and `AUTOMATIC`. Default is `ORIGINAL`.", }, - + "cam_role_name": { + Type: schema.TypeString, + Optional: true, + Description: "CAM role name authorized to access.", + }, + "instance_name_settings": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: "Settings of CVM instance names.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_name": { + Type: schema.TypeString, + Required: true, + Description: "CVM instance name.", + }, + "instance_name_style": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateAllowedStringValue(INSTANCE_NAME_STYLE), + Default: INSTANCE_NAME_ORIGINAL, + Description: "Type of CVM instance name. Valid values: `ORIGINAL` and `UNIQUE`. Default is `ORIGINAL`.", + }, + }, + }, + }, // Computed values "status": { Type: schema.TypeString, @@ -354,6 +380,26 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte request.DiskTypePolicy = helper.String(v.(string)) } + if v, ok := d.GetOk("cam_role_name"); ok { + request.CamRoleName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("instance_name_settings"); ok { + settings := make([]*as.InstanceNameSettings, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + settingsInfo := as.InstanceNameSettings{} + if instanceName, ok := dMap["instance_name"]; ok { + settingsInfo.InstanceName = helper.String(instanceName.(string)) + } + if instanceNameStyle, ok := dMap["instance_name_style"]; ok { + settingsInfo.InstanceNameStyle = helper.String(instanceNameStyle.(string)) + } + settings = append(settings, &settingsInfo) + } + request.InstanceNameSettings = settings[0] + } + response, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().CreateLaunchConfiguration(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", @@ -408,6 +454,17 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf _ = d.Set("user_data", helper.PString(config.UserData)) _ = d.Set("instance_tags", flattenInstanceTagsMapping(config.InstanceTags)) _ = d.Set("disk_type_policy", *config.DiskTypePolicy) + + _ = d.Set("cam_role_name", *config.CamRoleName) + if config.InstanceNameSettings != nil { + settings := make([]map[string]interface{}, 0) + settings = append(settings, map[string]interface{}{ + "instance_name": config.InstanceNameSettings.InstanceName, + "instance_name_style": config.InstanceNameSettings.InstanceNameStyle, + }) + _ = d.Set("instance_name_settings", settings) + } + if config.SystemDisk.DiskType != nil { _ = d.Set("system_disk_type", *config.SystemDisk.DiskType) } @@ -557,6 +614,26 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte request.DiskTypePolicy = helper.String(v.(string)) } + if v, ok := d.GetOk("cam_role_name"); ok { + request.CamRoleName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("instance_name_settings"); ok { + settings := make([]*as.InstanceNameSettings, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + settingsInfo := as.InstanceNameSettings{} + if instanceName, ok := dMap["instance_name"]; ok { + settingsInfo.InstanceName = helper.String(instanceName.(string)) + } + if instanceNameStyle, ok := dMap["instance_name_style"]; ok { + settingsInfo.InstanceNameStyle = helper.String(instanceNameStyle.(string)) + } + settings = append(settings, &settingsInfo) + } + request.InstanceNameSettings = settings[0] + } + response, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().UpgradeLaunchConfiguration(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", diff --git a/website/docs/r/as_scaling_config.html.markdown b/website/docs/r/as_scaling_config.html.markdown index 8158478cfc..2bafa74360 100644 --- a/website/docs/r/as_scaling_config.html.markdown +++ b/website/docs/r/as_scaling_config.html.markdown @@ -48,10 +48,12 @@ The following arguments are supported: * `configuration_name` - (Required) Name of a launch configuration. * `image_id` - (Required) An available image ID for a cvm instance. * `instance_types` - (Required) Specified types of CVM instances. +* `cam_role_name` - (Optional) CAM role name authorized to access. * `data_disk` - (Optional) Configurations of data disk. * `disk_type_policy` - (Optional) Policy of cloud disk type. Valid values: `ORIGINAL` and `AUTOMATIC`. Default is `ORIGINAL`. * `enhanced_monitor_service` - (Optional) To specify whether to enable cloud monitor service. Default is `TRUE`. * `enhanced_security_service` - (Optional) To specify whether to enable cloud security service. Default is `TRUE`. +* `instance_name_settings` - (Optional) Settings of CVM instance names. * `instance_tags` - (Optional) A list of tags used to associate different resources. * `internet_charge_type` - (Optional) Charge types for network traffic. Valid values: `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `TRAFFIC_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. * `internet_max_bandwidth_out` - (Optional) Max bandwidth of Internet access in Mbps. Default is `0`. @@ -71,6 +73,11 @@ The `data_disk` object supports the following: * `disk_type` - (Optional) Types of disk. Valid values: `CLOUD_PREMIUM` and `CLOUD_SSD`. valid when disk_type_policy is ORIGINAL. * `snapshot_id` - (Optional) Data disk snapshot ID. +The `instance_name_settings` object supports the following: + +* `instance_name` - (Required) CVM instance name. +* `instance_name_style` - (Optional) Type of CVM instance name. Valid values: `ORIGINAL` and `UNIQUE`. Default is `ORIGINAL`. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: