Skip to content

Commit f4adefe

Browse files
committed
fix: nodepool - encrypt testcase and description
1 parent 00a8525 commit f4adefe

File tree

5 files changed

+106
-12
lines changed

5 files changed

+106
-12
lines changed

tencentcloud/basic_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ const (
9595
defaultTkeOSImageName = "tlinux2.2(tkernel3)x86_64"
9696
)
9797

98+
// Project
99+
const defaultProjectVariable = `
100+
variable "default_project" {
101+
default = ` + defaultProjectId + `
102+
}
103+
`
104+
98105
// EMR
99106
const (
100107
defaultEMRVpcId = defaultVpcId
@@ -637,7 +644,7 @@ variable "tke_cidr_c" {
637644

638645
const TkeDefaultNodeInstanceVar = `
639646
variable "ins_type" {
640-
default = "S5.MEDIUM4"
647+
default = "SA2.LARGE8"
641648
}
642649
`
643650

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
243243
"encrypt": {
244244
Type: schema.TypeBool,
245245
Optional: true,
246-
Description: "Specify whether to encrypt data disk, default: false.",
246+
Description: "Specify whether to encrypt data disk, default: false. NOTE: Make sure the instance type is offering and the cam role `QcloudKMSAccessForCVMRole` was provided.",
247247
},
248248
"throughput_performance": {
249249
Type: schema.TypeInt,
@@ -497,6 +497,11 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
497497
Default: true,
498498
Description: "Indicate to keep the CVM instance when delete the node pool. Default is `true`.",
499499
},
500+
//"deletion_protection": {
501+
// Type: schema.TypeBool,
502+
// Optional: true,
503+
// Description: "Indicates whether the node pool deletion protection is enabled.",
504+
//},
500505
"node_os": {
501506
Type: schema.TypeString,
502507
Optional: true,
@@ -1000,6 +1005,10 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
10001005
_ = d.Set("node_os_type", nodePool.OsCustomizeType)
10011006
}
10021007

1008+
//if nodePool.DeletionProtection != nil {
1009+
// _ = d.Set("deletion_protection", nodePool.DeletionProtection)
1010+
//}
1011+
10031012
//set composed struct
10041013
lables := make(map[string]interface{}, len(nodePool.Labels))
10051014
for _, v := range nodePool.Labels {
@@ -1194,6 +1203,8 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11941203
nodeOs := d.Get("node_os").(string)
11951204
nodeOsType := d.Get("node_os_type").(string)
11961205

1206+
//deletionProtection := d.Get("deletion_protection").(bool)
1207+
11971208
service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
11981209

11991210
nodePoolId, err := service.CreateClusterNodePool(ctx, clusterId, name, groupParaStr, configParaStr, enableAutoScale, nodeOs, nodeOsType, labels, taints, iAdvanced)
@@ -1294,10 +1305,21 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12941305
}
12951306

12961307
// ModifyClusterNodePool
1297-
if d.HasChange("min_size") || d.HasChange("max_size") || d.HasChange("name") || d.HasChange("labels") || d.HasChange("taints") || d.HasChange("enable_auto_scale") || d.HasChange("node_os_type") || d.HasChange("node_os") {
1308+
if d.HasChanges(
1309+
"min_size",
1310+
"max_size",
1311+
"name",
1312+
"labels",
1313+
"taints",
1314+
//"deletion_protection",
1315+
"enable_auto_scale",
1316+
"node_os_type",
1317+
"node_os",
1318+
) {
12981319
maxSize := int64(d.Get("max_size").(int))
12991320
minSize := int64(d.Get("min_size").(int))
13001321
enableAutoScale := d.Get("enable_auto_scale").(bool)
1322+
//deletionProtection := d.Get("deletion_protection").(bool)
13011323
name := d.Get("name").(string)
13021324
nodeOs := d.Get("node_os").(string)
13031325
nodeOsType := d.Get("node_os_type").(string)
@@ -1423,13 +1445,18 @@ func resourceKubernetesNodePoolDelete(d *schema.ResourceData, meta interface{})
14231445
service = TkeService{client: meta.(*TencentCloudClient).apiV3Conn}
14241446
items = strings.Split(d.Id(), FILED_SP)
14251447
deleteKeepInstance = d.Get("delete_keep_instance").(bool)
1448+
//deletionProtection = d.Get("deletion_protection").(bool)
14261449
)
14271450
if len(items) != 2 {
14281451
return fmt.Errorf("resource_tc_kubernetes_node_pool id is broken")
14291452
}
14301453
clusterId := items[0]
14311454
nodePoolId := items[1]
14321455

1456+
//if deletionProtection {
1457+
// return fmt.Errorf("deletion protection was enabled, please set `deletion_protection` to `false` and apply first")
1458+
//}
1459+
14331460
//delete as group
14341461
hasDelete := false
14351462
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {

tencentcloud/resource_tc_kubernetes_node_pool_test.go

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func testNodePoolSweep(region string) error {
6161
return nil
6262
}
6363

64-
func TestAccTencentCloudTkeNodePoolResource(t *testing.T) {
64+
func TestAccTencentCloudTkeNodePoolResourceBasic(t *testing.T) {
6565
t.Parallel()
6666
resource.Test(t, resource.TestCase{
6767
PreCheck: func() { testAccPreCheck(t) },
@@ -129,6 +129,25 @@ func TestAccTencentCloudTkeNodePoolResource(t *testing.T) {
129129
})
130130
}
131131

132+
func TestAccTencentCloudTkeNodePoolResourceDiskEncrypt(t *testing.T) {
133+
t.Parallel()
134+
resource.Test(t, resource.TestCase{
135+
PreCheck: func() { testAccPreCheck(t) },
136+
Providers: testAccProviders,
137+
CheckDestroy: testAccCheckTkeNodePoolDestroy,
138+
Steps: []resource.TestStep{
139+
{
140+
Config: testAccTkeNodePoolClusterEncrypt,
141+
Check: resource.ComposeTestCheckFunc(
142+
testAccCheckTkeNodePoolExists,
143+
resource.TestCheckResourceAttrSet(testTkeClusterNodePoolResourceKey, "cluster_id"),
144+
resource.TestCheckResourceAttr(testTkeClusterNodePoolResourceKey, "auto_scaling_config.0.data_disk.0.encrypt", "true"),
145+
),
146+
},
147+
},
148+
})
149+
}
150+
132151
func testAccCheckTkeNodePoolDestroy(s *terraform.State) error {
133152
logId := getLogId(contextNil)
134153
ctx := context.WithValue(context.TODO(), logIdKey, logId)
@@ -202,7 +221,7 @@ func testAccCheckTkeNodePoolExists(s *terraform.State) error {
202221

203222
}
204223

205-
const testAccTkeNodePoolClusterBasic = TkeDataSource + TkeDefaultNodeInstanceVar + `
224+
const testAccTkeNodePoolClusterBasic = defaultProjectVariable + defaultImages + TkeDataSource + TkeDefaultNodeInstanceVar + `
206225
variable "availability_zone" {
207226
default = "ap-guangzhou-3"
208227
}
@@ -231,7 +250,9 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
231250
scaling_group_name = "basic_group"
232251
default_cooldown = 400
233252
termination_policies = ["OLDEST_INSTANCE"]
234-
scaling_group_project_id = "` + defaultProjectId + `"
253+
scaling_group_project_id = var.default_project
254+
delete_keep_instance = false
255+
node_os="Tencent tlinux release 2.2 (Final)"
235256
236257
auto_scaling_config {
237258
instance_type = var.ins_type
@@ -243,7 +264,6 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
243264
data_disk {
244265
disk_type = "CLOUD_PREMIUM"
245266
disk_size = 50
246-
encrypt = true
247267
}
248268
249269
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
@@ -271,7 +291,6 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
271291
"root-dir=/var/lib/kubelet"
272292
]
273293
}
274-
node_os="Tencent tlinux release 2.2 (Final)"
275294
}
276295
`
277296

@@ -286,8 +305,8 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
286305
retry_policy = "INCREMENTAL_INTERVALS"
287306
desired_capacity = 2
288307
enable_auto_scale = false
289-
node_os = "` + defaultTkeOSImageName + `"
290-
scaling_group_project_id = "` + defaultProjectId + `"
308+
node_os = var.default_img
309+
scaling_group_project_id = var.default_project
291310
delete_keep_instance = false
292311
scaling_group_name = "basic_group_test"
293312
default_cooldown = 350
@@ -314,7 +333,6 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
314333
disk_type = "CLOUD_PREMIUM"
315334
disk_size = 100
316335
delete_with_instance = true
317-
encrypt = true
318336
}
319337
320338
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
@@ -344,3 +362,43 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
344362
}
345363
}
346364
`
365+
366+
const testAccTkeNodePoolClusterEncrypt = testAccTkeNodePoolClusterBasic + `
367+
resource "tencentcloud_kubernetes_node_pool" "np_test" {
368+
name = "np_with_disk_encrypt"
369+
cluster_id = local.cluster_id
370+
max_size = 3
371+
min_size = 1
372+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
373+
subnet_ids = [data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id]
374+
retry_policy = "INCREMENTAL_INTERVALS"
375+
desired_capacity = 1
376+
enable_auto_scale = true
377+
scaling_group_name = "encrypt_asg"
378+
default_cooldown = 400
379+
termination_policies = ["OLDEST_INSTANCE"]
380+
scaling_group_project_id = var.default_project
381+
delete_keep_instance = false
382+
node_os="Tencent tlinux release 2.2 (Final)"
383+
384+
auto_scaling_config {
385+
instance_type = var.ins_type
386+
cam_role_name = "TCB_QcsRole"
387+
system_disk_type = "CLOUD_PREMIUM"
388+
system_disk_size = "50"
389+
security_group_ids = [data.tencentcloud_security_groups.sg.security_groups[0].security_group_id]
390+
391+
data_disk {
392+
disk_type = "CLOUD_PREMIUM"
393+
disk_size = 50
394+
encrypt = true
395+
}
396+
public_ip_assigned = false
397+
password = "test123#"
398+
enhanced_security_service = false
399+
enhanced_monitor_service = false
400+
401+
}
402+
unschedulable = 0
403+
}
404+
`

tencentcloud/service_tencentcloud_tke.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ func (me *TkeService) CreateClusterNodePool(ctx context.Context, clusterId, name
11661166
request.LaunchConfigurePara = &configPara
11671167
request.InstanceAdvancedSettings = &iAdvanced
11681168
request.EnableAutoscale = &enableAutoScale
1169+
//request.DeletionProtection = &deletionProtection
11691170
request.NodePoolOs = &nodeOs
11701171
request.OsCustomizeType = &nodeOsType
11711172

@@ -1207,6 +1208,7 @@ func (me *TkeService) ModifyClusterNodePool(ctx context.Context, clusterId, node
12071208
request.Taints = taints
12081209
request.Labels = labels
12091210
request.EnableAutoscale = &enableAutoScale
1211+
//request.DeletionProtection = &deletionProtection
12101212
request.MaxNodesNum = &maxSize
12111213
request.MinNodesNum = &minSize
12121214
request.Name = &name

website/docs/r/kubernetes_node_pool.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ The `data_disk` object supports the following:
214214
* `delete_with_instance` - (Optional, Bool) Indicates whether the disk remove after instance terminated.
215215
* `disk_size` - (Optional, Int) Volume of disk in GB. Default is `0`.
216216
* `disk_type` - (Optional, String) Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`.
217-
* `encrypt` - (Optional, Bool) Specify whether to encrypt data disk, default: false.
217+
* `encrypt` - (Optional, Bool) Specify whether to encrypt data disk, default: false. NOTE: Make sure the instance type is offering and the cam role `QcloudKMSAccessForCVMRole` was provided.
218218
* `snapshot_id` - (Optional, String, ForceNew) Data disk snapshot ID.
219219
* `throughput_performance` - (Optional, Int) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD` and `data_size` > 460GB.
220220

0 commit comments

Comments
 (0)