@@ -215,17 +215,17 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
215215 Elem : & schema.Resource {
216216 Schema : map [string ]* schema.Schema {
217217 "disk_type" : {
218- Type : schema .TypeString ,
219- Optional : true ,
220- ForceNew : true ,
218+ Type : schema .TypeString ,
219+ Optional : true ,
220+ // ForceNew: true,
221221 Default : SYSTEM_DISK_TYPE_CLOUD_PREMIUM ,
222222 ValidateFunc : validateAllowedStringValue (SYSTEM_DISK_ALLOW_TYPE ),
223223 Description : "Types of disk. Valid value: `CLOUD_PREMIUM` and `CLOUD_SSD`." ,
224224 },
225225 "disk_size" : {
226- Type : schema .TypeInt ,
227- Optional : true ,
228- ForceNew : true ,
226+ Type : schema .TypeInt ,
227+ Optional : true ,
228+ // ForceNew: true,
229229 Default : 0 ,
230230 Description : "Volume of disk in GB. Default is `0`." ,
231231 },
@@ -240,6 +240,16 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
240240 Optional : true ,
241241 Description : "Indicates whether the disk remove after instance terminated." ,
242242 },
243+ "encrypt" : {
244+ Type : schema .TypeBool ,
245+ Optional : true ,
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." ,
247+ },
248+ "throughput_performance" : {
249+ Type : schema .TypeInt ,
250+ Optional : true ,
251+ Description : "Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD` and `data_size` > 460GB." ,
252+ },
243253 },
244254 },
245255 },
@@ -487,6 +497,11 @@ func ResourceTencentCloudKubernetesNodePool() *schema.Resource {
487497 Default : true ,
488498 Description : "Indicate to keep the CVM instance when delete the node pool. Default is `true`." ,
489499 },
500+ //"deletion_protection": {
501+ // Type: schema.TypeBool,
502+ // Optional: true,
503+ // Description: "Indicates whether the node pool deletion protection is enabled.",
504+ //},
490505 "node_os" : {
491506 Type : schema .TypeString ,
492507 Optional : true ,
@@ -651,6 +666,8 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
651666 diskSize := uint64 (value ["disk_size" ].(int ))
652667 snapshotId := value ["snapshot_id" ].(string )
653668 deleteWithInstance , dOk := value ["delete_with_instance" ].(bool )
669+ encrypt , eOk := value ["encrypt" ].(bool )
670+ throughputPerformance := value ["throughput_performance" ].(int )
654671 dataDisk := as.DataDisk {
655672 DiskType : & diskType ,
656673 }
@@ -663,6 +680,12 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
663680 if dOk {
664681 dataDisk .DeleteWithInstance = & deleteWithInstance
665682 }
683+ if eOk {
684+ dataDisk .Encrypt = & encrypt
685+ }
686+ if throughputPerformance > 0 {
687+ dataDisk .ThroughputPerformance = helper .IntUint64 (throughputPerformance )
688+ }
666689 request .DataDisks = append (request .DataDisks , & dataDisk )
667690 }
668691 }
@@ -795,6 +818,8 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
795818 diskSize := uint64 (value ["disk_size" ].(int ))
796819 snapshotId := value ["snapshot_id" ].(string )
797820 deleteWithInstance , dOk := value ["delete_with_instance" ].(bool )
821+ encrypt , eOk := value ["encrypt" ].(bool )
822+ throughputPerformance := value ["throughput_performance" ].(int )
798823 dataDisk := as.DataDisk {
799824 DiskType : & diskType ,
800825 }
@@ -807,6 +832,12 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
807832 if dOk {
808833 dataDisk .DeleteWithInstance = & deleteWithInstance
809834 }
835+ if eOk {
836+ dataDisk .Encrypt = & encrypt
837+ }
838+ if throughputPerformance > 0 {
839+ dataDisk .ThroughputPerformance = helper .IntUint64 (throughputPerformance )
840+ }
810841 request .DataDisks = append (request .DataDisks , & dataDisk )
811842 }
812843 } else {
@@ -871,6 +902,13 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
871902 return request
872903}
873904
905+ func desiredCapacityOutRange (d * schema.ResourceData ) bool {
906+ capacity := d .Get ("desired_capacity" ).(int )
907+ minSize := d .Get ("min_size" ).(int )
908+ maxSize := d .Get ("max_size" ).(int )
909+ return capacity > maxSize || capacity < minSize
910+ }
911+
874912func resourceKubernetesNodePoolRead (d * schema.ResourceData , meta interface {}) error {
875913 defer logElapsed ("resource.tencentcloud_kubernetes_node_pool.read" )()
876914
@@ -967,6 +1005,10 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
9671005 _ = d .Set ("node_os_type" , nodePool .OsCustomizeType )
9681006 }
9691007
1008+ //if nodePool.DeletionProtection != nil {
1009+ // _ = d.Set("deletion_protection", nodePool.DeletionProtection)
1010+ //}
1011+
9701012 //set composed struct
9711013 lables := make (map [string ]interface {}, len (nodePool .Labels ))
9721014 for _ , v := range nodePool .Labels {
@@ -1031,6 +1073,12 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
10311073 if item .DeleteWithInstance != nil {
10321074 disk ["delete_with_instance" ] = * item .DeleteWithInstance
10331075 }
1076+ if item .Encrypt != nil {
1077+ disk ["encrypt" ] = * item .Encrypt
1078+ }
1079+ if item .ThroughputPerformance != nil {
1080+ disk ["throughput_performance" ] = * item .ThroughputPerformance
1081+ }
10341082 dataDisks = append (dataDisks , disk )
10351083 }
10361084 launchConfig ["data_disk" ] = dataDisks
@@ -1155,6 +1203,8 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
11551203 nodeOs := d .Get ("node_os" ).(string )
11561204 nodeOsType := d .Get ("node_os_type" ).(string )
11571205
1206+ //deletionProtection := d.Get("deletion_protection").(bool)
1207+
11581208 service := TkeService {client : meta .(* TencentCloudClient ).apiV3Conn }
11591209
11601210 nodePoolId , err := service .CreateClusterNodePool (ctx , clusterId , name , groupParaStr , configParaStr , enableAutoScale , nodeOs , nodeOsType , labels , taints , iAdvanced )
@@ -1233,11 +1283,43 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12331283 d .SetPartial ("auto_scaling_config" )
12341284 }
12351285
1286+ var capacityHasChanged = false
1287+ // assuming
1288+ // min 1 max 6 desired 2
1289+ // to
1290+ // min 3 max 6 desired 5
1291+ // modify min/max first will cause error, this case must upgrade desired first
1292+ if d .HasChange ("desired_capacity" ) || ! desiredCapacityOutRange (d ) {
1293+ desiredCapacity := int64 (d .Get ("desired_capacity" ).(int ))
1294+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
1295+ errRet := service .ModifyClusterNodePoolDesiredCapacity (ctx , clusterId , nodePoolId , desiredCapacity )
1296+ if errRet != nil {
1297+ return retryError (errRet )
1298+ }
1299+ return nil
1300+ })
1301+ if err != nil {
1302+ return err
1303+ }
1304+ capacityHasChanged = true
1305+ }
1306+
12361307 // ModifyClusterNodePool
1237- 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+ ) {
12381319 maxSize := int64 (d .Get ("max_size" ).(int ))
12391320 minSize := int64 (d .Get ("min_size" ).(int ))
12401321 enableAutoScale := d .Get ("enable_auto_scale" ).(bool )
1322+ //deletionProtection := d.Get("deletion_protection").(bool)
12411323 name := d .Get ("name" ).(string )
12421324 nodeOs := d .Get ("node_os" ).(string )
12431325 nodeOsType := d .Get ("node_os_type" ).(string )
@@ -1253,14 +1335,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
12531335 if err != nil {
12541336 return err
12551337 }
1256- d .SetPartial ("min_size" )
1257- d .SetPartial ("max_size" )
1258- d .SetPartial ("name" )
1259- d .SetPartial ("enable_auto_scale" )
1260- d .SetPartial ("node_os" )
1261- d .SetPartial ("node_os_type" )
1262- d .SetPartial ("labels" )
1263- d .SetPartial ("taints" )
12641338 }
12651339
12661340 // ModifyScalingGroup
@@ -1329,7 +1403,7 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13291403 d .SetPartial ("termination_policies" )
13301404 }
13311405
1332- if d .HasChange ("desired_capacity" ) {
1406+ if d .HasChange ("desired_capacity" ) && ! capacityHasChanged {
13331407 desiredCapacity := int64 (d .Get ("desired_capacity" ).(int ))
13341408 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
13351409 errRet := service .ModifyClusterNodePoolDesiredCapacity (ctx , clusterId , nodePoolId , desiredCapacity )
@@ -1341,7 +1415,6 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13411415 if err != nil {
13421416 return err
13431417 }
1344- d .SetPartial ("desired_capacity" )
13451418 }
13461419
13471420 if d .HasChange ("auto_scaling_config.0.backup_instance_types" ) {
@@ -1372,13 +1445,18 @@ func resourceKubernetesNodePoolDelete(d *schema.ResourceData, meta interface{})
13721445 service = TkeService {client : meta .(* TencentCloudClient ).apiV3Conn }
13731446 items = strings .Split (d .Id (), FILED_SP )
13741447 deleteKeepInstance = d .Get ("delete_keep_instance" ).(bool )
1448+ //deletionProtection = d.Get("deletion_protection").(bool)
13751449 )
13761450 if len (items ) != 2 {
13771451 return fmt .Errorf ("resource_tc_kubernetes_node_pool id is broken" )
13781452 }
13791453 clusterId := items [0 ]
13801454 nodePoolId := items [1 ]
13811455
1456+ //if deletionProtection {
1457+ // return fmt.Errorf("deletion protection was enabled, please set `deletion_protection` to `false` and apply first")
1458+ //}
1459+
13821460 //delete as group
13831461 hasDelete := false
13841462 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
0 commit comments