@@ -108,6 +108,30 @@ import (
108
108
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
109
109
)
110
110
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
+
111
135
func composedKubernetesAsScalingConfigPara () map [string ]* schema.Schema {
112
136
needSchema := map [string ]* schema.Schema {
113
137
"instance_type" : {
@@ -116,6 +140,12 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
116
140
ForceNew : true ,
117
141
Description : "Specified types of CVM instance." ,
118
142
},
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
+ },
119
149
"system_disk_type" : {
120
150
Type : schema .TypeString ,
121
151
Optional : true ,
@@ -457,7 +487,7 @@ func composeParameterToAsScalingGroupParaSerial(d *schema.ResourceData) (string,
457
487
}
458
488
459
489
//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 ) {
461
491
var (
462
492
result string
463
493
errRet error
@@ -687,7 +717,7 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
687
717
return err
688
718
}
689
719
690
- configParaStr , err := comosedKubernetesAsScalingConfigParaSerial (configParas [0 ].(map [string ]interface {}), meta )
720
+ configParaStr , err := composedKubernetesAsScalingConfigParaSerial (configParas [0 ].(map [string ]interface {}), meta )
691
721
if err != nil {
692
722
return err
693
723
}
@@ -742,7 +772,16 @@ func resourceKubernetesNodePoolCreate(d *schema.ResourceData, meta interface{})
742
772
return err
743
773
}
744
774
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
746
785
err = resourceKubernetesNodePoolUpdate (d , meta )
747
786
if err != nil {
748
787
return err
@@ -811,6 +850,21 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
811
850
}
812
851
d .SetPartial ("desired_capacity" )
813
852
}
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
+ }
814
868
d .Partial (false )
815
869
816
870
return resourceKubernetesNodePoolRead (d , meta )
0 commit comments