@@ -62,12 +62,24 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
62
62
ForceNew : true ,
63
63
Description : "The available tags within this TCR instance." ,
64
64
},
65
+ "open_public_operation" : {
66
+ Type : schema .TypeBool ,
67
+ Optional : true ,
68
+ ForceNew : true ,
69
+ Default : false ,
70
+ Description : "Control public network access." ,
71
+ },
65
72
//Computed values
66
73
"status" : {
67
74
Type : schema .TypeString ,
68
75
Computed : true ,
69
76
Description : "Status of the TCR instance." ,
70
77
},
78
+ "public_status" : {
79
+ Type : schema .TypeString ,
80
+ Computed : true ,
81
+ Description : "Status of the TCR instance public network access." ,
82
+ },
71
83
"public_domain" : {
72
84
Type : schema .TypeString ,
73
85
Computed : true ,
@@ -97,11 +109,13 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
97
109
tcrService := TCRService {client : meta .(* TencentCloudClient ).apiV3Conn }
98
110
99
111
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
105
119
)
106
120
107
121
outErr = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -123,6 +137,7 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
123
137
if err != nil {
124
138
return retryError (err )
125
139
} else if has && * instance .Status == "Running" {
140
+ instanceStatus = "Running"
126
141
return nil
127
142
} else if ! has {
128
143
return resource .NonRetryableError (fmt .Errorf ("create tcr instance fail" ))
@@ -134,6 +149,25 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
134
149
if err != nil {
135
150
return err
136
151
}
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
+ }
137
171
138
172
return resourceTencentCloudTcrInstanceRead (d , meta )
139
173
}
@@ -164,11 +198,35 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
164
198
return nil
165
199
}
166
200
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
+
167
224
_ = d .Set ("name" , instance .RegistryName )
168
225
_ = d .Set ("instance_type" , instance .RegistryType )
169
226
_ = d .Set ("status" , instance .Status )
170
227
_ = d .Set ("public_domain" , instance .PublicDomain )
171
228
_ = d .Set ("internal_end_point" , instance .InternalEndpoint )
229
+ _ = d .Set ("public_status" , publicStatus )
172
230
173
231
tags := make (map [string ]string , len (instance .TagSpecification .Tags ))
174
232
for _ , tag := range instance .TagSpecification .Tags {
0 commit comments