Skip to content

fix(monitor): [121814649] tencentcloud_monitor_tmp_instance set creation wait #3109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3109.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_monitor_tmp_instance: set creation wait
```
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

if result == nil || result.Response == nil || result.Response.Names == nil {
return resource.NonRetryableError(fmt.Errorf("Create monitor tmpExporterIntegration failed, Response is nil."))
}

response = result
return nil
})
Expand All @@ -154,6 +159,10 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
return err
}

if len(response.Response.Names) < 1 {
return fmt.Errorf("Names is nil.")
}

tmpExporterIntegrationId := *response.Response.Names[0]

d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP))
Expand All @@ -162,7 +171,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
}

func resourceTencentCloudMonitorTmpExporterIntegrationRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmpExporterIntegration.read")()
defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmp_exporter_integration.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
Expand Down
33 changes: 33 additions & 0 deletions tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

if result == nil || result.Response == nil {
return resource.NonRetryableError(fmt.Errorf("Create monitor tmpInstance failed, Response is nil."))
}

response = result
return nil
})
Expand All @@ -137,6 +141,10 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
return err
}

if response.Response.InstanceId == nil {
return fmt.Errorf("InstanceId is nil.")
}

tmpInstanceId := *response.Response.InstanceId
service := svcmonitor.NewMonitorService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
Expand All @@ -162,6 +170,31 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
return err
}

// wait
initStatus := monitor.NewDescribePrometheusInstanceInitStatusRequest()
initStatus.InstanceId = &tmpInstanceId
err = resource.Retry(8*tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, errRet := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().DescribePrometheusInstanceInitStatus(initStatus)
if errRet != nil {
return tccommon.RetryError(errRet, tccommon.InternalError)
}

if result == nil || result.Response == nil || result.Response.Status == nil {
return resource.NonRetryableError(fmt.Errorf("prometheusInstanceInit status is nil, operate failed"))
}

status := result.Response.Status
if *status == "running" {
return nil
}

return resource.RetryableError(fmt.Errorf("prometheusInstanceInit status is %s", *status))
})

if err != nil {
return err
}

if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
tagService := svctag.NewTagService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
region := meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region
Expand Down
Loading