@@ -62,12 +62,24 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
6262 ForceNew : true ,
6363 Description : "The available tags within this TCR instance." ,
6464 },
65+ "open_public_operation" : {
66+ Type : schema .TypeBool ,
67+ Optional : true ,
68+ ForceNew : true ,
69+ Default : false ,
70+ Description : "Control public network access." ,
71+ },
6572 //Computed values
6673 "status" : {
6774 Type : schema .TypeString ,
6875 Computed : true ,
6976 Description : "Status of the TCR instance." ,
7077 },
78+ "public_status" : {
79+ Type : schema .TypeString ,
80+ Computed : true ,
81+ Description : "Status of the TCR instance public network access." ,
82+ },
7183 "public_domain" : {
7284 Type : schema .TypeString ,
7385 Computed : true ,
@@ -97,11 +109,13 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
97109 tcrService := TCRService {client : meta .(* TencentCloudClient ).apiV3Conn }
98110
99111 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
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
105119 )
106120
107121 outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -123,6 +137,7 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
123137 if err != nil {
124138 return retryError (err )
125139 } else if has && * instance .Status == "Running" {
140+ instanceStatus = "Running"
126141 return nil
127142 } else if ! has {
128143 return resource .NonRetryableError (fmt .Errorf ("create tcr instance fail" ))
@@ -134,6 +149,25 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
134149 if err != nil {
135150 return err
136151 }
152+ if instanceStatus == "Running" {
153+ outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
154+ if v , ok := d .GetOk ("open_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+ }
164+ }
165+ return nil
166+ })
167+ if outErr != nil {
168+ return outErr
169+ }
170+ }
137171
138172 return resourceTencentCloudTcrInstanceRead (d , meta )
139173}
@@ -164,11 +198,35 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
164198 return nil
165199 }
166200
201+ publicStatus , has , outErr := tcrService .DescribeExternalEndpointStatus (ctx , d .Id ())
202+ if outErr != nil {
203+ outErr = resource .Retry (readRetryTimeout , func () * resource.RetryError {
204+ publicStatus , has , inErr = tcrService .DescribeExternalEndpointStatus (ctx , d .Id ())
205+ if inErr != nil {
206+ return retryError (inErr )
207+ }
208+ return nil
209+ })
210+ }
211+ if outErr != nil {
212+ return outErr
213+ }
214+ if ! has {
215+ d .SetId ("" )
216+ return nil
217+ }
218+ if publicStatus == "Opening" || publicStatus == "Opened" {
219+ _ = d .Set ("open_public_operation" , true )
220+ } else if publicStatus == "Closed" {
221+ _ = d .Set ("open_public_operation" , false )
222+ }
223+
167224 _ = d .Set ("name" , instance .RegistryName )
168225 _ = d .Set ("instance_type" , instance .RegistryType )
169226 _ = d .Set ("status" , instance .Status )
170227 _ = d .Set ("public_domain" , instance .PublicDomain )
171228 _ = d .Set ("internal_end_point" , instance .InternalEndpoint )
229+ _ = d .Set ("public_status" , publicStatus )
172230
173231 tags := make (map [string ]string , len (instance .TagSpecification .Tags ))
174232 for _ , tag := range instance .TagSpecification .Tags {
0 commit comments