@@ -18,8 +18,8 @@ import (
18
18
19
19
func ResourceTencentCloudMonitorTmpInstance () * schema.Resource {
20
20
return & schema.Resource {
21
- Read : resourceTencentCloudMonitorTmpInstanceRead ,
22
21
Create : resourceTencentCloudMonitorTmpInstanceCreate ,
22
+ Read : resourceTencentCloudMonitorTmpInstanceRead ,
23
23
Update : resourceTencentCloudMonitorTmpInstanceUpdate ,
24
24
Delete : resourceTencentCloudMonitorTmpInstanceDelete ,
25
25
Importer : & schema.ResourceImporter {
@@ -47,7 +47,7 @@ func ResourceTencentCloudMonitorTmpInstance() *schema.Resource {
47
47
"data_retention_time" : {
48
48
Type : schema .TypeInt ,
49
49
Required : true ,
50
- Description : "Data retention time." ,
50
+ Description : "Data retention time(in days). Value range: 15, 30, 45, 90, 180, 360, 720 ." ,
51
51
},
52
52
53
53
"zone" : {
@@ -93,9 +93,8 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
93
93
defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.create" )()
94
94
defer tccommon .InconsistentCheck (d , meta )()
95
95
96
- logId := tccommon .GetLogId (tccommon .ContextNil )
97
-
98
96
var (
97
+ logId = tccommon .GetLogId (tccommon .ContextNil )
99
98
request = monitor .NewCreatePrometheusMultiTenantInstancePostPayModeRequest ()
100
99
response * monitor.CreatePrometheusMultiTenantInstancePostPayModeResponse
101
100
)
@@ -112,7 +111,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
112
111
request .SubnetId = helper .String (v .(string ))
113
112
}
114
113
115
- if v , ok := d .GetOk ("data_retention_time" ); ok {
114
+ if v , ok := d .GetOkExists ("data_retention_time" ); ok {
116
115
request .DataRetentionTime = helper .IntInt64 (v .(int ))
117
116
}
118
117
@@ -128,6 +127,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
128
127
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
129
128
logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
130
129
}
130
+
131
131
response = result
132
132
return nil
133
133
})
@@ -138,7 +138,6 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
138
138
}
139
139
140
140
tmpInstanceId := * response .Response .InstanceId
141
-
142
141
service := svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
143
142
ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
144
143
@@ -147,14 +146,18 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
147
146
if errRet != nil {
148
147
return tccommon .RetryError (errRet , tccommon .InternalError )
149
148
}
149
+
150
150
if * instance .InstanceStatus == 2 {
151
151
return nil
152
152
}
153
+
153
154
if * instance .InstanceStatus == 3 {
154
155
return resource .NonRetryableError (fmt .Errorf ("tmpInstance status is %v, operate failed." , * instance .InstanceStatus ))
155
156
}
157
+
156
158
return resource .RetryableError (fmt .Errorf ("tmpInstance status is %v, retry..." , * instance .InstanceStatus ))
157
159
})
160
+
158
161
if err != nil {
159
162
return err
160
163
}
@@ -167,6 +170,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
167
170
return err
168
171
}
169
172
}
173
+
170
174
d .SetId (tmpInstanceId )
171
175
return resourceTencentCloudMonitorTmpInstanceRead (d , meta )
172
176
}
@@ -175,15 +179,14 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
175
179
defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmpInstance.read" )()
176
180
defer tccommon .InconsistentCheck (d , meta )()
177
181
178
- logId := tccommon .GetLogId (tccommon .ContextNil )
179
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
180
-
181
- service := svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
182
+ var (
183
+ logId = tccommon .GetLogId (tccommon .ContextNil )
184
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
185
+ service = svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
186
+ )
182
187
183
188
tmpInstanceId := d .Id ()
184
-
185
189
tmpInstance , err := service .DescribeMonitorTmpInstance (ctx , tmpInstanceId )
186
-
187
190
if err != nil {
188
191
return err
189
192
}
@@ -236,25 +239,20 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
236
239
if err != nil {
237
240
return err
238
241
}
239
- _ = d .Set ("tags" , tags )
240
242
243
+ _ = d .Set ("tags" , tags )
241
244
return nil
242
245
}
243
246
244
247
func resourceTencentCloudMonitorTmpInstanceUpdate (d * schema.ResourceData , meta interface {}) error {
245
248
defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.update" )()
246
249
defer tccommon .InconsistentCheck (d , meta )()
247
250
248
- logId := tccommon .GetLogId (tccommon .ContextNil )
249
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
250
-
251
- request := monitor .NewModifyPrometheusInstanceAttributesRequest ()
252
-
253
- request .InstanceId = helper .String (d .Id ())
254
-
255
- if v , ok := d .GetOk ("instance_name" ); ok {
256
- request .InstanceName = helper .String (v .(string ))
257
- }
251
+ var (
252
+ logId = tccommon .GetLogId (tccommon .ContextNil )
253
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
254
+ request = monitor .NewModifyPrometheusInstanceAttributesRequest ()
255
+ )
258
256
259
257
if d .HasChange ("vpc_id" ) {
260
258
return fmt .Errorf ("`vpc_id` do not support change now." )
@@ -264,16 +262,21 @@ func resourceTencentCloudMonitorTmpInstanceUpdate(d *schema.ResourceData, meta i
264
262
return fmt .Errorf ("`subnet_id` do not support change now." )
265
263
}
266
264
265
+ if d .HasChange ("zone" ) {
266
+ return fmt .Errorf ("`zone` do not support change now." )
267
+ }
268
+
269
+ request .InstanceId = helper .String (d .Id ())
270
+ if v , ok := d .GetOk ("instance_name" ); ok {
271
+ request .InstanceName = helper .String (v .(string ))
272
+ }
273
+
267
274
if d .HasChange ("data_retention_time" ) {
268
275
if v , ok := d .GetOk ("data_retention_time" ); ok {
269
276
request .DataRetentionTime = helper .IntInt64 (v .(int ))
270
277
}
271
278
}
272
279
273
- if d .HasChange ("zone" ) {
274
- return fmt .Errorf ("`zone` do not support change now." )
275
- }
276
-
277
280
err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
278
281
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMonitorClient ().ModifyPrometheusInstanceAttributes (request )
279
282
if e != nil {
@@ -282,6 +285,7 @@ func resourceTencentCloudMonitorTmpInstanceUpdate(d *schema.ResourceData, meta i
282
285
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
283
286
logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
284
287
}
288
+
285
289
return nil
286
290
})
287
291
@@ -307,11 +311,12 @@ func resourceTencentCloudMonitorTmpInstanceDelete(d *schema.ResourceData, meta i
307
311
defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.delete" )()
308
312
defer tccommon .InconsistentCheck (d , meta )()
309
313
310
- logId := tccommon .GetLogId (tccommon .ContextNil )
311
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
312
-
313
- service := svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
314
- tmpInstanceId := d .Id ()
314
+ var (
315
+ logId = tccommon .GetLogId (tccommon .ContextNil )
316
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
317
+ service = svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
318
+ tmpInstanceId = d .Id ()
319
+ )
315
320
316
321
if err := service .IsolateMonitorTmpInstanceById (ctx , tmpInstanceId ); err != nil {
317
322
return err
@@ -322,20 +327,25 @@ func resourceTencentCloudMonitorTmpInstanceDelete(d *schema.ResourceData, meta i
322
327
if errRet != nil {
323
328
return tccommon .RetryError (errRet , tccommon .InternalError )
324
329
}
330
+
325
331
if * instance .InstanceStatus == 6 {
326
332
return nil
327
333
}
334
+
328
335
if * instance .InstanceStatus == 3 {
329
336
return resource .NonRetryableError (fmt .Errorf ("tmpInstance status is %v, operate failed." , * instance .InstanceStatus ))
330
337
}
338
+
331
339
return resource .RetryableError (fmt .Errorf ("tmpInstance status is %v, retry..." , * instance .InstanceStatus ))
332
340
})
341
+
333
342
if err != nil {
334
343
return err
335
344
}
336
345
337
346
if err := service .DeleteMonitorTmpInstanceById (ctx , tmpInstanceId ); err != nil {
338
347
return err
339
348
}
349
+
340
350
return nil
341
351
}
0 commit comments