@@ -46,7 +46,90 @@ func customScaleWorkerResourceImporter(ctx context.Context, d *schema.ResourceDa
4646 return []* schema.ResourceData {d }, nil
4747}
4848
49- func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1 (ctx context.Context , req * tke.DescribeClusterInstancesRequest , resp * tke.DescribeClusterInstancesResponse ) error {
49+ func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1 (ctx context.Context , req * cvm.DescribeInstancesRequest , resp * cvm.DescribeInstancesResponse ) error {
50+ d := tccommon .ResourceDataFromContext (ctx )
51+
52+ instances := make ([]* cvm.Instance , 0 )
53+ instances = append (instances , resp .Response .InstanceSet ... )
54+
55+ instanceList := make ([]interface {}, 0 , len (instances ))
56+ for _ , instance := range instances {
57+ mapping := map [string ]interface {}{
58+ "count" : 1 ,
59+ "instance_charge_type_prepaid_period" : 1 ,
60+ "instance_type" : helper .PString (instance .InstanceType ),
61+ "subnet_id" : helper .PString (instance .VirtualPrivateCloud .SubnetId ),
62+ "availability_zone" : helper .PString (instance .Placement .Zone ),
63+ "instance_name" : helper .PString (instance .InstanceName ),
64+ "instance_charge_type" : helper .PString (instance .InstanceChargeType ),
65+ "system_disk_type" : helper .PString (instance .SystemDisk .DiskType ),
66+ "system_disk_size" : helper .PInt64 (instance .SystemDisk .DiskSize ),
67+ "internet_charge_type" : helper .PString (instance .InternetAccessible .InternetChargeType ),
68+ "bandwidth_package_id" : helper .PString (instance .InternetAccessible .BandwidthPackageId ),
69+ "internet_max_bandwidth_out" : helper .PInt64 (instance .InternetAccessible .InternetMaxBandwidthOut ),
70+ "security_group_ids" : helper .StringsInterfaces (instance .SecurityGroupIds ),
71+ "img_id" : helper .PString (instance .ImageId ),
72+ }
73+
74+ if instance .RenewFlag != nil && helper .PString (instance .InstanceChargeType ) == "PREPAID" {
75+ mapping ["instance_charge_type_prepaid_renew_flag" ] = helper .PString (instance .RenewFlag )
76+ } else {
77+ mapping ["instance_charge_type_prepaid_renew_flag" ] = ""
78+ }
79+ if helper .PInt64 (instance .InternetAccessible .InternetMaxBandwidthOut ) > 0 {
80+ mapping ["public_ip_assigned" ] = true
81+ }
82+
83+ if instance .CamRoleName != nil {
84+ mapping ["cam_role_name" ] = instance .CamRoleName
85+ }
86+ if instance .LoginSettings != nil {
87+ if instance .LoginSettings .KeyIds != nil && len (instance .LoginSettings .KeyIds ) > 0 {
88+ mapping ["key_ids" ] = helper .StringsInterfaces (instance .LoginSettings .KeyIds )
89+ }
90+ if instance .LoginSettings .Password != nil {
91+ mapping ["password" ] = helper .PString (instance .LoginSettings .Password )
92+ }
93+ }
94+ if instance .DisasterRecoverGroupId != nil && helper .PString (instance .DisasterRecoverGroupId ) != "" {
95+ mapping ["disaster_recover_group_ids" ] = []string {helper .PString (instance .DisasterRecoverGroupId )}
96+ }
97+ if instance .HpcClusterId != nil {
98+ mapping ["hpc_cluster_id" ] = helper .PString (instance .HpcClusterId )
99+ }
100+
101+ dataDisks := make ([]interface {}, 0 , len (instance .DataDisks ))
102+ for _ , v := range instance .DataDisks {
103+ dataDisk := map [string ]interface {}{
104+ "disk_type" : helper .PString (v .DiskType ),
105+ "disk_size" : helper .PInt64 (v .DiskSize ),
106+ "snapshot_id" : helper .PString (v .DiskId ),
107+ "encrypt" : helper .PBool (v .Encrypt ),
108+ "kms_key_id" : helper .PString (v .KmsKeyId ),
109+ }
110+ dataDisks = append (dataDisks , dataDisk )
111+ }
112+
113+ mapping ["data_disk" ] = dataDisks // worker_config.data_disk
114+ instanceList = append (instanceList , mapping )
115+ }
116+ if importFlag1 {
117+ _ = d .Set ("worker_config" , instanceList )
118+ }
119+
120+ // The machines I generated was deleted by others.
121+ if len (WorkersNewWorkerInstancesList ) == 0 {
122+ d .SetId ("" )
123+ return nil
124+ }
125+
126+ _ = d .Set ("cluster_id" , GlobalClusterId )
127+ _ = d .Set ("labels" , WorkersLabelsMap )
128+ _ = d .Set ("worker_instances_list" , WorkersNewWorkerInstancesList )
129+
130+ return nil
131+ }
132+ func clusterInstanceParamHandle (ctx context.Context , req * tke.DescribeClusterInstancesRequest , resp * tke.DescribeClusterInstancesResponse ) error {
50133 d := tccommon .ResourceDataFromContext (ctx )
51134 var has = map [string ]bool {}
52135
@@ -198,90 +281,6 @@ func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1(ctx context.Conte
198281 return nil
199282}
200283
201- func resourceTencentCloudKubernetesScaleWorkerReadPostRequest2 (ctx context.Context , req * cvm.DescribeInstancesRequest , resp * cvm.DescribeInstancesResponse ) error {
202- d := tccommon .ResourceDataFromContext (ctx )
203-
204- instances := make ([]* cvm.Instance , 0 )
205- instances = append (instances , resp .Response .InstanceSet ... )
206-
207- instanceList := make ([]interface {}, 0 , len (instances ))
208- for _ , instance := range instances {
209- mapping := map [string ]interface {}{
210- "count" : 1 ,
211- "instance_charge_type_prepaid_period" : 1 ,
212- "instance_type" : helper .PString (instance .InstanceType ),
213- "subnet_id" : helper .PString (instance .VirtualPrivateCloud .SubnetId ),
214- "availability_zone" : helper .PString (instance .Placement .Zone ),
215- "instance_name" : helper .PString (instance .InstanceName ),
216- "instance_charge_type" : helper .PString (instance .InstanceChargeType ),
217- "system_disk_type" : helper .PString (instance .SystemDisk .DiskType ),
218- "system_disk_size" : helper .PInt64 (instance .SystemDisk .DiskSize ),
219- "internet_charge_type" : helper .PString (instance .InternetAccessible .InternetChargeType ),
220- "bandwidth_package_id" : helper .PString (instance .InternetAccessible .BandwidthPackageId ),
221- "internet_max_bandwidth_out" : helper .PInt64 (instance .InternetAccessible .InternetMaxBandwidthOut ),
222- "security_group_ids" : helper .StringsInterfaces (instance .SecurityGroupIds ),
223- "img_id" : helper .PString (instance .ImageId ),
224- }
225-
226- if instance .RenewFlag != nil && helper .PString (instance .InstanceChargeType ) == "PREPAID" {
227- mapping ["instance_charge_type_prepaid_renew_flag" ] = helper .PString (instance .RenewFlag )
228- } else {
229- mapping ["instance_charge_type_prepaid_renew_flag" ] = ""
230- }
231- if helper .PInt64 (instance .InternetAccessible .InternetMaxBandwidthOut ) > 0 {
232- mapping ["public_ip_assigned" ] = true
233- }
234-
235- if instance .CamRoleName != nil {
236- mapping ["cam_role_name" ] = instance .CamRoleName
237- }
238- if instance .LoginSettings != nil {
239- if instance .LoginSettings .KeyIds != nil && len (instance .LoginSettings .KeyIds ) > 0 {
240- mapping ["key_ids" ] = helper .StringsInterfaces (instance .LoginSettings .KeyIds )
241- }
242- if instance .LoginSettings .Password != nil {
243- mapping ["password" ] = helper .PString (instance .LoginSettings .Password )
244- }
245- }
246- if instance .DisasterRecoverGroupId != nil && helper .PString (instance .DisasterRecoverGroupId ) != "" {
247- mapping ["disaster_recover_group_ids" ] = []string {helper .PString (instance .DisasterRecoverGroupId )}
248- }
249- if instance .HpcClusterId != nil {
250- mapping ["hpc_cluster_id" ] = helper .PString (instance .HpcClusterId )
251- }
252-
253- dataDisks := make ([]interface {}, 0 , len (instance .DataDisks ))
254- for _ , v := range instance .DataDisks {
255- dataDisk := map [string ]interface {}{
256- "disk_type" : helper .PString (v .DiskType ),
257- "disk_size" : helper .PInt64 (v .DiskSize ),
258- "snapshot_id" : helper .PString (v .DiskId ),
259- "encrypt" : helper .PBool (v .Encrypt ),
260- "kms_key_id" : helper .PString (v .KmsKeyId ),
261- }
262- dataDisks = append (dataDisks , dataDisk )
263- }
264-
265- mapping ["data_disk" ] = dataDisks // worker_config.data_disk
266- instanceList = append (instanceList , mapping )
267- }
268- if importFlag1 {
269- _ = d .Set ("worker_config" , instanceList )
270- }
271-
272- // The machines I generated was deleted by others.
273- if len (WorkersNewWorkerInstancesList ) == 0 {
274- d .SetId ("" )
275- return nil
276- }
277-
278- _ = d .Set ("cluster_id" , GlobalClusterId )
279- _ = d .Set ("labels" , WorkersLabelsMap )
280- _ = d .Set ("worker_instances_list" , WorkersNewWorkerInstancesList )
281-
282- return nil
283- }
284-
285284func resourceTencentCloudKubernetesScaleWorkerDeletePostRequest0 (ctx context.Context , req * tke.DescribeClustersRequest , resp * tke.DescribeClustersResponse ) * resource.RetryError {
286285 if len (resp .Response .Clusters ) == 0 {
287286 return resource .NonRetryableError (fmt .Errorf ("The cluster has been deleted" ))
@@ -379,7 +378,7 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
379378
380379 dMap := make (map [string ]interface {}, 5 )
381380 //mount_target, docker_graph_path, data_disk, extra_args, desired_pod_num
382- iAdvancedParas := []string {"mount_target" , "docker_graph_path" , "extra_args" , "data_disk" , "desired_pod_num" , "gpu_args" }
381+ iAdvancedParas := []string {"mount_target" , "docker_graph_path" , "extra_args" , "data_disk" , "desired_pod_num" , "gpu_args" , "taints" }
383382 for _ , k := range iAdvancedParas {
384383 if v , ok := d .GetOk (k ); ok {
385384 dMap [k ] = v
@@ -396,6 +395,23 @@ func resourceTencentCloudKubernetesScaleWorkerCreateOnStart(ctx context.Context)
396395 iAdvanced .PreStartUserScript = helper .String (v .(string ))
397396 }
398397
398+ if v , ok := d .GetOk ("taints" ); ok {
399+ for _ , item := range v .([]interface {}) {
400+ taintsMap := item .(map [string ]interface {})
401+ taint := tke.Taint {}
402+ if v , ok := taintsMap ["key" ]; ok {
403+ taint .Key = helper .String (v .(string ))
404+ }
405+ if v , ok := taintsMap ["value" ]; ok {
406+ taint .Value = helper .String (v .(string ))
407+ }
408+ if v , ok := taintsMap ["effect" ]; ok {
409+ taint .Effect = helper .String (v .(string ))
410+ }
411+ iAdvanced .Taints = append (iAdvanced .Taints , & taint )
412+ }
413+ }
414+
399415 if v , ok := d .GetOk ("user_script" ); ok {
400416 iAdvanced .UserScript = helper .String (v .(string ))
401417 }
@@ -609,3 +625,61 @@ func resourceTencentCloudKubernetesScaleWorkerDeleteOnExit(ctx context.Context)
609625 }
610626 return nil
611627}
628+
629+ func resourceTencentCloudKubernetesScaleWorkerReadPostFillRequest1 (ctx context.Context , req * cvm.DescribeInstancesRequest ) error {
630+ d := tccommon .ResourceDataFromContext (ctx )
631+ meta := tccommon .ProviderMetaFromContext (ctx )
632+ logId := tccommon .GetLogId (ctx )
633+
634+ idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
635+ if len (idSplit ) != 2 {
636+ return fmt .Errorf ("id is broken,%s" , d .Id ())
637+ }
638+ clusterId := idSplit [0 ]
639+
640+ request := tke .NewDescribeClusterInstancesRequest ()
641+ request .ClusterId = helper .String (clusterId )
642+
643+ instanceSet := make ([]* tke.Instance , 0 )
644+
645+ var offset int64 = 0
646+ var pageSize int64 = 100
647+ for {
648+ request .Offset = & offset
649+ request .Limit = & pageSize
650+ ratelimit .Check (request .GetAction ())
651+
652+ response , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTkeClient ().DescribeClusterInstances (request )
653+ if err != nil {
654+ return err
655+ }
656+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), response .ToJsonString ())
657+
658+ if err := clusterInstanceParamHandle (ctx , request , response ); err != nil {
659+ return err
660+ }
661+
662+ if response == nil || len (response .Response .InstanceSet ) < 1 {
663+ break
664+ }
665+ count := len (response .Response .InstanceSet )
666+ instanceSet = append (instanceSet , response .Response .InstanceSet ... )
667+
668+ if count < int (pageSize ) {
669+ break
670+ }
671+ offset += pageSize
672+ }
673+ if instanceSet == nil {
674+ d .SetId ("" )
675+ log .Printf ("[WARN]%s resource `kubernetes_scale_worker` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
676+ return nil
677+ }
678+ return nil
679+ }
680+
681+ func resourceTencentCloudKubernetesScaleWorkerReadPreRequest1 (ctx context.Context , req * cvm.DescribeInstancesRequest ) error {
682+ req .InstanceIds = WorkersInstanceIds
683+
684+ return nil
685+ }
0 commit comments