Skip to content

Commit bd4a7a6

Browse files
author
hellertang
authored
update scale config (#843)
1 parent 430dd70 commit bd4a7a6

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

tencentcloud/extension_as.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ var SCALING_DISK_TYPE_ALLOW_POLICY = []string{
5959
SCALING_DISK_TYPE_POLICY_AUTOMATIC,
6060
}
6161

62+
const (
63+
INSTANCE_NAME_ORIGINAL = "ORIGINAL"
64+
INSTANCE_NAME_UNIQUE = "UNIQUE"
65+
)
66+
67+
var INSTANCE_NAME_STYLE = []string{
68+
INSTANCE_NAME_ORIGINAL,
69+
INSTANCE_NAME_UNIQUE,
70+
}
71+
6272
const (
6373
SCALING_GROUP_ADJUSTMENT_TYPE_CHANGE_IN_CAPACITY = "CHANGE_IN_CAPACITY"
6474
SCALING_GROUP_ADJUSTMENT_TYPE_EXACT_CAPACITY = "EXACT_CAPACITY"

tencentcloud/resource_tc_as_scaling_config.go

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,33 @@ func resourceTencentCloudAsScalingConfig() *schema.Resource {
204204
ValidateFunc: validateAllowedStringValue(SCALING_DISK_TYPE_ALLOW_POLICY),
205205
Description: "Policy of cloud disk type. Valid values: `ORIGINAL` and `AUTOMATIC`. Default is `ORIGINAL`.",
206206
},
207-
207+
"cam_role_name": {
208+
Type: schema.TypeString,
209+
Optional: true,
210+
Description: "CAM role name authorized to access.",
211+
},
212+
"instance_name_settings": {
213+
Type: schema.TypeList,
214+
Optional: true,
215+
MaxItems: 1,
216+
Description: "Settings of CVM instance names.",
217+
Elem: &schema.Resource{
218+
Schema: map[string]*schema.Schema{
219+
"instance_name": {
220+
Type: schema.TypeString,
221+
Required: true,
222+
Description: "CVM instance name.",
223+
},
224+
"instance_name_style": {
225+
Type: schema.TypeString,
226+
Optional: true,
227+
ValidateFunc: validateAllowedStringValue(INSTANCE_NAME_STYLE),
228+
Default: INSTANCE_NAME_ORIGINAL,
229+
Description: "Type of CVM instance name. Valid values: `ORIGINAL` and `UNIQUE`. Default is `ORIGINAL`.",
230+
},
231+
},
232+
},
233+
},
208234
// Computed values
209235
"status": {
210236
Type: schema.TypeString,
@@ -354,6 +380,26 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte
354380
request.DiskTypePolicy = helper.String(v.(string))
355381
}
356382

383+
if v, ok := d.GetOk("cam_role_name"); ok {
384+
request.CamRoleName = helper.String(v.(string))
385+
}
386+
387+
if v, ok := d.GetOk("instance_name_settings"); ok {
388+
settings := make([]*as.InstanceNameSettings, 0, 10)
389+
for _, item := range v.([]interface{}) {
390+
dMap := item.(map[string]interface{})
391+
settingsInfo := as.InstanceNameSettings{}
392+
if instanceName, ok := dMap["instance_name"]; ok {
393+
settingsInfo.InstanceName = helper.String(instanceName.(string))
394+
}
395+
if instanceNameStyle, ok := dMap["instance_name_style"]; ok {
396+
settingsInfo.InstanceNameStyle = helper.String(instanceNameStyle.(string))
397+
}
398+
settings = append(settings, &settingsInfo)
399+
}
400+
request.InstanceNameSettings = settings[0]
401+
}
402+
357403
response, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().CreateLaunchConfiguration(request)
358404
if err != nil {
359405
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
@@ -408,6 +454,17 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
408454
_ = d.Set("user_data", helper.PString(config.UserData))
409455
_ = d.Set("instance_tags", flattenInstanceTagsMapping(config.InstanceTags))
410456
_ = d.Set("disk_type_policy", *config.DiskTypePolicy)
457+
458+
_ = d.Set("cam_role_name", *config.CamRoleName)
459+
if config.InstanceNameSettings != nil {
460+
settings := make([]map[string]interface{}, 0)
461+
settings = append(settings, map[string]interface{}{
462+
"instance_name": config.InstanceNameSettings.InstanceName,
463+
"instance_name_style": config.InstanceNameSettings.InstanceNameStyle,
464+
})
465+
_ = d.Set("instance_name_settings", settings)
466+
}
467+
411468
if config.SystemDisk.DiskType != nil {
412469
_ = d.Set("system_disk_type", *config.SystemDisk.DiskType)
413470
}
@@ -557,6 +614,26 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
557614
request.DiskTypePolicy = helper.String(v.(string))
558615
}
559616

617+
if v, ok := d.GetOk("cam_role_name"); ok {
618+
request.CamRoleName = helper.String(v.(string))
619+
}
620+
621+
if v, ok := d.GetOk("instance_name_settings"); ok {
622+
settings := make([]*as.InstanceNameSettings, 0, 10)
623+
for _, item := range v.([]interface{}) {
624+
dMap := item.(map[string]interface{})
625+
settingsInfo := as.InstanceNameSettings{}
626+
if instanceName, ok := dMap["instance_name"]; ok {
627+
settingsInfo.InstanceName = helper.String(instanceName.(string))
628+
}
629+
if instanceNameStyle, ok := dMap["instance_name_style"]; ok {
630+
settingsInfo.InstanceNameStyle = helper.String(instanceNameStyle.(string))
631+
}
632+
settings = append(settings, &settingsInfo)
633+
}
634+
request.InstanceNameSettings = settings[0]
635+
}
636+
560637
response, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().UpgradeLaunchConfiguration(request)
561638
if err != nil {
562639
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",

website/docs/r/as_scaling_config.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ The following arguments are supported:
4848
* `configuration_name` - (Required) Name of a launch configuration.
4949
* `image_id` - (Required) An available image ID for a cvm instance.
5050
* `instance_types` - (Required) Specified types of CVM instances.
51+
* `cam_role_name` - (Optional) CAM role name authorized to access.
5152
* `data_disk` - (Optional) Configurations of data disk.
5253
* `disk_type_policy` - (Optional) Policy of cloud disk type. Valid values: `ORIGINAL` and `AUTOMATIC`. Default is `ORIGINAL`.
5354
* `enhanced_monitor_service` - (Optional) To specify whether to enable cloud monitor service. Default is `TRUE`.
5455
* `enhanced_security_service` - (Optional) To specify whether to enable cloud security service. Default is `TRUE`.
56+
* `instance_name_settings` - (Optional) Settings of CVM instance names.
5557
* `instance_tags` - (Optional) A list of tags used to associate different resources.
5658
* `internet_charge_type` - (Optional) Charge types for network traffic. Valid values: `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `TRAFFIC_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`.
5759
* `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:
7173
* `disk_type` - (Optional) Types of disk. Valid values: `CLOUD_PREMIUM` and `CLOUD_SSD`. valid when disk_type_policy is ORIGINAL.
7274
* `snapshot_id` - (Optional) Data disk snapshot ID.
7375

76+
The `instance_name_settings` object supports the following:
77+
78+
* `instance_name` - (Required) CVM instance name.
79+
* `instance_name_style` - (Optional) Type of CVM instance name. Valid values: `ORIGINAL` and `UNIQUE`. Default is `ORIGINAL`.
80+
7481
## Attributes Reference
7582

7683
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)