Skip to content

Commit

Permalink
minor changes to assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
hariarla committed Aug 28, 2023
1 parent e85c169 commit 72db63e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand All @@ -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("")

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
18 changes: 10 additions & 8 deletions website/docs/r/iam_access_group_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72db63e

Please sign in to comment.