@@ -153,8 +153,6 @@ import (
153153 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
154154 as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
155155 sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
156- cwp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp/v20180228"
157- tat "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat/v20201028"
158156 tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
159157 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
160158)
@@ -1388,73 +1386,77 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
13881386 return err
13891387 }
13901388
1391- // step 2: change existed cvm security service if necessary
1392- workersInsIdOfNodePool := make ([]string , 0 )
1393- _ , workers , err := service .DescribeClusterInstances (ctx , clusterId )
1394- if err != nil {
1389+ // change existed cvm security service if necessary
1390+ if err := ModifySecurityServiceOfCvmInNodePool (ctx , d , & service , & cvmService , client , clusterId , * nodePool .NodePoolId ); err != nil {
13951391 return err
13961392 }
1397- for _ , worker := range workers {
1398- if worker .NodePoolId != "" && worker .NodePoolId == * nodePool .NodePoolId {
1399- workersInsIdOfNodePool = append (workersInsIdOfNodePool , worker .InstanceId )
1400- }
1401- }
1402-
1403- if d .HasChange ("auto_scaling_config.0.enhanced_security_service" ) {
1404- const BatchProcessedInsLimit = 100 // limit 100 items to change each request
1405- launchConfigRaw := d .Get ("auto_scaling_config" ).([]interface {})
1406- dMap := launchConfigRaw [0 ].(map [string ]interface {})
1407-
1408- if v , ok := dMap ["enhanced_security_service" ]; ok && ! v .(bool ) {
1409- // uninstall, cwp/DeleteMachine, need uuid
1410- // https://cloud.tencent.com/document/product/296/19844
1411- for i := 0 ; i < len (workersInsIdOfNodePool ); i += BatchProcessedInsLimit {
1412- var reqInstanceIds []string
1413- if i + BatchProcessedInsLimit <= len (workersInsIdOfNodePool ) {
1414- reqInstanceIds = workersInsIdOfNodePool [i : i + BatchProcessedInsLimit ]
1415- } else {
1416- reqInstanceIds = workersInsIdOfNodePool [i :]
1417- }
1418- // get uuid
1419- instanceSet , err := cvmService .DescribeInstanceSetByIds (ctx , helper .StrListToStr (helper .StringsStringsPoint (reqInstanceIds )))
1420- if err != nil {
1421- return err
1422- }
1423- // call cwp/DeleteMachine
1424- for _ , ins := range instanceSet {
1425- requestDeleteMachine := cwp .NewDeleteMachineRequest ()
1426- requestDeleteMachine .Uuid = ins .Uuid
1427- if _ , err := client .UseCwpClient ().DeleteMachine (requestDeleteMachine ); err != nil {
1428- return err
1429- }
1430- }
1431- }
1432- } else {
1433- // default is true, install security agent
1434- // tat/InvokeCommand, CommandId=cmd-d8jj2skv, instanceId is enough
1435- // https://cloud.tencent.com/document/product/1340/52678
1436- for i := 0 ; i < len (workersInsIdOfNodePool ); i += BatchProcessedInsLimit {
1437- var reqInstanceIds []string
1438- if i + BatchProcessedInsLimit <= len (workersInsIdOfNodePool ) {
1439- reqInstanceIds = workersInsIdOfNodePool [i : i + BatchProcessedInsLimit ]
1440- } else {
1441- reqInstanceIds = workersInsIdOfNodePool [i :]
1442- }
1443- requestInvokeCommand := tat .NewInvokeCommandRequest ()
1444- requestInvokeCommand .InstanceIds = helper .StringsStringsPoint (reqInstanceIds )
1445- requestInvokeCommand .CommandId = helper .String (InstallSecurityAgentCommandId )
1446- requestInvokeCommand .Parameters = helper .String ("{}" )
1447- requestInvokeCommand .Timeout = helper .Uint64 (60 )
1448- _ , err := client .UseTatClient ().InvokeCommand (requestInvokeCommand )
1449- if err != nil {
1450- log .Printf ("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n " ,
1451- logId , request .GetAction (), request .ToJsonString (), err .Error ())
1452- return err
1453- }
1454- }
14551393
1456- }
1457- }
1394+ //workersInsIdOfNodePool := make([]string, 0)
1395+ //_, workers, err := service.DescribeClusterInstances(ctx, clusterId)
1396+ //if err != nil {
1397+ // return err
1398+ //}
1399+ //for _, worker := range workers {
1400+ // if worker.NodePoolId != "" && worker.NodePoolId == *nodePool.NodePoolId {
1401+ // workersInsIdOfNodePool = append(workersInsIdOfNodePool, worker.InstanceId)
1402+ // }
1403+ //}
1404+
1405+ //if d.HasChange("auto_scaling_config.0.enhanced_security_service") {
1406+ // const BatchProcessedInsLimit = 100 // limit 100 items to change each request
1407+ // launchConfigRaw := d.Get("auto_scaling_config").([]interface{})
1408+ // dMap := launchConfigRaw[0].(map[string]interface{})
1409+ //
1410+ // if v, ok := dMap["enhanced_security_service"]; ok && !v.(bool) {
1411+ // // uninstall, cwp/DeleteMachine, need uuid
1412+ // // https://cloud.tencent.com/document/product/296/19844
1413+ // for i := 0; i < len(workersInsIdOfNodePool); i += BatchProcessedInsLimit {
1414+ // var reqInstanceIds []string
1415+ // if i+BatchProcessedInsLimit <= len(workersInsIdOfNodePool) {
1416+ // reqInstanceIds = workersInsIdOfNodePool[i : i+BatchProcessedInsLimit]
1417+ // } else {
1418+ // reqInstanceIds = workersInsIdOfNodePool[i:]
1419+ // }
1420+ // // get uuid
1421+ // instanceSet, err := cvmService.DescribeInstanceSetByIds(ctx, helper.StrListToStr(helper.StringsStringsPoint(reqInstanceIds)))
1422+ // if err != nil {
1423+ // return err
1424+ // }
1425+ // // call cwp/DeleteMachine
1426+ // for _, ins := range instanceSet {
1427+ // requestDeleteMachine := cwp.NewDeleteMachineRequest()
1428+ // requestDeleteMachine.Uuid = ins.Uuid
1429+ // if _, err := client.UseCwpClient().DeleteMachine(requestDeleteMachine); err != nil {
1430+ // return err
1431+ // }
1432+ // }
1433+ // }
1434+ // } else {
1435+ // // default is true, install security agent
1436+ // // tat/InvokeCommand, CommandId=cmd-d8jj2skv, instanceId is enough
1437+ // // https://cloud.tencent.com/document/product/1340/52678
1438+ // for i := 0; i < len(workersInsIdOfNodePool); i += BatchProcessedInsLimit {
1439+ // var reqInstanceIds []string
1440+ // if i+BatchProcessedInsLimit <= len(workersInsIdOfNodePool) {
1441+ // reqInstanceIds = workersInsIdOfNodePool[i : i+BatchProcessedInsLimit]
1442+ // } else {
1443+ // reqInstanceIds = workersInsIdOfNodePool[i:]
1444+ // }
1445+ // requestInvokeCommand := tat.NewInvokeCommandRequest()
1446+ // requestInvokeCommand.InstanceIds = helper.StringsStringsPoint(reqInstanceIds)
1447+ // requestInvokeCommand.CommandId = helper.String(InstallSecurityAgentCommandId)
1448+ // requestInvokeCommand.Parameters = helper.String("{}")
1449+ // requestInvokeCommand.Timeout = helper.Uint64(60)
1450+ // _, err := client.UseTatClient().InvokeCommand(requestInvokeCommand)
1451+ // if err != nil {
1452+ // log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
1453+ // logId, request.GetAction(), request.ToJsonString(), err.Error())
1454+ // return err
1455+ // }
1456+ // }
1457+ //
1458+ // }
1459+ //}
14581460 d .SetPartial ("auto_scaling_config" )
14591461 }
14601462
0 commit comments