@@ -313,9 +313,8 @@ func resourceTencentCLoudTcrVpcAttachmentDelete(d *schema.ResourceData, meta int
313313 return nil
314314}
315315
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 {
319318 result , has , inErr := tcrService .DescribeTCRVPCAttachmentById (ctx , instanceId , vpcId , subnetId )
320319 if inErr != nil {
321320 return retryError (inErr )
@@ -329,15 +328,20 @@ func EnableTcrVpcDns(ctx context.Context, tcrService TCRService, instanceId stri
329328 inErr = fmt .Errorf ("%s get tcr accessIp fail, accessIp is not exists from SDK DescribeTcrVpcAttachmentById" , vpcId )
330329 return resource .RetryableError (inErr )
331330 }
332- vpcAccess = result
331+ accessIp = * result . AccessIp
333332 return nil
334333 })
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
337341 }
338342
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 )
341345 if inErr != nil {
342346 return retryError (inErr )
343347 }
@@ -348,30 +352,13 @@ func EnableTcrVpcDns(ctx context.Context, tcrService TCRService, instanceId stri
348352}
349353
350354func 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
371358 }
372359
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 )
375362 if inErr != nil {
376363 return retryError (inErr )
377364 }
0 commit comments