@@ -313,9 +313,8 @@ func resourceTencentCLoudTcrVpcAttachmentDelete(d *schema.ResourceData, meta int
313
313
return nil
314
314
}
315
315
316
- func EnableTcrVpcDns (ctx context.Context , tcrService TCRService , instanceId string , vpcId string , subnetId string , usePublicDomain bool ) error {
317
- var vpcAccess * tcr.AccessVpc
318
- outErr := resource .Retry (readRetryTimeout , func () * resource.RetryError {
316
+ func WaitForAccessIpExists (ctx context.Context , tcrService TCRService , instanceId string , vpcId string , subnetId string ) (accessIp string , errRet error ) {
317
+ errRet = resource .Retry (readRetryTimeout , func () * resource.RetryError {
319
318
result , has , inErr := tcrService .DescribeTCRVPCAttachmentById (ctx , instanceId , vpcId , subnetId )
320
319
if inErr != nil {
321
320
return retryError (inErr )
@@ -329,15 +328,20 @@ func EnableTcrVpcDns(ctx context.Context, tcrService TCRService, instanceId stri
329
328
inErr = fmt .Errorf ("%s get tcr accessIp fail, accessIp is not exists from SDK DescribeTcrVpcAttachmentById" , vpcId )
330
329
return resource .RetryableError (inErr )
331
330
}
332
- vpcAccess = result
331
+ accessIp = * result . AccessIp
333
332
return nil
334
333
})
335
- if outErr != nil {
336
- return outErr
334
+ return
335
+ }
336
+
337
+ func EnableTcrVpcDns (ctx context.Context , tcrService TCRService , instanceId string , vpcId string , subnetId string , usePublicDomain bool ) error {
338
+ accessIp , err := WaitForAccessIpExists (ctx , tcrService , instanceId , vpcId , subnetId )
339
+ if err != nil {
340
+ return err
337
341
}
338
342
339
- outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
340
- inErr := tcrService .CreateTcrVpcDns (ctx , instanceId , vpcId , * vpcAccess . AccessIp , usePublicDomain )
343
+ outErr : = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
344
+ inErr := tcrService .CreateTcrVpcDns (ctx , instanceId , vpcId , accessIp , usePublicDomain )
341
345
if inErr != nil {
342
346
return retryError (inErr )
343
347
}
@@ -348,30 +352,13 @@ func EnableTcrVpcDns(ctx context.Context, tcrService TCRService, instanceId stri
348
352
}
349
353
350
354
func DisableTcrVpcDns (ctx context.Context , tcrService TCRService , instanceId string , vpcId string , subnetId string , usePublicDomain bool ) error {
351
- var vpcAccess * tcr.AccessVpc
352
- outErr := resource .Retry (readRetryTimeout , func () * resource.RetryError {
353
- result , has , inErr := tcrService .DescribeTCRVPCAttachmentById (ctx , instanceId , vpcId , subnetId )
354
- if inErr != nil {
355
- return retryError (inErr )
356
- }
357
- if ! has {
358
- inErr = fmt .Errorf ("%s create tcr vpcAccess %s fail, vpcAccess is not exists from SDK DescribeTcrVpcAttachmentById" , instanceId , vpcId )
359
- return resource .RetryableError (inErr )
360
- }
361
-
362
- if * result .AccessIp == "" {
363
- inErr = fmt .Errorf ("%s get tcr accessIp fail, accessIp is not exists from SDK DescribeTcrVpcAttachmentById" , vpcId )
364
- return resource .RetryableError (inErr )
365
- }
366
- vpcAccess = result
367
- return nil
368
- })
369
- if outErr != nil {
370
- return outErr
355
+ accessIp , err := WaitForAccessIpExists (ctx , tcrService , instanceId , vpcId , subnetId )
356
+ if err != nil {
357
+ return err
371
358
}
372
359
373
- outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
374
- inErr := tcrService .DeleteTcrVpcDns (ctx , instanceId , vpcId , * vpcAccess . AccessIp , usePublicDomain )
360
+ outErr : = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
361
+ inErr := tcrService .DeleteTcrVpcDns (ctx , instanceId , vpcId , accessIp , usePublicDomain )
375
362
if inErr != nil {
376
363
return retryError (inErr )
377
364
}
0 commit comments