From c39d333a4654bfba23e9c43e50f5cc5fdbbb6ae1 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Fri, 1 Jul 2022 15:12:12 +0800 Subject: [PATCH 1/2] fix: tke - ignore disk size param if zero --- .../resource_tc_kubernetes_cluster.go | 4 +++- ...source_tc_kubernetes_cluster_attachment.go | 4 +++- .../resource_tc_kubernetes_node_pool.go | 22 +++++++------------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tencentcloud/resource_tc_kubernetes_cluster.go b/tencentcloud/resource_tc_kubernetes_cluster.go index 8d460fa68f..ddbda80ecf 100644 --- a/tencentcloud/resource_tc_kubernetes_cluster.go +++ b/tencentcloud/resource_tc_kubernetes_cluster.go @@ -1505,9 +1505,11 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{}, snapshotId = value["snapshot_id"].(string) dataDisk = cvm.DataDisk{ DiskType: &diskType, - DiskSize: &diskSize, } ) + if diskSize > 0 { + dataDisk.DiskSize = &diskSize + } if snapshotId != "" { dataDisk.SnapshotId = &snapshotId } diff --git a/tencentcloud/resource_tc_kubernetes_cluster_attachment.go b/tencentcloud/resource_tc_kubernetes_cluster_attachment.go index 8c3cbba8f8..f638114e40 100644 --- a/tencentcloud/resource_tc_kubernetes_cluster_attachment.go +++ b/tencentcloud/resource_tc_kubernetes_cluster_attachment.go @@ -325,13 +325,15 @@ func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) ( diskPartition = value["disk_partition"].(string) dataDisk = tke.DataDisk{ DiskType: &diskType, - DiskSize: &diskSize, FileSystem: &fileSystem, AutoFormatAndMount: &autoFormatAndMount, MountTarget: &mountTarget, DiskPartition: &diskPartition, } ) + if diskSize > 0 { + dataDisk.DiskSize = &diskSize + } setting.DataDisks = append(setting.DataDisks, &dataDisk) } } diff --git a/tencentcloud/resource_tc_kubernetes_node_pool.go b/tencentcloud/resource_tc_kubernetes_node_pool.go index aaae6f6cac..aea45c0b6c 100644 --- a/tencentcloud/resource_tc_kubernetes_node_pool.go +++ b/tencentcloud/resource_tc_kubernetes_node_pool.go @@ -654,7 +654,9 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me deleteWithInstance, dOk := value["delete_with_instance"].(bool) dataDisk := as.DataDisk{ DiskType: &diskType, - DiskSize: &diskSize, + } + if diskSize > 0 { + dataDisk.DiskSize = &diskSize } if snapshotId != "" { dataDisk.SnapshotId = &snapshotId @@ -796,7 +798,9 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s deleteWithInstance, dOk := value["delete_with_instance"].(bool) dataDisk := as.DataDisk{ DiskType: &diskType, - DiskSize: &diskSize, + } + if diskSize > 0 { + dataDisk.DiskSize = &diskSize } if snapshotId != "" { dataDisk.SnapshotId = &snapshotId @@ -1127,7 +1131,6 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{}) logId = getLogId(contextNil) ctx = context.WithValue(context.TODO(), logIdKey, logId) clusterId = d.Get("cluster_id").(string) - nodeConfig = d.Get("node_config").([]interface{}) enableAutoScale = d.Get("enable_auto_scale").(bool) configParas = d.Get("auto_scaling_config").([]interface{}) name = d.Get("name").(string) @@ -1137,10 +1140,6 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("need only one auto_scaling_config") } - if len(nodeConfig) > 1 { - return fmt.Errorf("need only one node_config") - } - groupParaStr, err := composeParameterToAsScalingGroupParaSerial(d) if err != nil { return err @@ -1155,13 +1154,8 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{}) taints := GetTkeTaints(d, "taints") //compose InstanceAdvancedSettings - if workConfig, ok := d.GetOk("node_config"); ok { - workConfigList := workConfig.([]interface{}) - if len(workConfigList) == 1 { - workConfigPara := workConfigList[0].(map[string]interface{}) - setting := tkeGetInstanceAdvancedPara(workConfigPara, meta) - iAdvanced = setting - } + if workConfig, ok := helper.InterfacesHeadMap(d, "node_config"); ok { + iAdvanced = tkeGetInstanceAdvancedPara(workConfig, meta) } if temp, ok := d.GetOk("extra_args"); ok { From b8deabc0a4393950e243892b70d3ad84646f832e Mon Sep 17 00:00:00 2001 From: Kagashino Date: Fri, 1 Jul 2022 15:35:20 +0800 Subject: [PATCH 2/2] fix: tke - data_disk support encrypt and kms key --- tencentcloud/resource_tc_kubernetes_cluster.go | 18 ++++++++++++++++++ .../docs/r/kubernetes_cluster.html.markdown | 2 ++ .../r/kubernetes_scale_worker.html.markdown | 2 ++ 3 files changed, 22 insertions(+) diff --git a/tencentcloud/resource_tc_kubernetes_cluster.go b/tencentcloud/resource_tc_kubernetes_cluster.go index ddbda80ecf..2aeefff3ed 100644 --- a/tencentcloud/resource_tc_kubernetes_cluster.go +++ b/tencentcloud/resource_tc_kubernetes_cluster.go @@ -615,6 +615,16 @@ func TkeCvmCreateInfo() map[string]*schema.Schema { Optional: true, Description: "Data disk snapshot ID.", }, + "encrypt": { + Type: schema.TypeBool, + Optional: true, + Description: "Indicates whether to encrypt data disk, default `false`.", + }, + "kms_key_id": { + Type: schema.TypeString, + Optional: true, + Description: "ID of the custom CMK in the format of UUID or `kms-abcd1234`. This parameter is used to encrypt cloud disks.", + }, "file_system": { Type: schema.TypeString, ForceNew: true, @@ -1503,6 +1513,8 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{}, diskType = value["disk_type"].(string) diskSize = int64(value["disk_size"].(int)) snapshotId = value["snapshot_id"].(string) + encrypt = value["encrypt"].(bool) + kmsKeyId = value["kms_key_id"].(string) dataDisk = cvm.DataDisk{ DiskType: &diskType, } @@ -1513,6 +1525,12 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{}, if snapshotId != "" { dataDisk.SnapshotId = &snapshotId } + if encrypt { + dataDisk.Encrypt = &encrypt + } + if kmsKeyId != "" { + dataDisk.KmsKeyId = &kmsKeyId + } request.DataDisks = append(request.DataDisks, &dataDisk) } } diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index ab3d58ac3b..cc19770f00 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -511,7 +511,9 @@ The `data_disk` object supports the following: * `disk_partition` - (Optional, ForceNew) The name of the device or partition to mount. * `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`. * `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`. +* `encrypt` - (Optional) Indicates whether to encrypt data disk, default `false`. * `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`. +* `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. * `mount_target` - (Optional, ForceNew) Mount target. * `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID. diff --git a/website/docs/r/kubernetes_scale_worker.html.markdown b/website/docs/r/kubernetes_scale_worker.html.markdown index ab42209383..957d243a75 100644 --- a/website/docs/r/kubernetes_scale_worker.html.markdown +++ b/website/docs/r/kubernetes_scale_worker.html.markdown @@ -130,7 +130,9 @@ The `data_disk` object supports the following: * `disk_partition` - (Optional, ForceNew) The name of the device or partition to mount. * `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is `0`. * `disk_type` - (Optional, ForceNew) Types of disk, available values: `CLOUD_PREMIUM` and `CLOUD_SSD` and `CLOUD_HSSD` and `CLOUD_TSSD`. +* `encrypt` - (Optional) Indicates whether to encrypt data disk, default `false`. * `file_system` - (Optional, ForceNew) File system, e.g. `ext3/ext4/xfs`. +* `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. * `mount_target` - (Optional, ForceNew) Mount target. * `snapshot_id` - (Optional, ForceNew) Data disk snapshot ID.