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

New Resource: aws_ram_resource_association #7449

Merged
merged 2 commits into from
Feb 12, 2019

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Feb 5, 2019

Reference: #6527

Output from acceptance testing:

--- PASS: TestAccAwsRamResourceAssociation_disappears (29.50s)
--- PASS: TestAccAwsRamResourceAssociation_basic (31.78s)

@bflad bflad added new-resource Introduces a new resource. help wanted service/ram Issues and PRs that pertain to the ram service. labels Feb 5, 2019
@ghost ghost added documentation Introduces or discusses updates to documentation. size/XL Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Feb 5, 2019
@dbektas
Copy link

dbektas commented Feb 5, 2019

Hi @bflad !

as far as I am aware, one needs to switch to Master Account within a certain AWS organisation -> go to AWS RAM -> Settings -> enable Sharing.
This step is a requirement in order to be able to share resource with other principals within a certain organisation. Just then you can switch back to your previous account and be able to share resources with others.

However I am not sure why you are not able to share resources from standalone account (meaning share with external accounts)? I was expecting this test to pass as there are no prior requirements to be conducted.

Please let me know if I can be of further help.

@bflad
Copy link
Contributor Author

bflad commented Feb 5, 2019

@dbektas I can understand the error with our "normal" testing AWS account that is a member of an AWS Organizations Organization, but the error is really odd with the standalone AWS account (AWS Organizations disabled / not a member or master of an Organization).

In both my manual and automated testing it is not trying to associate any principals with the Resource Share, just associating resources with it via AssociateResourceShare, to manage that piece of functionality with the service. The fact the error doesn't occur during Resource Share creation, but only after, is strange. 🙁 In any event, I have opened AWS Support Case 5755832021 to track this and will report back any findings from that.

@dbektas
Copy link

dbektas commented Feb 5, 2019

Yeah, I just checked RAM whitepaper and I would suggest that this is not even foreseen to be supported by AWS.

Meaning, the only way to share resources is to be within an organisation.

However, im subscribed to this, keenly waiting for the resolution.

Reference: #6527

Output from acceptance testing:

```
--- PASS: TestAccAwsRamResourceAssociation_disappears (29.50s)
--- PASS: TestAccAwsRamResourceAssociation_basic (31.78s)
```
@bflad bflad force-pushed the f-aws_ram_resource_association branch from 74680fa to 384be32 Compare February 6, 2019 18:06
@bflad bflad removed the help wanted label Feb 6, 2019
@bflad bflad requested a review from a team February 6, 2019 18:06
@bflad
Copy link
Contributor Author

bflad commented Feb 6, 2019

Enabling Resource Sharing in the master AWS Organizations account got past the AssociateResourceShare error in the account that is part of an organization. I'll try to post further updates from support regarding whether standalone accounts are supported at all or if they plan on having CreateResourceShare fail the same way, fixing the AssociateResourceShare error, or improving the error message/documentation.

Terraform resource has been successfully acceptance tested and is ready for review.

@bflad bflad changed the title [WIP] New Resource: aws_ram_resource_association New Resource: aws_ram_resource_association Feb 6, 2019
@sudomann
Copy link

sudomann commented Feb 6, 2019

When should one expect to be able to use this?

@bflad
Copy link
Contributor Author

bflad commented Feb 7, 2019

When should one expect to be able to use this?

When it is reviewed by another maintainer, any feedback is addressed, and the merged code is released. My best guess would be either today (if someone is available) or middle of next week.

Copy link
Member

@nywilken nywilken 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 good to me. I left a few questions and minor suggestions but nothing that would prevent this from being merged.

resourceShareARN := d.Get("resource_share_arn").(string)

