Skip to content

Commit 594c394

Browse files
authored
fix: tke - data disk add encrypt and ignore 0 disk size (#1128)
* fix: tke - ignore disk size param if zero * fix: tke - data_disk support encrypt and kms key
1 parent 389827e commit 594c394

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
615615
Optional: true,
616616
Description: "Data disk snapshot ID.",
617617
},
618+
"encrypt": {
619+
Type: schema.TypeBool,
620+
Optional: true,
621+
Description: "Indicates whether to encrypt data disk, default `false`.",
622+
},
623+
"kms_key_id": {
624+
Type: schema.TypeString,
625+
Optional: true,
626+
Description: "ID of the custom CMK in the format of UUID or `kms-abcd1234`. This parameter is used to encrypt cloud disks.",
627+
},
618628
"file_system": {
619629
Type: schema.TypeString,
620630
ForceNew: true,
@@ -1503,14 +1513,24 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
15031513
diskType = value["disk_type"].(string)
15041514
diskSize = int64(value["disk_size"].(int))
15051515
snapshotId = value["snapshot_id"].(string)
1516+
encrypt = value["encrypt"].(bool)
1517+
kmsKeyId = value["kms_key_id"].(string)
15061518
dataDisk = cvm.DataDisk{
15071519
DiskType: &diskType,
1508-
DiskSize: &diskSize,
15091520
}
15101521
)
1522+
if diskSize > 0 {
1523+
dataDisk.DiskSize = &diskSize
1524+
}
15111525
if snapshotId != "" {
15121526
dataDisk.SnapshotId = &snapshotId
15131527
}
1528+
if encrypt {
1529+
dataDisk.Encrypt = &encrypt
1530+
}
1531+
if kmsKeyId != "" {
1532+
dataDisk.KmsKeyId = &kmsKeyId
1533+
}
15141534
request.DataDisks = append(request.DataDisks, &dataDisk)
15151535
}
15161536
}

tencentcloud/resource_tc_kubernetes_cluster_attachment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,15 @@ func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) (
325325
diskPartition = value["disk_partition"].(string)
326326
dataDisk = tke.DataDisk{
327327
DiskType: &diskType,
328-
DiskSize: &diskSize,
329328
FileSystem: &fileSystem,
330329
AutoFormatAndMount: &autoFormatAndMount,
331330
MountTarget: &mountTarget,
332331
DiskPartition: &diskPartition,
333332
}
334333
)
334+
if diskSize > 0 {
335+
dataDisk.DiskSize = &diskSize
336+
}
335337
setting.DataDisks = append(setting.DataDisks, &dataDisk)
336338
}
337339
}

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,9 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
654654
deleteWithInstance, dOk := value["delete_with_instance"].(bool)
655655
dataDisk := as.DataDisk{
656656
DiskType: &diskType,
657-
DiskSize: &diskSize,
657+
}
658+
if diskSize > 0 {
659+
dataDisk.DiskSize = &diskSize
658660
}
659661
if snapshotId != "" {
660662
dataDisk.SnapshotId = &snapshotId
@@ -796,7 +798,9 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
796798
deleteWithInstance, dOk := value["delete_with_instance"].(bool)
797799
dataDisk := as.DataDisk{
798800
DiskType: &diskType,
799-
DiskSize: &diskSize,
801+
}
802+
if diskSize > 0 {
803+
dataDisk.DiskSize = &diskSize
800804
}
801805
if snapshotId != "" {
802806
dataDisk.SnapshotId = &snapshotId
@@ -1127,7 +1131,6 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11271131
logId = getLogId(contextNil)
11281132
ctx = context.WithValue(context.TODO(), logIdKey, logId)
11291133
clusterId = d.Get("cluster_id").(string)
1130-
nodeConfig = d.Get("node_config").([]interface{})
11311134
enableAutoScale = d.Get("enable_auto_scale").(bool)
11321135
configParas = d.Get("auto_scaling_config").([]interface{})
11331136
name = d.Get("name").(string)
@@ -1137,10 +1140,6 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11371140
return fmt.Errorf("need only one auto_scaling_config")
11381141
}
11391142

1140-
if len(nodeConfig) > 1 {
1141-
return fmt.Errorf("need only one node_config")
1142-
}
1143-
11441143
groupParaStr, err := composeParameterToAsScalingGroupParaSerial(d)
11451144
if err != nil {
11461145
return err
@@ -1155,13 +1154,8 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11551154
taints := GetTkeTaints(d, "taints")
11561155

11571156
//compose InstanceAdvancedSettings
1158-
if workConfig, ok := d.GetOk("node_config"); ok {
1159-
workConfigList := workConfig.([]interface{})
1160-
if len(workConfigList) == 1 {
1161-
workConfigPara := workConfigList[0].(map[string]interface{})
1162-
setting := tkeGetInstanceAdvancedPara(workConfigPara, meta)
1163-
iAdvanced = setting
1164-
}
1157+
if workConfig, ok := helper.InterfacesHeadMap(d, "node_config"); ok {
1158+
iAdvanced = tkeGetInstanceAdvancedPara(workConfig, meta)
11651159
}
11661160

11671161
if temp, ok := d.GetOk("extra_args"); ok {

website/docs/r/kubernetes_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ The `data_disk` object supports the following:
511511
* `disk_partition` - (Optional, ForceNew) The name of the device or partition to mount.
512512
* `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`.
513513
* `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`.
514+
* `encrypt` - (Optional) Indicates whether to encrypt data disk, default `false`.
514515
* `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`.
516+
* `kms_key_id` - (Optional) ID of the custom CMK in the format of UUID or `kms-abcd1234`. This parameter is used to encrypt cloud disks.
515517
* `mount_target` - (Optional, ForceNew) Mount target.
516518
* `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID.
517519

website/docs/r/kubernetes_scale_worker.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ The `data_disk` object supports the following:
130130
* `disk_partition` - (Optional, ForceNew) The name of the device or partition to mount.
131131
* `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`.
132132
* `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`.
133+
* `encrypt` - (Optional) Indicates whether to encrypt data disk, default `false`.
133134
* `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`.
135+
* `kms_key_id` - (Optional) ID of the custom CMK in the format of UUID or `kms-abcd1234`. This parameter is used to encrypt cloud disks.
134136
* `mount_target` - (Optional, ForceNew) Mount target.
135137
* `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID.
136138

0 commit comments

Comments
 (0)