@@ -331,10 +331,21 @@ func composedKubernetesAsScalingConfigPara() map[string]*schema.Schema {
331331 Description : "ID list of keys." ,
332332 },
333333 "security_group_ids" : {
334- Type : schema .TypeSet ,
335- Optional : true ,
336- Elem : & schema.Schema {Type : schema .TypeString },
337- Description : "Security groups to which a CVM instance belongs." ,
334+ Type : schema .TypeSet ,
335+ Optional : true ,
336+ Computed : true ,
337+ Elem : & schema.Schema {Type : schema .TypeString },
338+ ConflictsWith : []string {"auto_scaling_config.0.orderly_security_group_ids" },
339+ Deprecated : "The order of elements in this field cannot be guaranteed. Use `orderly_security_group_ids` instead." ,
340+ Description : "Security groups to which a CVM instance belongs." ,
341+ },
342+ "orderly_security_group_ids" : {
343+ Type : schema .TypeList ,
344+ Optional : true ,
345+ Computed : true ,
346+ Elem : & schema.Schema {Type : schema .TypeString },
347+ ConflictsWith : []string {"auto_scaling_config.0.security_group_ids" },
348+ Description : "Ordered security groups to which a CVM instance belongs." ,
338349 },
339350 "enhanced_security_service" : {
340351 Type : schema .TypeBool ,
@@ -764,7 +775,16 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
764775 }
765776
766777 if v , ok := dMap ["security_group_ids" ]; ok {
767- request .SecurityGroupIds = helper .InterfacesStringsPoint (v .(* schema.Set ).List ())
778+ if list := v .(* schema.Set ).List (); len (list ) > 0 {
779+ errRet = fmt .Errorf ("The parameter `security_group_ids` has an issue that the actual order of the security group may be inconsistent with the order of your tf code, which will cause your service to be inaccessible. Please use `orderly_security_group_ids` instead." )
780+ return result , errRet
781+ }
782+ }
783+
784+ if v , ok := dMap ["orderly_security_group_ids" ]; ok {
785+ if list := v .([]interface {}); len (list ) > 0 {
786+ request .SecurityGroupIds = helper .InterfacesStringsPoint (list )
787+ }
768788 }
769789
770790 request .EnhancedService = & as.EnhancedService {}
@@ -843,7 +863,7 @@ func composedKubernetesAsScalingConfigParaSerial(dMap map[string]interface{}, me
843863 return result , errRet
844864}
845865
846- func composeAsLaunchConfigModifyRequest (d * schema.ResourceData , launchConfigId string ) * as.ModifyLaunchConfigurationAttributesRequest {
866+ func composeAsLaunchConfigModifyRequest (d * schema.ResourceData , launchConfigId string ) ( * as.ModifyLaunchConfigurationAttributesRequest , error ) {
847867 launchConfigRaw := d .Get ("auto_scaling_config" ).([]interface {})
848868 dMap := launchConfigRaw [0 ].(map [string ]interface {})
849869 request := as .NewModifyLaunchConfigurationAttributesRequest ()
@@ -910,8 +930,21 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
910930 request .InternetAccessible .PublicIpAssigned = & publicIpAssigned
911931 }
912932
913- if v , ok := dMap ["security_group_ids" ]; ok {
914- request .SecurityGroupIds = helper .InterfacesStringsPoint (v .(* schema.Set ).List ())
933+ if d .HasChange ("auto_scaling_config.0.security_group_ids" ) {
934+ if v , ok := dMap ["security_group_ids" ]; ok {
935+ if list := v .(* schema.Set ).List (); len (list ) > 0 {
936+ errRet := fmt .Errorf ("The parameter `security_group_ids` has an issue that the actual order of the security group may be inconsistent with the order of your tf code, which will cause your service to be inaccessible. You can check whether the order of your current security groups meets your expectations through the TencentCloud Console, then use `orderly_security_group_ids` field to update them." )
937+ return nil , errRet
938+ }
939+ }
940+ }
941+
942+ if d .HasChange ("auto_scaling_config.0.orderly_security_group_ids" ) {
943+ if v , ok := dMap ["orderly_security_group_ids" ]; ok {
944+ if list := v .([]interface {}); len (list ) > 0 {
945+ request .SecurityGroupIds = helper .InterfacesStringsPoint (list )
946+ }
947+ }
915948 }
916949
917950 chargeType , ok := dMap ["instance_charge_type" ].(string )
@@ -986,7 +1019,7 @@ func composeAsLaunchConfigModifyRequest(d *schema.ResourceData, launchConfigId s
9861019
9871020 request .InstanceChargeType = & chargeType
9881021
989- return request
1022+ return request , nil
9901023}
9911024
9921025func desiredCapacityOutRange (d * schema.ResourceData ) bool {
@@ -1186,7 +1219,11 @@ func resourceKubernetesNodePoolRead(d *schema.ResourceData, meta interface{}) er
11861219 if v , ok := d .GetOk ("auto_scaling_config.0.password" ); ok {
11871220 launchConfig ["password" ] = v .(string )
11881221 }
1189- launchConfig ["security_group_ids" ] = helper .StringsInterfaces (launchCfg .SecurityGroupIds )
1222+
1223+ if launchCfg .SecurityGroupIds != nil {
1224+ launchConfig ["security_group_ids" ] = helper .StringsInterfaces (launchCfg .SecurityGroupIds )
1225+ launchConfig ["orderly_security_group_ids" ] = helper .StringsInterfaces (launchCfg .SecurityGroupIds )
1226+ }
11901227
11911228 enableSecurity := launchCfg .EnhancedService .SecurityService .Enabled
11921229 enableMonitor := launchCfg .EnhancedService .MonitorService .Enabled
@@ -1381,7 +1418,10 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13811418 }
13821419 launchConfigId := * nodePool .LaunchConfigurationId
13831420 // change as config here
1384- request := composeAsLaunchConfigModifyRequest (d , launchConfigId )
1421+ request , composeError := composeAsLaunchConfigModifyRequest (d , launchConfigId )
1422+ if composeError != nil {
1423+ return composeError
1424+ }
13851425 _ , err = client .UseAsClient ().ModifyLaunchConfigurationAttributes (request )
13861426 if err != nil {
13871427 log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
0 commit comments