@@ -62,12 +62,23 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
6262 ForceNew : true ,
6363 Description : "The available tags within this TCR instance." ,
6464 },
65+ "public_operation" : {
66+ Type : schema .TypeString ,
67+ Optional : true ,
68+ ForceNew : true ,
69+ Description : "Control public network access. Valid values are:`Create`, `Delete`." ,
70+ },
6571 //Computed values
6672 "status" : {
6773 Type : schema .TypeString ,
6874 Computed : true ,
6975 Description : "Status of the TCR instance." ,
7076 },
77+ "public_status" : {
78+ Type : schema .TypeString ,
79+ Computed : true ,
80+ Description : "Status of the TCR instance public network access." ,
81+ },
7182 "public_domain" : {
7283 Type : schema .TypeString ,
7384 Computed : true ,
@@ -97,11 +108,11 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
97108 tcrService := TCRService {client : meta .(* TencentCloudClient ).apiV3Conn }
98109
99110 var (
100- name = d .Get ("name" ).(string )
101- insType = d .Get ("instance_type" ).(string )
102- tags = helper .GetTags (d , "tags" )
103- outErr , inErr error
104- instanceId string
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
105116 )
106117
107118 outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -135,6 +146,34 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
135146 return err
136147 }
137148
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 )
169+ }
170+ }
171+ return nil
172+ })
173+ if outErr != nil {
174+ return outErr
175+ }
176+
138177 return resourceTencentCloudTcrInstanceRead (d , meta )
139178}
140179
@@ -164,11 +203,35 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
164203 return nil
165204 }
166205
206+ publicStatus , has , outErr := tcrService .DescribeExternalEndpointStatus (ctx , d .Id ())
207+ if outErr != nil {
208+ outErr = resource .Retry (readRetryTimeout , func () * resource.RetryError {
209+ publicStatus , has , inErr = tcrService .DescribeExternalEndpointStatus (ctx , d .Id ())
210+ if inErr != nil {
211+ return retryError (inErr )
212+ }
213+ return nil
214+ })
215+ }
216+ if outErr != nil {
217+ return outErr
218+ }
219+ if ! has {
220+ d .SetId ("" )
221+ return nil
222+ }
223+ if publicStatus == "Opening" || publicStatus == "Opened" {
224+ _ = d .Set ("public_operation" , "Create" )
225+ } else if publicStatus == "Closed" {
226+ _ = d .Set ("public_operation" , "Delete" )
227+ }
228+
167229 _ = d .Set ("name" , instance .RegistryName )
168230 _ = d .Set ("instance_type" , instance .RegistryType )
169231 _ = d .Set ("status" , instance .Status )
170232 _ = d .Set ("public_domain" , instance .PublicDomain )
171233 _ = d .Set ("internal_end_point" , instance .InternalEndpoint )
234+ _ = d .Set ("public_status" , publicStatus )
172235
173236 tags := make (map [string ]string , len (instance .TagSpecification .Tags ))
174237 for _ , tag := range instance .TagSpecification .Tags {
0 commit comments