[terragrunt] How can you conditionally include a provider in a generate
block?
#205
Answered
by
yorinasub17
yorinasub17
asked this question in
Help
-
I'm aiming to consolidate all providers here, however I have one provider that requires authentication against a remote source to work. This provider has very limited use and I wouldn't want to authenticate against every run. However if I could conditionally include this provider based on the use of certain modules that would be ideal. |
Beta Was this translation helpful? Give feedback.
Answered by
yorinasub17
Feb 16, 2022
Replies: 1 comment
-
You can do this by using string template directives. For example: locals {
# Assuming you have a folder structure like ACCOUNT/REGION/ENV, you can have a
# region.hcl file like ACCOUNT/REGION/region.hcl to dynamically change what gets loaded here.
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}
%{ if local.region_vars.locals.region == "us-west-1" }
provider "aws" {
alias = "us-west-1"
region = "us-west-1"
}
%{ endfor }
EOF
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yorinasub17
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do this by using string template directives. For example: