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

Normalized the IAM role data source #1330

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

Ninir
Copy link
Contributor

@Ninir Ninir commented Aug 3, 2017

This normalizes the IAM Role data source to match the resource:

  • Arguments & attributes are now named the same as in the resource
  • The data source acceptance test has been fixed to include a variabilized part
  • It is now using the read method from the resource, which handles more cases

Fixes #1129

Tests

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSDataSourceIAMRole_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSDataSourceIAMRole_basic -timeout 120m
=== RUN   TestAccAWSDataSourceIAMRole_basic
--- PASS: TestAccAWSDataSourceIAMRole_basic (35.26s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	35.291s

@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Aug 3, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

This looks otherwise sensible, just left you a comment regarding deprecation policy - we prefer not to break things for people without prior warning.

@@ -21,6 +16,11 @@ func dataSourceAwsIAMRole() *schema.Resource {
"assume_role_policy_document": {
Type: schema.TypeString,
Computed: true,
Removed: "Use `assume_role_policy` instead",
Copy link
Member

Choose a reason for hiding this comment

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

I think we should deprecate things in the first stage and then eventually phase them out after a few releases, in a separate PR.

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Aug 3, 2017
@Ninir
Copy link
Contributor Author

Ninir commented Aug 4, 2017

Thanks for the review @radeksimko . Just made the related changes!

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSDataSourceIAMRole_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSDataSourceIAMRole_basic -timeout 120m
=== RUN   TestAccAWSDataSourceIAMRole_basic
--- PASS: TestAccAWSDataSourceIAMRole_basic (20.92s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	20.955s

@Ninir Ninir removed the waiting-response Maintainers are waiting on response from community or contributor. label Aug 4, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

I left you just one really low prio question - this LGTM.


req := &iam.GetRoleInput{
RoleName: aws.String(roleName),
if !hasName && !hasRoleName {
Copy link
Member

Choose a reason for hiding this comment

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

Nice work with meaningful variable names here 👍

req := &iam.GetRoleInput{
RoleName: aws.String(roleName),
if !hasName && !hasRoleName {
return errwrap.Wrapf("`name` must be set", nil)
Copy link
Member

@radeksimko radeksimko Aug 5, 2017

Choose a reason for hiding this comment

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

What's the benefit of errwrap here, as we're not wrapping any error? Can't it be either fmt.Errorf() (with name being argument) or errors.New()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When looking at Wrapf, it states:

Wrapf wraps an error with a formatting message. This is similar to using fmt.Errorf to wrap an error. If you're using fmt.Errorf to wrap errors, you should replace it with this.

Find it better to use it than fmt.Errorf, but errors.New could still do it. Do you prefer one or the other?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is about one or the other - both have valid use cases.

As you rightly quote from errwrap "... to wrap errors ...". 😉 We don't have a real error (as in nothing matching error interface) as we're literally constructing new string-based one here. errwrap is meant to be used for cases where you get a typed error (e.g. from AWS SDK) and you want to add some extra context without hiding the original error behind.

fmt.Errorf("Extra context: %s", origErr) comes back as &errors.errorString{s:"Extra context: stringified original error"}. You have no way to reliably figure out what the original error was, except by doing string match of the message. Errwrap provides way to do this: https://github.com/hashicorp/errwrap#custom-types

We'd rarely use errwrap when returning error from CRUD, because there's unlikely going to be anything relying on the error type in the rest of the stack. We only present it to the user as text.

Let me know if that explanation makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes total sense, thanks for the precision there. Should be all ok.

@radeksimko
Copy link
Member

LGTM, merge at will. 🙂

@Ninir Ninir merged commit 8ef9c6a into hashicorp:master Aug 7, 2017
@Ninir Ninir deleted the f-iam-role-attributes branch August 7, 2017 09:02
@ghost
Copy link

ghost commented Apr 11, 2020

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 Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discrepancy between aws_iam_role and data.aws_iam_role
2 participants