Replies: 1 comment 3 replies
-
Do you generally group together resources that need different providers hierarchically? Is the top-level If so, you could follow a pattern where you specify something like this in your # root.hcl
locals {
providers_hcl_file = find_in_parent_folders("providers.hcl")
contents = local.providers_hcl_file.locals.contents
}
generate "providers" {
path = "providers.tf"
if_exists = "overwrite"
contents = local.contents
} and a # aws/providers.hcl
locals {
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
contents = <<EOF
provider "aws" {
region = "${local.region_vars.locals.aws_region}"
# ... shared config for AWS
}
EOF
}
# databricks/providers.hcl
locals {
contents = <<EOF
provider "databricks" {
alias "mws"
# ... shared config for Databricks
}
EOF
}
If you aren't managing your resources in a hierarchy like that, you could also look to leverage Stacks, and have every unit define it's own EDIT: The example was wrong. Updated. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to set up a Terragrunt stack for Databricks on AWS. The resources are similar to this example but I planned on splitting this module into multiple ones. This means that some of these modules require the
databricks
andaws
providers, whereas others simply need theaws
or other basic providers (e.g.random
).To centralize the provider configuration, I'm following the pattern of having a
root.hcl
that generates the provider and is included in each unit:root.hcl
:some/unit/terragrunt.hcl
:The issue I have with this approach is that this provider file is then unconditionally generated in all units, regardless of whether they actually need the provider or not. And if the Terraform module of a unit does not include the provider in the
required_providers
section inversions.tf
, in the best case it would just download the latest provider (aws), but in the worst case (databricks) it would throw an error, because it defaults tohashicorp/<provider>
, as it's missing thesource = ...
field.I've come across a very similar question where the suggestion was to just use
%{ if ... }
around the provider code to conditionally template it. However, this didn't work for me, as I wanted the condition to be specified in the unit'sterragrunt.hcl
file (ideally somehow passing that down to the includedroot.hcl
file). If I did aread_terragrunt_config("terragrunt.hcl")
in theroot.hcl
I would get a cyclic dependency creating an infinite loop.One other idea I currently have is to put the provider generation for each provider in a separate HCL file and then explicitly include that one, e.g.:
terragrunt.hcl
:Does anyone else have a better idea or has come across the same or a similar problem?
Beta Was this translation helpful? Give feedback.
All reactions