Thank you for explaining that. Once you’ve passed the configuration_aliases into the nf_cis_benchmark module.
module nf_cis_benchmark {
source = "./modules/nf_cis_benchmark"
name = local.name
environment = "${local.environments[terraform.workspace]}"
region = data.aws_region.current.name
organization_id = data.aws_organizations_organization.org.id
account_id = data.aws_caller_identity.current.account_id
workspace = "${terraform.workspace}"
workspace_iam_roles = var.workspace_iam_roles[terraform.workspace]
providers = {
aws.us-east-1 = aws
aws.af-south-1 = aws.af-south-1
aws.ap-east-1 = aws.ap-east-1
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1,
aws.ap-southeast-2 = aws.ap-southeast-2
aws.ca-central-1 = aws.ca-central-1,
aws.eu-central-1 = aws.eu-central-1,
aws.eu-north-1 = aws.eu-north-1,
aws.eu-south-1 = aws.eu-south-1,
aws.eu-west-1 = aws.eu-west-1,
aws.eu-west-2 = aws.eu-west-2,
aws.eu-west-3 = aws.eu-west-3,
aws.me-south-1 = aws.me-south-1,
aws.sa-east-1 = aws.sa-east-1,
aws.us-east-2 = aws.us-east-2,
aws.us-west-1 = aws.us-west-1,
aws.us-west-2 = aws.us-west-2
}
}
Then the nf_cis_benchmark module should call the vpc module which uses the providers like so
module vpc {
count = var.environment != "logging" || var.environment != "billing" ? 1 : 0
source = "./modules/vpc"
aws_s3_bucket = "${aws_s3_bucket.vpc_flow_log.id}"
aws_s3_bucket_arn = "${aws_s3_bucket.vpc_flow_log.arn}"
workspace_iam_roles= var.workspace_iam_roles
providers = {
aws.us-east-1 = aws
aws.af-south-1 = aws.af-south-1
aws.ap-east-1 = aws.ap-east-1
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1,
aws.ap-southeast-2 = aws.ap-southeast-2
aws.ca-central-1 = aws.ca-central-1,
aws.eu-central-1 = aws.eu-central-1,
aws.eu-north-1 = aws.eu-north-1,
aws.eu-south-1 = aws.eu-south-1,
aws.eu-west-1 = aws.eu-west-1,
aws.eu-west-2 = aws.eu-west-2,
aws.eu-west-3 = aws.eu-west-3,
aws.me-south-1 = aws.me-south-1,
aws.sa-east-1 = aws.sa-east-1,
aws.us-east-2 = aws.us-east-2,
aws.us-west-1 = aws.us-west-1,
aws.us-west-2 = aws.us-west-2
}
}
The vpc module then call a flow_log module like so
module af-south-1 {
source = "./modules/flow_log"
providers = {
aws = aws.af-south-1
}
log_destination = "${module.nf_cis_benchmark.aws_s3_bucket_vpc_flow_log}"
log_destination_type = "s3"
traffic_type = "REJECT"
aws_vpc_ids = data.aws_vpcs.af-south-1.ids
}
The main.tf flow log module looks like so
resource aws_flow_log flow_log{
count = length(var.aws_vpc_ids)
log_destination = var.log_destination
log_destination_type = var.log_destination_type
traffic_type = var.traffic_type
vpc_id = var.aws_vpc_ids[count.index]
depends_on = [ var.log_destination ]
// Tags
tags = {
Name = "${var.aws_vpc_ids[count.index]}"
cost_environment = "${local.environments[terraform.workspace] == "production" ? "production" : "non-production"}"
cost_category = "SEC"
cost_team_owner = "MOPRAV"
}
}
The question is how to pass the providers from the root module to nf_cis_benchmark to vpc so that each flow_log module is created in the appropriate aws account.
The error that I get is
Error: Cannot override provider configuration
│
│ on modules/nf_cis_benchmark/vpc.tf line 26, in module "vpc":
│ 26: aws.us-west-1 = aws.us-west-1,
│
│ Provider aws.us-west-1 is configured within the module module.nf_cis_benchmark.module.vpc and cannot be overridden.