input := &ram.AssociateResourceShareInput{
ClientToken: aws.String(resource.UniqueId()),
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about adding a comment indicating that ClientToken is unique case-sensitive id used for tracking the request, and not an AWS Account ID? Or maybe just adding a link to https://docs.aws.amazon.com/ram/latest/APIReference/API_AssociateResourceShare.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what this has to do with an AWS account ID and we don't tend to re-document the AWS Go SDK structs inline. Using resource.UniqueId() is just for a 26 digit randomly generated number behind a mutex to help protect from concurrency issues. We do this rather than implementing our function when one is readily available. We could use resource.PrefixedUniqueId() which would allow for some form of prefix beyond the resource.UniqueId() default of "terraform-", etc. but many of these ClientToken/IdempotencyToken fields have byte length restrictions so in my opinion seems safer to just default to a short standard.

If you would like anything changed in this regard, we should create an issue and apply the change across the codebase.

Copy link
Member

@nywilken nywilken Feb 12, 2019

Choose a reason for hiding this comment

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

If you would like anything changed in this regard, we should create an issue and apply the change across the codebase.

Sorry for the confusion I was actually referring to the field name ClientToken. At first glance it seemed like an AWS specific thing but after reading the documentation I understood why resource.UniqueId() was being used. No action necessary. Thanks for the explanation of resource.UniqueId() and resource.PrefixUniqueId() btw.

}
}

func waitForRamResourceShareResourceAssociation(conn *ram.RAM, resourceShareARN, resourceARN string) error {
Copy link
Member

Choose a reason for hiding this comment

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

The func name waitForRamResourceShareResourceAssociation has a bit of a stutter. What do you think shortening this to waitForResourceAssociationShare(...) as the other parts are implied by the function signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naming is hard. 😅 In previous code reviews I was asked to do waitForServiceThingAction before for a consistent pattern, but everything in this regard is all over the place if you look across the codebase. If you feel strongly about this, I can certainly go back and adjust these (this isn't the only stuttering one simply due to the action being similar to the thing).

Copy link
Member

Choose a reason for hiding this comment

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

Naming is hard.

Probably the first biggest problem in programming.

I don't feel strongly enough about it to adjust right now. I would be interested in thinking about it more when we start to think about large resource refactors or at least looking at what is the most consistent. Thanks again for the background context.

log.Printf("[DEBUG] Disassociating RAM Resource Share: %s", input)
_, err = conn.DisassociateResourceShare(input)

if isAWSErr(err, ram.ErrCodeUnknownResourceException, "") {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a pattern we follow: check for isAWSErr than check err != nil. Is there a reason, other than the nested if statements, that we don't do something like the following to reduce the number if err checks?

if err != nil {
  if isAWSErr(err, ram.ErrCodeUnkonwnResourceException, "") {
    return nil
  }

return fmt.Errorf("error disassociating RAM Resource Share (%s) Resource Association (%s): %s", resourceShareARN, resourceARN, 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.

There are two good reasons:

  • It follows a good (in my opinion easier to read) coding style practice of aligning the happy path on the left and encourages returning early
  • It prevents subtle error handling bugs, which are hard to catch during review. I caught this one in a review just the other day (I can dig up the reference if necessary):
if err != nil {
  if isAWSErr(err, "...", "...") {
    return nil
  }
}

Or the occasional:

if err != nil {
  if isAWSErr(err, "...", "...") {
    log.Printf("[WARN] Thing X (%s) not found, removing from state", d.Id())
    d.SetId("")
    return nil
  }
}

These look trivial when isolated, but when reviewing hundreds of lines of code they can be easy to miss. I'm not sure a linter can catch them either unless there is one out there that requires combining a nested if with its parent when its the only logic in the conditional.

Copy link
Member

Choose a reason for hiding this comment

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

These look trivial when isolated, but when reviewing hundreds of lines of code they can be easy to miss. I'm not sure a linter can catch them either unless there is one out there that requires combining a nested if with its parent when its the only logic in the conditional.

Great point! Thanks for sharing from your experiences 💯

@bflad bflad added this to the v1.59.0 milestone Feb 12, 2019
@bflad bflad merged commit 9016821 into master Feb 12, 2019
@bflad bflad deleted the f-aws_ram_resource_association branch February 12, 2019 15:44
bflad added a commit that referenced this pull request Feb 12, 2019
@bflad
Copy link
Contributor Author

bflad commented Feb 14, 2019

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

@ghost
Copy link

ghost commented Mar 31, 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 Mar 31, 2020
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. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/ram Issues and PRs that pertain to the ram service. size/XL 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.

None yet

4 participants