Skip to content

Commit 667d227

Browse files
authored
feat:support host_name_style for tke node pool (#1435)
* feat:support host_name_style for tke node pool * add changelog * adjust e2e case name
1 parent a70e884 commit 667d227

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

.changelog/1435.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_kubernetes_node_pool: support host_name_style field
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,10 @@ func Provider() terraform.ResourceProvider {
12111211
"tencentcloud_eks_container_instance": resourceTencentCloudEksContainerInstance(),
12121212
"tencentcloud_kubernetes_addon_attachment": resourceTencentCloudTkeAddonAttachment(),
12131213
"tencentcloud_kubernetes_auth_attachment": resourceTencentCloudTKEAuthAttachment(),
1214-
"tencentcloud_kubernetes_as_scaling_group": ResourceTencentCloudKubernetesAsScalingGroup(),
1214+
"tencentcloud_kubernetes_as_scaling_group": resourceTencentCloudKubernetesAsScalingGroup(),
12151215
"tencentcloud_kubernetes_scale_worker": resourceTencentCloudTkeScaleWorker(),
12161216
"tencentcloud_kubernetes_cluster_attachment": resourceTencentCloudTkeClusterAttachment(),
1217-
"tencentcloud_kubernetes_node_pool": ResourceTencentCloudKubernetesNodePool(),
1217+
"tencentcloud_kubernetes_node_pool": resourceTencentCloudKubernetesNodePool(),
12181218
"tencentcloud_mysql_backup_policy": resourceTencentCloudMysqlBackupPolicy(),
12191219
"tencentcloud_mysql_account": resourceTencentCloudMysqlAccount(),
12201220
"tencentcloud_mysql_account_privilege": resourceTencentCloudMysqlAccountPrivilege(),

tencentcloud/resource_tc_kubernetes_as_scaling_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import (
6363
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
6464
)
6565

66-
func ResourceTencentCloudKubernetesAsScalingGroup() *schema.Resource {
66+
func resourceTencentCloudKubernetesAsScalingGroup() *schema.Resource {
6767
return &schema.Resource{
6868
DeprecationMessage: "This resource was offline and no longer supported.",
6969
Create: resourceKubernetesAsScalingGroupCreate,

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ resource "tencentcloud_kubernetes_node_pool" "mynodepool" {
6767
password = "test123#"
6868
enhanced_security_service = false
6969
enhanced_monitor_service = false
70-
70+
host_name = "12.123.0.0"
71+
host_name_style = "ORIGINAL"
7172
}
7273
7374
labels = {
@@ -364,12 +365,18 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
364365
Computed: true,
365366
Description: "The hostname of the cloud server, dot (.) and dash (-) cannot be used as the first and last characters of HostName and cannot be used consecutively. Windows instances are not supported. Examples of other types (Linux, etc.): The character length is [2, 40], multiple periods are allowed, and there is a paragraph between the dots, and each paragraph is allowed to consist of letters (unlimited case), numbers and dashes (-). Pure numbers are not allowed. For usage, refer to `HostNameSettings` in https://www.tencentcloud.com/document/product/377/31001.",
366367
},
368+
"host_name_style": {
369+
Type: schema.TypeString,
370+
Optional: true,
371+
Computed: true,
372+
Description: "The style of the host name of the cloud server, the value range includes ORIGINAL and UNIQUE, and the default is ORIGINAL. For usage, refer to `HostNameSettings` in https://www.tencentcloud.com/document/product/377/31001.",
373+
},
367374
}
368375

369376
return needSchema
370377
}
371378

372-
func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
379+
func resourceTencentCloudKubernetesNodePool() *schema.Resource {
373380
return &schema.Resource{
374381
Create: resourceKubernetesNodePoolCreate,
375382
Read: resourceKubernetesNodePoolRead,
@@ -811,8 +818,22 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
811818
}
812819

813820
if v, ok := dMap["host_name"]; ok && v != "" {
814-
request.HostNameSettings = &as.HostNameSettings{
815-
HostName: helper.String(v.(string)),
821+
if request.HostNameSettings == nil {
822+
request.HostNameSettings = &as.HostNameSettings{
823+
HostName: helper.String(v.(string)),
824+
}
825+
} else {
826+
request.HostNameSettings.HostName = helper.String(v.(string))
827+
}
828+
}
829+
830+
if v, ok := dMap["host_name_style"]; ok && v != "" {
831+
if request.HostNameSettings != nil {
832+
request.HostNameSettings.HostNameStyle = helper.String(v.(string))
833+
} else {
834+
request.HostNameSettings = &as.HostNameSettings{
835+
HostNameStyle: helper.String(v.(string)),
836+
}
816837
}
817838
}
818839
result = request.ToJsonString()
@@ -924,8 +945,22 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
924945
}
925946

926947
if v, ok := dMap["host_name"]; ok && v != "" {
927-
request.HostNameSettings = &as.HostNameSettings{
928-
HostName: helper.String(v.(string)),
948+
if request.HostNameSettings == nil {
949+
request.HostNameSettings = &as.HostNameSettings{
950+
HostName: helper.String(v.(string)),
951+
}
952+
} else {
953+
request.HostNameSettings.HostName = helper.String(v.(string))
954+
}
955+
}
956+
957+
if v, ok := dMap["host_name_style"]; ok && v != "" {
958+
if request.HostNameSettings != nil {
959+
request.HostNameSettings.HostNameStyle = helper.String(v.(string))
960+
} else {
961+
request.HostNameSettings = &as.HostNameSettings{
962+
HostNameStyle: helper.String(v.(string)),
963+
}
929964
}
930965
}
931966

@@ -1151,6 +1186,9 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
11511186
if launchCfg.HostNameSettings != nil && launchCfg.HostNameSettings.HostName != nil {
11521187
launchConfig["host_name"] = launchCfg.HostNameSettings.HostName
11531188
}
1189+
if launchCfg.HostNameSettings != nil && launchCfg.HostNameSettings.HostNameStyle != nil {
1190+
launchConfig["host_name_style"] = launchCfg.HostNameSettings.HostNameStyle
1191+
}
11541192

11551193
asgConfig := make([]interface{}, 0, 1)
11561194
asgConfig = append(asgConfig, launchConfig)

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func testNodePoolSweep(region string) error {
6868
return nil
6969
}
7070

71-
func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
71+
func TestAccTencentCloudKubernetesNodePoolResource_basic(t *testing.T) {
7272
t.Parallel()
7373
resource.Test(t, resource.TestCase{
7474
PreCheck: func() { testAccPreCheck(t) },
@@ -104,6 +104,8 @@ func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
104104
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np1", "test1"),
105105
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np2", "test2"),
106106
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.security_group_ids.#", "1"),
107+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name", "12.123.0.0"),
108+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name_style", "ORIGINAL"),
107109
),
108110
},
109111
{
@@ -136,13 +138,15 @@ func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
136138
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np1", "testI"),
137139
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "tags.keep-test-np3", "testIII"),
138140
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.security_group_ids.#", "2"),
141+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name", "12.123.1.1"),
142+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.host_name_style", "UNIQUE"),
139143
),
140144
},
141145
},
142146
})
143147
}
144148

