@@ -128,6 +128,10 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
128128 logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
129129 }
130130
131+ if result == nil || result .Response == nil {
132+ return resource .NonRetryableError (fmt .Errorf ("Create monitor tmpInstance failed, Response is nil." ))
133+ }
134+
131135 response = result
132136 return nil
133137 })
@@ -137,6 +141,10 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
137141 return err
138142 }
139143
144+ if response .Response .InstanceId == nil {
145+ return fmt .Errorf ("InstanceId is nil." )
146+ }
147+
140148 tmpInstanceId := * response .Response .InstanceId
141149 service := svcmonitor .NewMonitorService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
142150 ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
@@ -162,6 +170,31 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
162170 return err
163171 }
164172
173+ // wait
174+ initStatus := monitor .NewDescribePrometheusInstanceInitStatusRequest ()
175+ initStatus .InstanceId = & tmpInstanceId
176+ err = resource .Retry (8 * tccommon .ReadRetryTimeout , func () * resource.RetryError {
177+ result , errRet := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMonitorClient ().DescribePrometheusInstanceInitStatus (initStatus )
178+ if errRet != nil {
179+ return tccommon .RetryError (errRet , tccommon .InternalError )
180+ }
181+
182+ if result == nil || result .Response == nil || result .Response .Status == nil {
183+ return resource .NonRetryableError (fmt .Errorf ("prometheusInstanceInit status is nil, operate failed" ))
184+ }
185+
186+ status := result .Response .Status
187+ if * status == "running" {
188+ return nil
189+ }
190+
191+ return resource .RetryableError (fmt .Errorf ("prometheusInstanceInit status is %s" , * status ))
192+ })
193+
194+ if err != nil {
195+ return err
196+ }
197+
165198 if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
166199 tagService := svctag .NewTagService (meta .(tccommon.ProviderMeta ).GetAPIV3Conn ())
167200 region := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().Region
0 commit comments