-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
There was a problem hiding this 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.
aws/data_source_aws_iam_role.go
Outdated
@@ -21,6 +16,11 @@ func dataSourceAwsIAMRole() *schema.Resource { | |||
"assume_role_policy_document": { | |||
Type: schema.TypeString, | |||
Computed: true, | |||
Removed: "Use `assume_role_policy` instead", |
There was a problem hiding this comment.
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.
1b73325
to
4c018a4
Compare
Thanks for the review @radeksimko . Just made the related changes!
|
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 👍
aws/data_source_aws_iam_role.go
Outdated
req := &iam.GetRoleInput{ | ||
RoleName: aws.String(roleName), | ||
if !hasName && !hasRoleName { | ||
return errwrap.Wrapf("`name` must be set", nil) |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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 usingfmt.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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
4c018a4
to
a7f45e7
Compare
LGTM, merge at will. 🙂 |
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! |
This normalizes the IAM Role data source to match the resource:
Fixes #1129
Tests