Skip to content

Instantly share code, notes, and snippets.

@hoo29
Last active September 12, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoo29/107d3612166458afc0616169f4c1e55a to your computer and use it in GitHub Desktop.
Save hoo29/107d3612166458afc0616169f4c1e55a to your computer and use it in GitHub Desktop.
Terraform
# These variables are declared as locals here for brevity but could equally be terraform variables, a terraform http data source, output from another module etc.
locals {
deployment_targets = {
# region = aws account id
"eu-west-1" = "00000000000"
"eu-west-2" = "11111111111"
}
module_version = "1.2.3"
}
provider "aws" {
for_each = local.deployment_targets # <- not allowed
alias = "${each.value}${each.value}"
region = each.key
assume_role {
role_arn = "arn:aws:iam::${each.value}:role/Iac"
}
}
module "cool_module" {
for_each = local.deployment_targets
source = "./modules/super_secure_module"
providers = {
aws = "aws.${each.value}${each.value}" # <- not allowed
}
}
module "super_cool_module" {
source = "terraform_registry"
version = local.module_version # <- not allowed
}
module "ultra_cool_module" {
source = "github.com/repo/my_module?ref=${local.module_version}" # <- not allowed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment