@@ -108,6 +108,30 @@ import (
108108 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
109109)
110110
111+ func getNodePoolInstanceTypes (d * schema.ResourceData ) []* string {
112+ configParas := d .Get ("auto_scaling_config" ).([]interface {})
113+ dMap := configParas [0 ].(map [string ]interface {})
114+ instanceType , _ := dMap ["instance_type" ]
115+ currInsType := instanceType .(string )
116+ v , ok := dMap ["backup_instance_types" ]
117+ backupInstanceTypes := v .([]interface {})
118+ instanceTypes := make ([]* string , 0 )
119+ if ! ok || len (backupInstanceTypes ) == 0 {
120+ instanceTypes = append (instanceTypes , & currInsType )
121+ return instanceTypes
122+ }
123+ headType := backupInstanceTypes [0 ].(string )
124+ if headType != currInsType {
125+ instanceTypes = append (instanceTypes , & currInsType )
126+ }
127+ for i := range backupInstanceTypes {
128+ insType := backupInstanceTypes [i ].(string )
129+ instanceTypes = append (instanceTypes , & insType )
130+ }
131+
132+ return instanceTypes
133+ }
134+
111135func composedKubernetesAsScalingConfigPara () map [string ]* schema.Schema {
112136 needSchema := map [string ]* schema.Schema {
113137 "instance_type" : {
@@ -116,6 +140,12 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
116140 ForceNew : true ,
117141 Description : "Specified types of CVM instance." ,
118142 },
143+ "backup_instance_types" : {
144+ Type : schema .TypeList ,
145+ Optional : true ,
146+ Description : "Backup CVM instance types if specified instance type sold out or mismatch." ,
147+ Elem : & schema.Schema {Type : schema .TypeString },
148+ },
119149 "system_disk_type" : {
120150 Type : schema .TypeString ,
121151 Optional : true ,
@@ -457,7 +487,7 @@ func composeParameterToAsScalingGroupParaSerial(d *schema.ResourceData) (string,
457487}
458488
459489//this function is similar to kubernetesAsScalingConfigParaSerial, but less parameter
460- func comosedKubernetesAsScalingConfigParaSerial (dMap map [string ]interface {}, meta interface {}) (string , error ) {
490+ func composedKubernetesAsScalingConfigParaSerial (dMap map [string ]interface {}, meta interface {}) (string , error ) {
461491 var (
462492 result string
463493 errRet error
@@ -687,7 +717,7 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
687717 return err
688718 }
689719
690- configParaStr , err := comosedKubernetesAsScalingConfigParaSerial (configParas [0 ].(map [string ]interface {}), meta )
720+ configParaStr , err := composedKubernetesAsScalingConfigParaSerial (configParas [0 ].(map [string ]interface {}), meta )
691721 if err != nil {
692722 return err
693723 }
@@ -742,7 +772,16 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
742772 return err
743773 }
744774
745- //modify os and image
775+ instanceTypes := getNodePoolInstanceTypes (d )
776+
777+ if len (instanceTypes ) != 0 {
778+ err := service .ModifyClusterNodePoolInstanceTypes (ctx , clusterId , nodePoolId , instanceTypes )
779+ if err != nil {
780+ return err
781+ }
782+ }
783+
784+ //modify os, instanceTypes and image
746785 err = resourceKubernetesNodePoolUpdate (d , meta )
747786 if err != nil {
748787 return err
@@ -811,6 +850,21 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
811850 }
812851 d .SetPartial ("desired_capacity" )
813852 }
853+
854+ if d .HasChange ("auto_scaling_config.0.backup_instance_types" ) {
855+ instanceTypes := getNodePoolInstanceTypes (d )
856+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
857+ errRet := service .ModifyClusterNodePoolInstanceTypes (ctx , clusterId , nodePoolId , instanceTypes )
858+ if errRet != nil {
859+ return retryError (errRet )
860+ }
861+ return nil
862+ })
863+ if err != nil {
864+ return err
865+ }
866+ d .Set ("auto_scaling_config.0.backup_instance_types" , instanceTypes )
867+ }
814868 d .Partial (false )
815869
816870 return resourceKubernetesNodePoolRead (d , meta )
0 commit comments