Skip to content

Commit e71e2f0

Browse files
authored
fix: as support host_name (#2052)
* fix: as support host_name * feat: add changelog * fix: modify changelog * fix: fmt
1 parent a58c7ad commit e71e2f0

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

.changelog/2052.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_as_scaling_config: Support field `host_name`
3+
```

tencentcloud/resource_tc_as_scaling_config.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ resource "tencentcloud_as_scaling_config" "example" {
3232
enhanced_monitor_service = false
3333
user_data = "dGVzdA=="
3434
35+
host_name_settings {
36+
host_name = "host-name-test"
37+
host_name_style = "UNIQUE"
38+
}
39+
3540
instance_tags = {
3641
tag = "example"
3742
}
@@ -61,7 +66,7 @@ Import
6166
AutoScaling Configuration can be imported using the id, e.g.
6267
6368
```
64-
$ terraform import tencentcloud_as_scaling_config.scaling_config asc-n32ymck2
69+
$ terraform import tencentcloud_as_scaling_config.example asc-n32ymck2
6570
```
6671
*/
6772
package tencentcloud
@@ -270,6 +275,26 @@ func resourceTencentCloudAsScalingConfig() *schema.Resource {
270275
Optional: true,
271276
Description: "CAM role name authorized to access.",
272277
},
278+
"host_name_settings": {
279+
Type: schema.TypeList,
280+
Optional: true,
281+
MaxItems: 1,
282+
Description: "Related settings of the cloud server hostname (HostName).",
283+
Elem: &schema.Resource{
284+
Schema: map[string]*schema.Schema{
285+
"host_name": {
286+
Type: schema.TypeString,
287+
Required: true,
288+
Description: "The host name of the cloud server; dots (.) and dashes (-) cannot be used as the first and last characters of HostName, and cannot be used consecutively; Windows instances are not supported; other types (Linux, etc.) instances: the character length is [2, 40], it is allowed to support multiple dots, and there is a paragraph between the dots, and each paragraph is allowed to consist of letters (no uppercase and lowercase restrictions), numbers and dashes (-). Pure numbers are not allowed.",
289+
},
290+
"host_name_style": {
291+
Type: schema.TypeString,
292+
Optional: true,
293+
Description: "The style of the host name of the cloud server, the value range includes `ORIGINAL` and `UNIQUE`, the default is `ORIGINAL`; `ORIGINAL`, the AS directly passes the HostName filled in the input parameter to the CVM, and the CVM may append a sequence to the HostName number, the HostName of the instance in the scaling group will conflict; `UNIQUE`, the HostName filled in as a parameter is equivalent to the host name prefix, AS and CVM will expand it, and the HostName of the instance in the scaling group can be guaranteed to be unique.",
294+
},
295+
},
296+
},
297+
},
273298
"instance_name_settings": {
274299
Type: schema.TypeList,
275300
Optional: true,
@@ -472,6 +497,22 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte
472497
request.CamRoleName = helper.String(v.(string))
473498
}
474499

500+
if v, ok := d.GetOk("host_name_settings"); ok {
501+
settings := make([]*as.HostNameSettings, 0, 10)
502+
for _, item := range v.([]interface{}) {
503+
dMap := item.(map[string]interface{})
504+
settingsInfo := as.HostNameSettings{}
505+
if hostName, ok := dMap["host_name"]; ok {
506+
settingsInfo.HostName = helper.String(hostName.(string))
507+
}
508+
if hostNameStyle, ok := dMap["host_name_style"]; ok {
509+
settingsInfo.HostNameStyle = helper.String(hostNameStyle.(string))
510+
}
511+
settings = append(settings, &settingsInfo)
512+
}
513+
request.HostNameSettings = settings[0]
514+
}
515+
475516
if v, ok := d.GetOk("instance_name_settings"); ok {
476517
settings := make([]*as.InstanceNameSettings, 0, 10)
477518
for _, item := range v.([]interface{}) {
@@ -544,6 +585,18 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
544585
_ = d.Set("disk_type_policy", *config.DiskTypePolicy)
545586

546587
_ = d.Set("cam_role_name", *config.CamRoleName)
588+
589+
if config.HostNameSettings != nil {
590+
settings := map[string]interface{}{}
591+
if config.HostNameSettings.HostName != nil {
592+
settings["host_name"] = config.HostNameSettings.HostName
593+
}
594+
if config.HostNameSettings.HostNameStyle != nil {
595+
settings["host_name_style"] = config.HostNameSettings.HostNameStyle
596+
}
597+
_ = d.Set("host_name_settings", []interface{}{settings})
598+
}
599+
547600
if config.InstanceNameSettings != nil {
548601
settings := make([]map[string]interface{}, 0)
549602
setting := map[string]interface{}{
@@ -751,6 +804,22 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
751804
request.CamRoleName = helper.String(v.(string))
752805
}
753806

807+
if v, ok := d.GetOk("host_name_settings"); ok {
808+
settings := make([]*as.HostNameSettings, 0, 10)
809+
for _, item := range v.([]interface{}) {
810+
dMap := item.(map[string]interface{})
811+
settingsInfo := as.HostNameSettings{}
812+
if hostName, ok := dMap["host_name"]; ok {
813+
settingsInfo.HostName = helper.String(hostName.(string))
814+
}
815+
if hostNameStyle, ok := dMap["host_name_style"]; ok {
816+
settingsInfo.HostNameStyle = helper.String(hostNameStyle.(string))
817+
}
818+
settings = append(settings, &settingsInfo)
819+
}
820+
request.HostNameSettings = settings[0]
821+
}
822+
754823
if v, ok := d.GetOk("instance_name_settings"); ok {
755824
settings := make([]*as.InstanceNameSettings, 0, 10)
756825
for _, item := range v.([]interface{}) {

tencentcloud/resource_tc_as_scaling_config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func TestAccTencentCloudAsScalingConfig_full(t *testing.T) {
107107
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "public_ip_assigned", "true"),
108108
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "enhanced_security_service", "false"),
109109
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "enhanced_monitor_service", "false"),
110+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.#", "1"),
111+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.0.host_name", "host-name"),
112+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.0.host_name_style", "ORIGINAL"),
110113
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "user_data", "test"),
111114
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "instance_tags.tag", "as"),
112115
),
@@ -129,6 +132,9 @@ func TestAccTencentCloudAsScalingConfig_full(t *testing.T) {
129132
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "enhanced_security_service", "true"),
130133
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "enhanced_monitor_service", "true"),
131134
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "user_data", "dGVzdA=="),
135+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.#", "1"),
136+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.0.host_name", "host-name-test"),
137+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "host_name_settings.0.host_name_style", "UNIQUE"),
132138
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "instance_tags.tag", "as"),
133139
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.launch_configuration", "instance_tags.test", "update"),
134140
),
@@ -252,6 +258,11 @@ resource "tencentcloud_as_scaling_config" "launch_configuration" {
252258
enhanced_security_service = false
253259
enhanced_monitor_service = false
254260
user_data = "test"
261+
262+
host_name_settings {
263+
host_name = "host-name"
264+
host_name_style = "ORIGINAL"
265+
}
255266
256267
instance_tags = {
257268
tag = "as"
@@ -283,6 +294,11 @@ resource "tencentcloud_as_scaling_config" "launch_configuration" {
283294
enhanced_security_service = true
284295
enhanced_monitor_service = true
285296
user_data = "dGVzdA=="
297+
298+
host_name_settings {
299+
host_name = "host-name-test"
300+
host_name_style = "UNIQUE"
301+
}
286302
287303
instance_tags = {
288304
tag = "as"

website/docs/r/as_scaling_config.html.markdown

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ resource "tencentcloud_as_scaling_config" "example" {
4242
enhanced_monitor_service = false
4343
user_data = "dGVzdA=="
4444
45+
host_name_settings {
46+
host_name = "host-name-test"
47+
host_name_style = "UNIQUE"
48+
}
49+
4550
instance_tags = {
4651
tag = "example"
4752
}
@@ -78,6 +83,7 @@ The following arguments are supported:
7883
* `disk_type_policy` - (Optional, String) Policy of cloud disk type. Valid values: `ORIGINAL` and `AUTOMATIC`. Default is `ORIGINAL`.
7984
* `enhanced_monitor_service` - (Optional, Bool) To specify whether to enable cloud monitor service. Default is `TRUE`.
8085
* `enhanced_security_service` - (Optional, Bool) To specify whether to enable cloud security service. Default is `TRUE`.
86+
* `host_name_settings` - (Optional, List) Related settings of the cloud server hostname (HostName).
8187
* `instance_charge_type_prepaid_period` - (Optional, Int) The tenancy (in month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`.
8288
* `instance_charge_type_prepaid_renew_flag` - (Optional, String) Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`.
8389
* `instance_charge_type` - (Optional, String) Charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `SPOTPAID`. The default is `POSTPAID_BY_HOUR`. NOTE: `SPOTPAID` instance must set `spot_instance_type` and `spot_max_price` at the same time.
@@ -104,6 +110,11 @@ The `data_disk` object supports the following:
104110
* `disk_type` - (Optional, String) Types of disk. Valid values: `CLOUD_PREMIUM` and `CLOUD_SSD`. valid when disk_type_policy is ORIGINAL.
105111
* `snapshot_id` - (Optional, String) Data disk snapshot ID.
106112

113+
The `host_name_settings` object supports the following:
114+
115+
* `host_name` - (Required, String) The host name of the cloud server; dots (.) and dashes (-) cannot be used as the first and last characters of HostName, and cannot be used consecutively; Windows instances are not supported; other types (Linux, etc.) instances: the character length is [2, 40], it is allowed to support multiple dots, and there is a paragraph between the dots, and each paragraph is allowed to consist of letters (no uppercase and lowercase restrictions), numbers and dashes (-). Pure numbers are not allowed.
116+
* `host_name_style` - (Optional, String) The style of the host name of the cloud server, the value range includes `ORIGINAL` and `UNIQUE`, the default is `ORIGINAL`; `ORIGINAL`, the AS directly passes the HostName filled in the input parameter to the CVM, and the CVM may append a sequence to the HostName number, the HostName of the instance in the scaling group will conflict; `UNIQUE`, the HostName filled in as a parameter is equivalent to the host name prefix, AS and CVM will expand it, and the HostName of the instance in the scaling group can be guaranteed to be unique.
117+
107118
The `instance_name_settings` object supports the following:
108119

109120
* `instance_name` - (Required, String) CVM instance name.
@@ -123,6 +134,6 @@ In addition to all arguments above, the following attributes are exported:
123134
AutoScaling Configuration can be imported using the id, e.g.
124135

125136
```
126-
$ terraform import tencentcloud_as_scaling_config.scaling_config asc-n32ymck2
137+
$ terraform import tencentcloud_as_scaling_config.example asc-n32ymck2
127138
```
128139

0 commit comments

Comments
 (0)