Skip to content
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

Add members attribute to iam_group data source #7132

Conversation

teraken0509
Copy link
Contributor

Fixes #7076

Changes proposed in this pull request:

  • Add members attribute
  • Modify document

Output from acceptance testing:

$  make testacc TEST=./aws TESTARGS='-run=TestAccAWSDataSourceIAMGroup_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSDataSourceIAMGroup_ -timeout 120m
=== RUN   TestAccAWSDataSourceIAMGroup_basic
=== PAUSE TestAccAWSDataSourceIAMGroup_basic
=== RUN   TestAccAWSDataSourceIAMGroup_member
=== PAUSE TestAccAWSDataSourceIAMGroup_member
=== CONT  TestAccAWSDataSourceIAMGroup_basic
=== CONT  TestAccAWSDataSourceIAMGroup_member
--- PASS: TestAccAWSDataSourceIAMGroup_basic (25.23s)
--- PASS: TestAccAWSDataSourceIAMGroup_member (31.90s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	31.950s

@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/iam Issues and PRs that pertain to the iam service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jan 14, 2019
@bflad bflad added new-data-source Introduces a new data source. enhancement Requests to existing resources that expand the functionality or scope. and removed new-data-source Introduces a new data source. labels Jan 15, 2019
@maxenglander
Copy link
Contributor

Hi @bflad is there anything blocking this from being merged/released?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kterada0509 👋 Thanks so much for submitting this and apologies for the delayed review. Overall this is looking really good, just a few minor things below and we should be able to get this in. Please reach out if you have any questions or do not have time to implement these items.

@@ -58,6 +82,20 @@ func dataSourceAwsIAMGroupRead(d *schema.ResourceData, meta interface{}) error {
d.Set("arn", group.Arn)
d.Set("path", group.Path)
d.Set("group_id", group.GroupId)
d.Set("members", dataSourceUsersRead(resp.Users))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using d.Set() with aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. 👍

Suggested change
d.Set("members", dataSourceUsersRead(resp.Users))
if err := d.Set("members", dataSourceUsersRead(resp.Users)); err != nil {
return fmt.Errorf("error setting members: %s", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

resource.TestCheckResourceAttrSet("data.aws_iam_group.test", "group_id"),
resource.TestCheckResourceAttr("data.aws_iam_group.test", "path", "/"),
resource.TestCheckResourceAttr("data.aws_iam_group.test", "group_name", groupName),
resource.TestMatchResourceAttr("data.aws_iam_group.test", "arn", regexp.MustCompile("^arn:aws:iam::[0-9]{12}:group/"+groupName)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify this and allow this testing to work in multiple AWS partitions with the below:

Suggested change
resource.TestMatchResourceAttr("data.aws_iam_group.test", "arn", regexp.MustCompile("^arn:aws:iam::[0-9]{12}:group/"+groupName)),
testAccCheckResourceAttrGlobalARN("data.aws_iam_group.test", "arn", "iam", fmt.Sprintf("group/%s", groupName)),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

resource.TestMatchResourceAttr("data.aws_iam_group.test", "arn", regexp.MustCompile("^arn:aws:iam::[0-9]{12}:group/"+groupName)),
resource.TestCheckResourceAttr("data.aws_iam_group.test", "members.#", "1"),
resource.TestCheckResourceAttrPair("data.aws_iam_group.test", "members.0.arn", "aws_iam_user.user", "arn"),
resource.TestCheckResourceAttrSet("data.aws_iam_group.test", "members.0.user_id"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be compared using the aws_iam_user resource unique_id attribute:

Suggested change
resource.TestCheckResourceAttrSet("data.aws_iam_group.test", "members.0.user_id"),
resource.TestCheckResourceAttrPair("data.aws_iam_group.test", "members.0.user_id", "aws_iam_user.user", "unique_id"),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -31,3 +31,15 @@ data "aws_iam_group" "example" {
* `path` - The path to the group.

* `group_id` - The stable and unique string identifying the group.

* `members` - The member of group. See supported fields below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Terraform 0.12, our documentation wording for explaining types is a little more important. 😄 Could you please note that this is a list of objects? e.g.

Suggested change
* `members` - The member of group. See supported fields below.
* `members` - List of objects containing group member information. See supported fields below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i updated the docs

@@ -30,6 +30,30 @@ func dataSourceAwsIAMGroup() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"members": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting here, that we may want to consider naming this attribute users to match the API. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i fixed.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Nov 7, 2019
@teraken0509 teraken0509 force-pushed the feature/add-members-attribute-for-iam-group-data-source branch from 57c114f to a81380b Compare November 8, 2019 08:27
@teraken0509
Copy link
Contributor Author

Re-run acctest.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSDataSourceIAMGroup_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSDataSourceIAMGroup_ -timeout 120m
=== RUN   TestAccAWSDataSourceIAMGroup_basic
=== PAUSE TestAccAWSDataSourceIAMGroup_basic
=== RUN   TestAccAWSDataSourceIAMGroup_users
=== PAUSE TestAccAWSDataSourceIAMGroup_users
=== CONT  TestAccAWSDataSourceIAMGroup_basic
=== CONT  TestAccAWSDataSourceIAMGroup_users
--- PASS: TestAccAWSDataSourceIAMGroup_basic (33.84s)
--- PASS: TestAccAWSDataSourceIAMGroup_users (38.82s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	38.896s

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 8, 2019
@bflad bflad added this to the v2.36.0 milestone Nov 8, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks so much for this, @kterada0509 🚀

Output from acceptance testing:

--- PASS: TestAccAWSDataSourceIAMGroup_basic (10.27s)
--- PASS: TestAccAWSDataSourceIAMGroup_users (12.62s)

@bflad bflad merged commit 2b61253 into hashicorp:master Nov 8, 2019
bflad added a commit that referenced this pull request Nov 8, 2019
@ghost
Copy link

ghost commented Nov 14, 2019

This has been released in version 2.36.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Dec 9, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Dec 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Include members in attributes of aws_iam_group data source
3 participants