diff --git a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_assignment.go b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_assignment.go index 648d03b82f..fb786da9a6 100644 --- a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_assignment.go +++ b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_assignment.go @@ -198,7 +198,7 @@ func resourceIBMIAMAccessGroupTemplateAssignmentCreate(context context.Context, d.SetId(*templateAssignmentResponse.ID) - _, err = waitForAssignment(d.Timeout(schema.TimeoutCreate), meta, d, isAccountSettingsTemplateAssigned) + _, err = waitForAssignment(d.Timeout(schema.TimeoutCreate), meta, d, isAccessGroupTemplateAssigned) if err != nil { return diag.FromErr(fmt.Errorf("error assigning %s", err)) } @@ -309,7 +309,7 @@ func resourceIBMIAMAccessGroupTemplateAssignmentUpdate(context context.Context, log.Printf("[DEBUG] UpdateAssignmentWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("UpdateAssignmentWithContext failed %s\n%s", err, response)) } - waitForAssignment(d.Timeout(schema.TimeoutUpdate), meta, d, isAccountSettingsTemplateAssigned) + waitForAssignment(d.Timeout(schema.TimeoutUpdate), meta, d, isAccessGroupTemplateAssigned) } return resourceIBMIAMAccessGroupTemplateAssignmentRead(context, d, meta) @@ -331,7 +331,7 @@ func resourceIBMIAMAccessGroupTemplateAssignmentDelete(context context.Context, return diag.FromErr(fmt.Errorf("DeleteAssignmentWithContext failed %s\n%s", err, response)) } - waitForAssignment(d.Timeout(schema.TimeoutDelete), meta, d, isAccountSettingsTemplateAssigned) + waitForAssignment(d.Timeout(schema.TimeoutDelete), meta, d, isAccessGroupTemplateAssignmentDeleted) d.SetId("") @@ -352,7 +352,7 @@ func waitForAssignment(timeout time.Duration, meta interface{}, d *schema.Resour return stateConf.WaitForState() } -func isAccountSettingsTemplateAssigned(id string, meta interface{}) resource.StateRefreshFunc { +func isAccessGroupTemplateAssigned(id string, meta interface{}) resource.StateRefreshFunc { return func() (interface{}, string, error) { iamAccessGroupsClient, err := meta.(conns.ClientSession).IAMAccessGroupsV2() if err != nil { @@ -388,3 +388,29 @@ func isAccountSettingsTemplateAssigned(id string, meta interface{}) resource.Sta return assignment, failed, fmt.Errorf("[ERROR] Unexpected status reached for assignment %s.: %s\n", id, response) } } + +func isAccessGroupTemplateAssignmentDeleted(id string, meta interface{}) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + iamAccessGroupsClient, err := meta.(conns.ClientSession).IAMAccessGroupsV2() + if err != nil { + return nil, failed, err + } + + getAssignmentOptions := &iamaccessgroupsv2.GetAssignmentOptions{} + + getAssignmentOptions.SetAssignmentID(id) + + assignment, response, err := iamAccessGroupsClient.GetAssignment(getAssignmentOptions) + + if err != nil { + if response != nil && response.StatusCode == 404 { + return assignment, complete, nil + } + + return nil, failed, fmt.Errorf("[ERROR] The assignment %s failed to delete or deletion was not completed within specific timeout period: %s\n%s", id, err, response) + } else { + log.Printf("Assignment removal still in progress\n") + } + return assignment, InProgress, nil + } +} diff --git a/website/docs/r/iam_access_group_template.html.markdown b/website/docs/r/iam_access_group_template.html.markdown index d942493d20..1c6bb01651 100644 --- a/website/docs/r/iam_access_group_template.html.markdown +++ b/website/docs/r/iam_access_group_template.html.markdown @@ -66,11 +66,15 @@ resource "ibm_iam_access_group_template" "iam_access_group_template_instance" { You can specify the following arguments for this resource. -* `account_id` - (Required, Forces new resource, String) The ID of the account to which the access group template is assigned. - * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9_-]+$/`. -* `description` - (Optional, Forces new resource, String) The description of the access group template. +* `name` - (Required, String) The name of the access group template. + * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9!@#$%^&*()_+{}:;"'<>,.?\/|\\-\\s]+$/`. + + **Note:** "Name" will be out of sync when anyone of the version resource updates this parameter. Please update this parameter with the latest version name +* `description` - (Optional, String) The description of the access group template. * Constraints: The maximum length is `250` characters. The minimum length is `0` characters. The value must match regular expression `/^[a-zA-Z0-9!@#$%^&*()_+{}:;"'<>,.?\/|\\-\\s]+$/`. -* `group` - (Optional, Forces new resource, List) Access Group Component. +* `account_id` - (Required, String) The ID of the account to which the access group template is assigned. + * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9_-]+$/`. +* `group` - (Optional, List) Access Group Component. Nested schema for **group**: * `action_controls` - (Optional, List) Access group action controls component. Nested schema for **action_controls**: @@ -119,16 +123,14 @@ Nested schema for **group**: * Constraints: The list items must match regular expression `/^[a-zA-Z0-9!@#$%^&*()_+{}:;"'<>,.?\/|\\-\\s]+$/`. The maximum length is `50` items. The minimum length is `0` items. * `name` - (Required, String) Give the access group a unique name that doesn't conflict with other templates access group name in the given account. This is shown in child accounts. * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9!@#$%^&*()_+{}:;"'<>,.?\/|\\-\\s]+$/`. -* `name` - (Required, Forces new resource, String) The name of the access group template. - * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9!@#$%^&*()_+{}:;"'<>,.?\/|\\-\\s]+$/`. -* `policy_template_references` - (Optional, Forces new resource, List) References to policy templates assigned to the access group template. +* `policy_template_references` - (Optional, List) References to policy templates assigned to the access group template. * Constraints: The maximum length is `100` items. The minimum length is `0` items. Nested schema for **policy_template_references**: * `id` - (Optional, String) Policy template ID. * Constraints: The maximum length is `100` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9_-]+$/`. * `version` - (Optional, String) Policy template version. * Constraints: The maximum length is `2` characters. The minimum length is `1` character. The value must match regular expression `/^[0-9]+$/`. -* `transaction_id` - (Optional, Forces new resource, String) An optional transaction id for the request. +* `transaction_id` - (Optional, String) An optional transaction id for the request. * Constraints: The maximum length is `50` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9_-]+$/`. ## Attribute Reference