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

data-source/aws_iam_user: Add permissions_boundary attribute #5187

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions aws/data_source_aws_iam_user.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
)

Expand All @@ -22,6 +22,10 @@ func dataSourceAwsIAMUser() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"permissions_boundary": {
Type: schema.TypeString,
Computed: true,
},
"user_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -44,13 +48,17 @@ func dataSourceAwsIAMUserRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Reading IAM User: %s", req)
resp, err := iamconn.GetUser(req)
if err != nil {
return errwrap.Wrapf("error getting user: {{err}}", err)
return fmt.Errorf("error getting user: %s", err)
}

user := resp.User
d.SetId(*user.UserId)
d.SetId(aws.StringValue(user.UserId))
d.Set("arn", user.Arn)
d.Set("path", user.Path)
d.Set("permissions_boundary", "")
if user.PermissionsBoundary != nil {
d.Set("permissions_boundary", user.PermissionsBoundary.PermissionsBoundaryArn)
}
d.Set("user_id", user.UserId)

return nil
Expand Down
3 changes: 2 additions & 1 deletion aws/data_source_aws_iam_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func TestAccAWSDataSourceIAMUser_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.aws_iam_user.test", "user_id"),
resource.TestCheckResourceAttr("data.aws_iam_user.test", "path", "/"),
resource.TestCheckResourceAttr("data.aws_iam_user.test", "permissions_boundary", ""),
resource.TestCheckResourceAttr("data.aws_iam_user.test", "user_name", userName),
resource.TestMatchResourceAttr("data.aws_iam_user.test", "arn", regexp.MustCompile("^arn:aws:iam::[0-9]{12}:user/"+userName)),
resource.TestMatchResourceAttr("data.aws_iam_user.test", "arn", regexp.MustCompile("^arn:[^:]+:iam::[0-9]{12}:user/"+userName)),
),
},
},
Expand Down
3 changes: 1 addition & 2 deletions website/docs/d/iam_user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ data "aws_iam_user" "example" {
## Attributes Reference

* `arn` - The Amazon Resource Name (ARN) assigned by AWS for this user.

* `path` - Path in which this user was created.

* `permissions_boundary` - The ARN of the policy that is used to set the permissions boundary for the user.
* `user_id` - The unique ID assigned by AWS for this user.