I'm having an issue with terraform/terragrunt deploying into multiple accounts. I want to manage DNS and KMS in my "master" account and deploy everything else into my dev/uat/prod environments.
I've configured multiple AWS accounts using the providers. One is auto-created through terragrunt and the other one is creating within my main.tf file.
I've tried many different ways to get this to work. Aliasing both providers, setting just one provider with an alias and removing terragrunt completely from the equation. In every case, the terraform is being applied to my "master" account for all resources..
Below is an example of my code:
backend = "s3"
# generate = {
# path = "backend.tf"
# if_exists = "overwrite"
# }
config = {
bucket = "arm-terraform-state"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-west-2"
dynamodb_table = "arm-terraform-state-lock"
}
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
alias = "main"
region = "${local.aws_region}"
profile = "${local.account}"
}
EOF
}
locals {
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
aws_region = local.region_vars.locals.aws_region
account = local.account_vars.locals.aws_profile
}
Above is my Terragrunt code. This is my module:
resource "aws_iam_role_policy" "logging_role_policy" {
provider = aws.main
name = format("aws-sftp-logging-policy-%s-%s",var.product_name,var.env)
role= aws_iam_role.logging_role.id
policy = data.aws_iam_policy_document.sftp_logging.json
}
############
# Route 53 #
############
resource "aws_route53_record" "sftp_record" {
provider = aws.master
zone_id = data.aws_route53_zone.facteus.zone_id
name = format("%s-%s",var.product_name,var.env)
type = "CNAME"
ttl = "30"
records = [aws_transfer_server.aws_transfer_service.endpoint]
}
account.hcl
that defines a different profile? – jordanmrole_arn
for the AWS provider and configuring roles which can be assumed on different accounts – jordanm