Adding child unit tags to generated block defined in root unit #3720
-
Hi 👋
I'm trying to define additional default provider tags in the each of my child units.
I'd imagine it would look something like this but I haven't gotten it to work. # root.hcl
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
region = "ap-southeast-2"
profile = "${local.profile}"
default_tags {
tags = local.default_tags -- I want this to be tags defined in the VPC unit.
}
}
EOF
} # vpc/terragrunt.hcl
include {
path = find_in_parent_folders("root.hcl")
}
locals {
default_tags = {
Project = "networking"
}
}
terraform {}
inputs {} The local.profile is from the root unit and the local.default_tags is from the final terraform generated by terragrunt. I don't know how to "inject" locals from the child VPC unit into the parent's block. I've gotten this to work but it isn't as nice# root.hcl
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
region = "ap-southeast-2"
profile = "${local.profile}"
default_tags {
tags = local.default_tags -- I want this to be tags defined in the VPC unit.
}
}
EOF
} # vpc/terragrunt.hcl
include {
path = find_in_parent_folders("root.hcl")
}
generate "tags" {
path = "tags.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
locals {
default_tags = {
Career = "networking"
}
}
EOF
}
terraform {}
inputs {} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You generally don't "inject" anything into a parent block. Units include other configurations, which are like template partials. You just merge them into the configurations where they're being included. The pattern that we recommend when users want that partial to be dynamic depending on the context of where it's being included is to use You can learn more about that here. |
Beta Was this translation helpful? Give feedback.
You generally don't "inject" anything into a parent block. Units include other configurations, which are like template partials. You just merge them into the configurations where they're being included.
The pattern that we recommend when users want that partial to be dynamic depending on the context of where it's being included is to use
read_terragrunt_config
to have the included partial read information after it's being included.You can learn more about that here.