@@ -48,6 +48,89 @@ func customScaleWorkerResourceImporter(ctx context.Context, d *schema.ResourceDa
48
48
49
49
func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1 (ctx context.Context , req * cvm.DescribeInstancesRequest , resp * cvm.DescribeInstancesResponse ) error {
50
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 resourceTencentCloudKubernetesScaleWorkerReadPostRequest2 (ctx context.Context , req * cvm.DescribeInstancesRequest , resp * cvm.DescribeInstancesResponse ) error {
133
+ d := tccommon .ResourceDataFromContext (ctx )
51
134
var has = map [string ]bool {}
52
135
53
136
workerInstancesList := d .Get ("worker_instances_list" ).([]interface {})
@@ -198,90 +281,6 @@ func resourceTencentCloudKubernetesScaleWorkerReadPostRequest1(ctx context.Conte
198
281
return nil
199
282
}
200
283
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
-
285
284
func resourceTencentCloudKubernetesScaleWorkerDeletePostRequest0 (ctx context.Context , req * tke.DescribeClustersRequest , resp * tke.DescribeClustersResponse ) * resource.RetryError {
286
285
if len (resp .Response .Clusters ) == 0 {
287
286
return resource .NonRetryableError (fmt .Errorf ("The cluster has been deleted" ))
0 commit comments