-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
remote_state backend S3 bucket parameters not set when using an assumed role profile #1650
Comments
I had an issue as same as you. At first i believe is the permission issue on aws arn. Terragrunt.hcllocals {
# Automatically load account-level variables
account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
# Automatically load region-level variables
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
short_region = local.region_vars.locals.short_region
aws_region = local.region_vars.locals.aws_region
aws_profile = local.account_vars.locals.aws_profile
aws_assume_role = local.account_vars.locals.aws_assume_role
}
# Generate an AWS provider block
generate "provider" {
path = "provider.tf"
if_exists = "overwrite"
contents = <<EOF
provider "aws" {
shared_credentials_file = "~/.aws/credentials"
# Only these AWS Account IDs may be operated on by this template
profile = "${local.aws_profile}"
region = "${local.aws_region}"
assume_role {
role_arn = "${local.aws_assume_role}"
}
}
provider "random" {
}
EOF
}
# Configure Terragrunt to automatically store tfstate files in an S3 bucket
remote_state {
backend = "s3"
config = {
encrypt = true
bucket = "${local.account_name}-${local.short_region}-test-terraform-state"
key = "${path_relative_to_include()}/terraform.tfstate"
region = local.aws_region
profile = local.aws_profile
}
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
} account.hcl# Set account-wide variables. These are automatically pulled in to configure the remote state bucket in the root
# terragrunt.hcl configuration.
locals {
account_name = "account1"
aws_account_name = "aws-account1"
aws_profile = "aad-sso-account1"
aws_assume_role = "arn:aws:iam::123456789012:role/terrgrunt-role"
} region.hcl# Set common variables for the region. This is automatically pulled in in the root terragrunt.hcl configuration to
# configure the remote state bucket and pass forward to the child modules as inputs.
locals {
aws_region = "ap-southeast-1"
short_region = "aps1"
} $ terragrunt plan --terragrunt-debug --terragrunt-log-level debug
Follow our company policy, we don't have own aws account. We use azure sso, then choose assume_role. |
Fix released as https://github.com/gruntwork-io/terragrunt/releases/tag/v0.29.1. Binaries should show up shortly. |
I am still seeing issues in 0.29.1 (and Tf 0.15.1) so I am not sure whether it's best to open a new issue (like #1661) or just comment here? The brief synopsis is Terragrunt seems to be ignoring all credentials except the |
Can you share how you are invoking terragrunt? The fix in v0.29.1 is to properly honor either the |
I was setting |
Ah because of the way the SDK works, the |
🤦 My bad. Thanks for the explanation 😄 |
Overview
When using an AWS Profile configured to assume an IAM Role to run terragrunt, the bucket is created successfully but none of the bucket parameters are set. This includes properties like Taggin, SSE, Versioning, and Bucket Policy.
NOTE: Initially I thought this issue was isolated to AWS SSO Profiles but I have been able to reproduce this issue with any assumed role AWS Profile!
The following error is observed during the bucket creation/init sequence...
Steps to Reproduce
Testing with standard AWS IAM Role Assumption Profile
Show Identity
NOTE: The behavior is the same whether
AWS_PROFILE
and/orAWS_DEFAULT_PROFILE
are set to the desired profileTerragrunt.hcl
test_module/test.tf
Terragrunt Apply (first-run with backend S3 bucket creation)
Testing with AWS SSO Profile
Terragrunt.hcl
test_module/test.tf
Terragrunt Apply (first-run with backend S3 bucket creation)
Workarounds
Using AWS Credential Environment variables
If you use standard AWS credential env vars (i.e.
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
,AWS_SESSION_TOKEN
) instead of using an AWS Profile (i.e.AWS_PROFILE
and/orAWS_DEFAULT_PROFILE
env vars) the bucket creation and parameters are set correctly, as expected, without error.NOTE: It does NOT matter where the AWS cred env vars are sourced from (e.g. AWS IAM User, AWS IAM Role assumption, AWS SSO generated CLI Creds)
Terragrunt Apply (first-run with backend S3 bucket creation)
Using Terragrunt
iam_role
config property to assume the role instead of an AWS ProfileNOTE: This method will not work with assumption of SSO IAM Roles as they are only assumable by the AWS SSO service!
Terragrunt.hcl
test_module/test.tf
Terragrunt Apply (first-run with backend S3 bucket creation)
Related: #1129, #1537
Possibly related: #1369
The text was updated successfully, but these errors were encountered: