@@ -164,11 +164,29 @@ func resourceTencentCloudIdentityCenterRoleAssignmentCreate(d *schema.ResourceDa
164164
165165 if len (response .Response .Tasks ) > 0 {
166166 task := response .Response .Tasks [0 ]
167+ if task == nil {
168+ return fmt .Errorf ("task is nil" )
169+ }
170+ if task .Status != nil && * task .Status == TASK_STATUS_FAILED {
171+ if task .FailureReason != nil {
172+ return fmt .Errorf ("create role assignment task failed, failure reason:%s" , * task .FailureReason )
173+ }
174+ return fmt .Errorf ("create role assignment task failed" )
175+ }
176+
177+ if task .TaskId == nil {
178+ return fmt .Errorf ("create role assignment task id is nil" )
179+ }
167180 taskId := * task .TaskId
168181 roleConfigurationId := * task .RoleConfigurationId
169- conf := tccommon .BuildStateChangeConf ([]string {}, []string {"Success" }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , taskId , []string {}))
170- if _ , e := conf .WaitForState (); e != nil {
182+ conf := tccommon .BuildStateChangeConf ([]string {}, []string {TASK_STATUS_SUCCESS , TASK_STATUS_FAILED }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , taskId , []string {}))
183+ if object , e := conf .WaitForState (); e != nil {
171184 return e
185+ } else {
186+ taskStatus := object .(* organization.TaskStatus )
187+ if taskStatus .Status != nil && * taskStatus .Status == TASK_STATUS_FAILED {
188+ return fmt .Errorf ("create role assignment task failed" )
189+ }
172190 }
173191
174192 targetUinString := strconv .FormatInt (targetUin , 10 )
@@ -188,18 +206,26 @@ func resourceTencentCloudIdentityCenterRoleAssignmentRead(d *schema.ResourceData
188206
189207 service := OrganizationService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
190208
191- respData , err := service .DescribeIdentityCenterRoleAssignmentById (ctx , d .Id ())
209+ var roleAssignmentsResponseParams * organization.ListRoleAssignmentsResponseParams
210+ err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
211+ result , e := service .DescribeIdentityCenterRoleAssignmentById (ctx , d .Id ())
212+ if e != nil {
213+ return tccommon .RetryError (e )
214+ }
215+ roleAssignmentsResponseParams = result
216+ return nil
217+ })
192218 if err != nil {
193219 return err
194220 }
195221
196- if respData == nil {
222+ if roleAssignmentsResponseParams == nil {
197223 d .SetId ("" )
198224 log .Printf ("[WARN]%s resource `identity_center_role_assignment` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
199225 return nil
200226 }
201- if len (respData .RoleAssignments ) > 0 {
202- roleAssignment := respData .RoleAssignments [0 ]
227+ if len (roleAssignmentsResponseParams .RoleAssignments ) > 0 {
228+ roleAssignment := roleAssignmentsResponseParams .RoleAssignments [0 ]
203229 if roleAssignment .RoleConfigurationId != nil {
204230 _ = d .Set ("role_configuration_id" , roleAssignment .RoleConfigurationId )
205231 }
@@ -292,10 +318,29 @@ func resourceTencentCloudIdentityCenterRoleAssignmentDelete(d *schema.ResourceDa
292318 return err
293319 }
294320
295- if deleteRoleAssignmentResponse .Response != nil && deleteRoleAssignmentResponse .Response .Task != nil && deleteRoleAssignmentResponse .Response .Task .TaskId != nil {
296- conf := tccommon .BuildStateChangeConf ([]string {}, []string {"Success" }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , * deleteRoleAssignmentResponse .Response .Task .TaskId , []string {}))
297- if _ , e := conf .WaitForState (); e != nil {
298- return e
321+ if deleteRoleAssignmentResponse == nil || deleteRoleAssignmentResponse .Response == nil {
322+ return fmt .Errorf ("delete role assignment response is nil" )
323+ }
324+ if deleteRoleAssignmentResponse .Response .Task == nil {
325+ return fmt .Errorf ("delete role assignment task is nil" )
326+ }
327+ task := deleteRoleAssignmentResponse .Response .Task
328+ if task .Status != nil && * task .Status == TASK_STATUS_FAILED {
329+ if task .FailureReason != nil {
330+ return fmt .Errorf ("delete role assignment failed, failure reason:%s" , * task .FailureReason )
331+ }
332+ return fmt .Errorf ("delete role assignment failed" )
333+ }
334+ if task .TaskId == nil {
335+ return fmt .Errorf ("delete role assignment task id is nil" )
336+ }
337+ conf := tccommon .BuildStateChangeConf ([]string {}, []string {TASK_STATUS_SUCCESS , TASK_STATUS_FAILED }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , * task .TaskId , []string {}))
338+ if object , e := conf .WaitForState (); e != nil {
339+ return e
340+ } else {
341+ taskStatus := object .(* organization.TaskStatus )
342+ if taskStatus .Status != nil && * taskStatus .Status == TASK_STATUS_FAILED {
343+ return fmt .Errorf ("delete role assignment failed" )
299344 }
300345 }
301346
@@ -318,10 +363,28 @@ func resourceTencentCloudIdentityCenterRoleAssignmentDelete(d *schema.ResourceDa
318363 return err
319364 }
320365
321- if dismantleRoleConfigurationResponse .Response != nil && dismantleRoleConfigurationResponse .Response .Task != nil && dismantleRoleConfigurationResponse .Response .Task .TaskId != nil {
322- conf := tccommon .BuildStateChangeConf ([]string {}, []string {"Success" }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , * dismantleRoleConfigurationResponse .Response .Task .TaskId , []string {}))
323- if _ , e := conf .WaitForState (); e != nil {
324- return e
366+ if dismantleRoleConfigurationResponse == nil || dismantleRoleConfigurationResponse .Response == nil {
367+ return fmt .Errorf ("dismantle role assignment response is nil" )
368+ }
369+ if dismantleRoleConfigurationResponse .Response .Task == nil {
370+ return fmt .Errorf ("dismantle role assignment task is nil" )
371+ }
372+ dismantleTask := dismantleRoleConfigurationResponse .Response .Task
373+
374+ if dismantleTask .TaskStatus != nil && * dismantleTask .TaskStatus == TASK_STATUS_FAILED {
375+ return fmt .Errorf ("dismantle role assignment task failed" )
376+ }
377+
378+ if dismantleTask .TaskId == nil {
379+ return fmt .Errorf ("dismantle role assignment task id is nil" )
380+ }
381+ conf = tccommon .BuildStateChangeConf ([]string {}, []string {TASK_STATUS_SUCCESS , TASK_STATUS_FAILED }, 2 * tccommon .ReadRetryTimeout , time .Second , service .AssignmentTaskStatusStateRefreshFunc (zoneId , * dismantleTask .TaskId , []string {}))
382+ if object , e := conf .WaitForState (); e != nil {
383+ return e
384+ } else {
385+ taskStatus := object .(* organization.TaskStatus )
386+ if taskStatus .Status != nil && * taskStatus .Status == TASK_STATUS_FAILED {
387+ return fmt .Errorf ("dismantle role assignment task failed" )
325388 }
326389 }
327390
0 commit comments