[terragrunt] How can you conditionally include a provider in a generate
block?
#205
-
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.
Replies: 2 comments
-
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.
-
I had a provider ( locals {
module_name = get_terragrunt_dir()
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "google" {
project = "..."
region = "..."
}
%{if endswith(local.module_name, "helm")}
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
%{endif}
EOF
} |
Beta Was this translation helpful? Give feedback.
You can do this by using string template directives. For example: