@@ -63,10 +63,11 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
6363 Description : "The available tags within this TCR instance." ,
6464 },
6565 "public_operation" : {
66- Type : schema .TypeString ,
66+ Type : schema .TypeBool ,
6767 Optional : true ,
6868 ForceNew : true ,
69- Description : "Control public network access. Valid values are:`Create`, `Delete`." ,
69+ Default : false ,
70+ Description : "Control public network access." ,
7071 },
7172 //Computed values
7273 "status" : {
@@ -108,11 +109,13 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
108109 tcrService := TCRService {client : meta .(* TencentCloudClient ).apiV3Conn }
109110
110111 var (
111- name = d .Get ("name" ).(string )
112- insType = d .Get ("instance_type" ).(string )
113- tags = helper .GetTags (d , "tags" )
114- outErr , inErr error
115- instanceId , operation string
112+ name = d .Get ("name" ).(string )
113+ insType = d .Get ("instance_type" ).(string )
114+ tags = helper .GetTags (d , "tags" )
115+ outErr , inErr error
116+ instanceId string
117+ instanceStatus string
118+ operation bool
116119 )
117120
118121 outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -134,6 +137,7 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
134137 if err != nil {
135138 return retryError (err )
136139 } else if has && * instance .Status == "Running" {
140+ instanceStatus = "Running"
137141 return nil
138142 } else if ! has {
139143 return resource .NonRetryableError (fmt .Errorf ("create tcr instance fail" ))
@@ -145,33 +149,24 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
145149 if err != nil {
146150 return err
147151 }
148-
149- outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
150- if v , ok := d .GetOk ("public_operation" ); ok {
151- operation = v .(string )
152- inErr = tcrService .ManageTCRExternalEndpoint (ctx , instanceId , operation )
153- if inErr != nil {
154- return retryError (inErr )
155- }
156- }
157- return nil
158- })
159- if outErr != nil {
160- return outErr
161- }
162-
163- outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
164- if v , ok := d .GetOk ("public_operation" ); ok {
165- operation = v .(string )
166- inErr = tcrService .ManageTCRExternalEndpoint (ctx , instanceId , operation )
167- if inErr != nil {
168- return retryError (inErr )
152+ if instanceStatus == "Running" {
153+ outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
154+ if v , ok := d .GetOk ("public_operation" ); ok {
155+ operation = v .(bool )
156+ if operation {
157+ inErr = tcrService .ManageTCRExternalEndpoint (ctx , instanceId , "Create" )
158+ } else {
159+ inErr = tcrService .ManageTCRExternalEndpoint (ctx , instanceId , "Delete" )
160+ }
161+ if inErr != nil {
162+ return retryError (inErr )
163+ }
169164 }
165+ return nil
166+ })
167+ if outErr != nil {
168+ return outErr
170169 }
171- return nil
172- })
173- if outErr != nil {
174- return outErr
175170 }
176171
177172 return resourceTencentCloudTcrInstanceRead (d , meta )
@@ -221,9 +216,9 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
221216 return nil
222217 }
223218 if publicStatus == "Opening" || publicStatus == "Opened" {
224- _ = d .Set ("public_operation" , "Create" )
219+ _ = d .Set ("public_operation" , true )
225220 } else if publicStatus == "Closed" {
226- _ = d .Set ("public_operation" , "Delete" )
221+ _ = d .Set ("public_operation" , false )
227222 }
228223
229224 _ = d .Set ("name" , instance .RegistryName )
0 commit comments