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

ARN attribute may contain incorrect AWS account ID for shareable resources #16978

Closed
12 tasks done
ewbankkit opened this issue Jan 5, 2021 · 15 comments
Closed
12 tasks done
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented Jan 5, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

AWS Provider v3.22.0.

Various resources (and data sources) for a number of AWS services include a computed arn resource that is synthesized in the resource's Read code rather than being set from relevant AWS API call's response (as the AWS API response does not include an ARN property). This page is a good starting point for finding the correct ARN format for such resources.
For shareable resources the account ID should be the ID of the AWS account that owns the resource, however in many such cases we are incorrectly setting the account ID field to the ID of the AWS account that is running Terraform. While these two account IDs are equal for resources that are actually created, they will be different for data sources (and resources that adopt resources, such as aws_default_route_table) if Terraform is run in the AWS account that the resource is shared into I.e. NOT the account that the corresponding resource was created in and subsequently shared from).

A typical incorrect pattern is

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("vpc/%s", d.Id()),
}.String()
d.Set("arn", arn)

whereas a correct pattern is:

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: *sg.OwnerId,
Resource: fmt.Sprintf("security-group/%s", *sg.GroupId),
}.String()
d.Set("arn", arn)

(apart from from the raw pointer dereference: #12992).

Affected Resource(s)

Relates: #13624.

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

@shuheiktgw
Copy link
Collaborator

The last one! 🎉 Thank you for your review, @ewbankkit!

@breathingdust
Copy link
Member

Hi @shuheiktgw! Thanks for all your work on this issue. 🚀 I've been trying to find your contact details, if you had a moment would you be able to email me at the address in my profile? Thank you!

@shuheiktgw
Copy link
Collaborator

shuheiktgw commented Mar 21, 2021

@breathingdust Sure! I just sent you an email so would you check your inbox?

@ewbankkit
Copy link
Contributor Author

The final affected resource will be corrected with Terraform AWS Provider v3.35.0.

@ghost
Copy link

ghost commented Apr 26, 2021

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 as resolved and limited conversation to collaborators Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.
Projects
None yet
Development

No branches or pull requests

3 participants