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

Provider's assume_role is silently ignored if role_arn isn't known during the plan step #24796

Closed
KyleKotowick opened this issue May 16, 2022 · 2 comments · Fixed by #26590
Closed
Assignees
Labels
authentication Pertains to authentication; to the provider itself of otherwise. bug Addresses a defect in current functionality.
Milestone

Comments

@KyleKotowick
Copy link
Contributor

KyleKotowick commented May 16, 2022

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

Terraform v1.1.9
on windows_amd64
+ provider registry.terraform.io/hashicorp/aws v4.14.0

Affected Resource(s)

  • AWS provider

Terraform Configuration Files

provider "aws" {
  alias   = "main"
  profile = "InvictonLabs_sandbox"
  region  = "ca-central-1"
}
provider "aws" {
  alias   = "assumed"
  profile = "InvictonLabs_sandbox"
  region  = "ca-central-1"
  assume_role {
    // Use uuid() since the value isn't known until the apply step. Of course we would never actually use this, 
    // it's just an example showing the issue when `role_arn` isn't known during the plan step.
    role_arn = uuid()
  }
}

data "aws_caller_identity" "main" {
  provider = aws.main
}
data "aws_caller_identity" "assumed" {
  provider = aws.assumed
}

output "main_account_id" {
  value = data.aws_caller_identity.main.account_id
}
output "assumed_account_id" {
  value = data.aws_caller_identity.assumed.account_id
}
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

assumed_account_id = "170970691995"
main_account_id = "170970691995"

Debug Output

Uploaded here: https://drive.google.com/file/d/1MF9jBFBc3wE5bs4hQspJzCF8OFg_U0q1/view?usp=sharing
It's PGP encrypted with Hashicorp's public key (using Keybase).

Expected Behavior

  1. (Preferred): The provider is created only once the value is known (apply-step), and it would error with "be7864f5-1675-49bd-b3a0-32adf2597fb6 is not a valid role to assume" or similar.
  2. (Less Preferred): If it really, truly can't create a provider in the apply step instead of the plan step, it should error with "Cannot create a provider where values are not known during the plan step" or similar.

Actual Behavior

It just ignores the assume_role block altogether, and creates the provider without assuming a role. This is really bad, as it almost caused me to delete a whole bunch of things that shouldn't be deleted because it suddenly changed the account that the provider was using (when I made a change that caused the assumed role ARN to not be known until the apply step).

Steps to Reproduce

  1. terraform apply
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/sts Issues and PRs that pertain to the sts service. labels May 16, 2022
@gdavison gdavison self-assigned this May 16, 2022
@gdavison gdavison added bug Addresses a defect in current functionality. authentication Pertains to authentication; to the provider itself of otherwise. and removed needs-triage Waiting for first response or review from a maintainer. service/sts Issues and PRs that pertain to the sts service. labels May 16, 2022
@github-actions github-actions bot added this to the v4.29.0 milestone Sep 1, 2022
@github-actions
Copy link

github-actions bot commented Sep 2, 2022

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Oct 3, 2022

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
authentication Pertains to authentication; to the provider itself of otherwise. bug Addresses a defect in current functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants