-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
local-exec provisioner doesn't run with the configured AWS provider account #21983
Comments
Hi @nergdron ! For the time being, since you can include environment variables in provisioner blocks, you might be able to export your AWS credentials as terraform environment variables - though I realize this might not work in your environment. Please note that the following is untested pseudo-code, but I think it's a good start: # SET AN ENV VAR - DON'T HARD CODE THIS
variable "aws_access_key_id" { }
resource "aws_thing" "example" {
provisioner "local_exec" {
environment {
AWS_ACCESS_KEY_ID = var.aws_access_key_id
}
}
} |
Yeah, we can't use environment variables for this because all our accounts have 2FA. Using just env vars in TF fails because the AWS 2FA can't prompt, and if we force the prompt in our script, it'd break our automated workflows from CI. So we really do need it to use the provider as configured to assume the role in the target account. Can you see any other approach we could take to use TF to configure EKS and then complete cluster configuration using a provisioner, keeping the role specified in the AWS provider? or any thoughts on when dynamic provider configuration will be done so we can fix all the issues we're currently hacking around because of that deficiency? |
I just ran into this and thought I leave my solution. We use
Unsetting the |
Summary: we have multiple AWS accounts configured for our users, one per deployment environment. We configure the Terraform AWS provider to use the right one for the right environment. However, when using the local-exec provisioner after creating a resource, the script provided to local-exec doesn't execute with the same AWS environment as
Terraform Version
Terraform Configuration Files
Terraform resource with local-exec provisioner:
local-exec script for execution:
Expected Behavior
Correctly runs script and configures local environment with the new EKS cluster details for further configuration, which is necessary as long as there's no dynamic provider configuration (see: #4149).
Actual Behavior
Script fails because it's run with the default AWS config and not the credentials configured in the provider:
Steps to Reproduce
terraform init && terraform apply
References
The text was updated successfully, but these errors were encountered: