@@ -18,8 +18,8 @@ import (
1818
1919func ResourceTencentCloudMonitorTmpInstance () * schema.Resource {
2020 return & schema.Resource {
21- Read : resourceTencentCloudMonitorTmpInstanceRead ,
2221 Create : resourceTencentCloudMonitorTmpInstanceCreate ,
22+ Read : resourceTencentCloudMonitorTmpInstanceRead ,
2323 Update : resourceTencentCloudMonitorTmpInstanceUpdate ,
2424 Delete : resourceTencentCloudMonitorTmpInstanceDelete ,
2525 Importer : & schema.ResourceImporter {
@@ -47,7 +47,7 @@ func ResourceTencentCloudMonitorTmpInstance() *schema.Resource {
4747 "data_retention_time" : {
4848 Type : schema .TypeInt ,
4949 Required : true ,
50- Description : "Data retention time." ,
50+ Description : "Data retention time(in days). Value range: 15, 30, 45, 90, 180, 360, 720 ." ,
5151 },
5252
5353 "zone" : {
@@ -93,9 +93,8 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
9393 defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.create" )()
9494 defer tccommon .InconsistentCheck (d , meta )()
9595
96- logId := tccommon .GetLogId (tccommon .ContextNil )
97-
9896 var (
97+ logId = tccommon .GetLogId (tccommon .ContextNil )
9998 request = monitor .NewCreatePrometheusMultiTenantInstancePostPayModeRequest ()
10099 response * monitor.CreatePrometheusMultiTenantInstancePostPayModeResponse
101100 )
@@ -112,7 +111,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
112111 request .SubnetId = helper .String (v .(string ))
113112 }
114113
115- if v , ok := d .GetOk ("data_retention_time" ); ok {
114+ if v , ok := d .GetOkExists ("data_retention_time" ); ok {
116115 request .DataRetentionTime = helper .IntInt64 (v .(int ))
117116 }
118117
@@ -128,6 +127,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
128127 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
129128 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
130129 }
130+
131131 response = result
132132 return nil
133133 })
@@ -138,7 +138,6 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
138138 }
139139
140140 tmpInstanceId := * response .Response .InstanceId
141-
142141 service := svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
143142 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
144143
@@ -147,14 +146,18 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
147146 if errRet != nil {
148147 return tccommon .RetryError (errRet , tccommon .InternalError )
149148 }
149+
150150 if * instance .InstanceStatus == 2 {
151151 return nil
152152 }
153+
153154 if * instance .InstanceStatus == 3 {
154155 return resource .NonRetryableError (fmt .Errorf ("tmpInstance status is %v, operate failed." , * instance .InstanceStatus ))
155156 }
157+
156158 return resource .RetryableError (fmt .Errorf ("tmpInstance status is %v, retry..." , * instance .InstanceStatus ))
157159 })
160+
158161 if err != nil {
159162 return err
160163 }
@@ -167,6 +170,7 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
167170 return err
168171 }
169172 }
173+
170174 d .SetId (tmpInstanceId )
171175 return resourceTencentCloudMonitorTmpInstanceRead (d , meta )
172176}
@@ -175,15 +179,14 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
175179 defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmpInstance.read" )()
176180 defer tccommon .InconsistentCheck (d , meta )()
177181
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+ )
182187
183188 tmpInstanceId := d .Id ()
184-
185189 tmpInstance , err := service .DescribeMonitorTmpInstance (ctx , tmpInstanceId )
186-
187190 if err != nil {
188191 return err
189192 }
@@ -236,25 +239,20 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
236239 if err != nil {
237240 return err
238241 }
239- _ = d .Set ("tags" , tags )
240242
243+ _ = d .Set ("tags" , tags )
241244 return nil
242245}
243246
244247func resourceTencentCloudMonitorTmpInstanceUpdate (d * schema.ResourceData , meta interface {}) error {
245248 defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.update" )()
246249 defer tccommon .InconsistentCheck (d , meta )()
247250
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+ )
258256
259257 if d .HasChange ("vpc_id" ) {
260258 return fmt .Errorf ("`vpc_id` do not support change now." )
@@ -264,16 +262,21 @@ func resourceTencentCloudMonitorTmpInstanceUpdate(d *schema.ResourceData, meta i
264262 return fmt .Errorf ("`subnet_id` do not support change now." )
265263 }
266264
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+
267274 if d .HasChange ("data_retention_time" ) {
268275 if v , ok := d .GetOk ("data_retention_time" ); ok {
269276 request .DataRetentionTime = helper .IntInt64 (v .(int ))
270277 }
271278 }
272279
273- if d .HasChange ("zone" ) {
274- return fmt .Errorf ("`zone` do not support change now." )
275- }
276-
277280 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
278281 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMonitorClient ().ModifyPrometheusInstanceAttributes (request )
279282 if e != nil {
@@ -282,6 +285,7 @@ func resourceTencentCloudMonitorTmpInstanceUpdate(d *schema.ResourceData, meta i
282285 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
283286 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
284287 }
288+
285289 return nil
286290 })
287291
@@ -307,11 +311,12 @@ func resourceTencentCloudMonitorTmpInstanceDelete(d *schema.ResourceData, meta i
307311 defer tccommon .LogElapsed ("resource.tencentcloud_monitor_tmp_instance.delete" )()
308312 defer tccommon .InconsistentCheck (d , meta )()
309313
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+ )
315320
316321 if err := service .IsolateMonitorTmpInstanceById (ctx , tmpInstanceId ); err != nil {
317322 return err
@@ -322,20 +327,25 @@ func resourceTencentCloudMonitorTmpInstanceDelete(d *schema.ResourceData, meta i
322327 if errRet != nil {
323328 return tccommon .RetryError (errRet , tccommon .InternalError )
324329 }
330+
325331 if * instance .InstanceStatus == 6 {
326332 return nil
327333 }
334+
328335 if * instance .InstanceStatus == 3 {
329336 return resource .NonRetryableError (fmt .Errorf ("tmpInstance status is %v, operate failed." , * instance .InstanceStatus ))
330337 }
338+
331339 return resource .RetryableError (fmt .Errorf ("tmpInstance status is %v, retry..." , * instance .InstanceStatus ))
332340 })
341+
333342 if err != nil {
334343 return err
335344 }
336345
337346 if err := service .DeleteMonitorTmpInstanceById (ctx , tmpInstanceId ); err != nil {
338347 return err
339348 }
349+
340350 return nil
341351}
0 commit comments