145-
func TestAccTencentCloudTkeNodePoolResourceDiskEncrypt(t *testing.T) {
149+
func TestAccTencentCloudKubernetesNodePoolResource_DiskEncrypt(t *testing.T) {
146150
t.Parallel()
147151
resource.Test(t, resource.TestCase{
148152
PreCheck: func() { testAccPreCheck(t) },
@@ -288,7 +292,8 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
288292
password = "test123#"
289293
enhanced_security_service = false
290294
enhanced_monitor_service = false
291-
295+
host_name = "12.123.0.0"
296+
host_name_style = "ORIGINAL"
292297
}
293298
unschedulable = 0
294299
labels = {
@@ -361,6 +366,8 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
361366
password = "test123#"
362367
enhanced_security_service = false
363368
enhanced_monitor_service = false
369+
host_name = "12.123.1.1"
370+
host_name_style = "UNIQUE"
364371
365372
}
366373
unschedulable = 0

website/docs/r/kubernetes_node_pool.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ resource "tencentcloud_kubernetes_node_pool" "mynodepool" {
7676
password = "test123#"
7777
enhanced_security_service = false
7878
enhanced_monitor_service = false
79-
79+
host_name = "12.123.0.0"
80+
host_name_style = "ORIGINAL"
8081
}
8182
8283
labels = {
@@ -188,6 +189,7 @@ The `auto_scaling_config` object supports the following:
188189
* `data_disk` - (Optional, List) Configurations of data disk.
189190
* `enhanced_monitor_service` - (Optional, Bool, ForceNew) To specify whether to enable cloud monitor service. Default is TRUE.
190191
* `enhanced_security_service` - (Optional, Bool, ForceNew) To specify whether to enable cloud security service. Default is TRUE.
192+
* `host_name_style` - (Optional, String) The style of the host name of the cloud server, the value range includes ORIGINAL and UNIQUE, and the default is ORIGINAL. For usage, refer to `HostNameSettings` in https://www.tencentcloud.com/document/product/377/31001.
191193
* `host_name` - (Optional, String) The hostname of the cloud server, dot (.) and dash (-) cannot be used as the first and last characters of HostName and cannot be used consecutively. Windows instances are not supported. Examples of other types (Linux, etc.): The character length is [2, 40], multiple periods are allowed, and there is a paragraph between the dots, and each paragraph is allowed to consist of letters (unlimited case), numbers and dashes (-). Pure numbers are not allowed. For usage, refer to `HostNameSettings` in https://www.tencentcloud.com/document/product/377/31001.
192194
* `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`.
193195
* `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`.

0 commit comments

Comments
 (0)