-
I am working on modularising a monolithic structured terraform environment. 1 provider.tf is included per module. The modules are uploaded into a private terraform cloud registry. The terragrunt.hcl that uses the module references it like below:
Structure:
The module linux_user has a provider.tf which requires 2 additional providers (publically available). So dependency looks like this:
The problem is that I use a root.hcl that creates the provider.tf which is especially needed for localstack integration and keeping my code dry.
What is the best practices for creating modules and specifying required providers? Shouldn't this be included in the module? Also note, that I don't want to put all of the providers in the root.hcl because some of the providers have specific requirements neuspaces/system where the provider needs additional configuration. Shouldn't the module dictate the versions of providers needed? Terragrunt should just dictate the version of the root module and not its dependencies? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I found a solution:
This way, all module versions & provider versions are in the same place. stub block in root.hclThis section shows an example of auto-generating the stub block from per folder configuration. You can add additional %{if VARIABLE} blocks as needed. locals {
stubs = read_terragrunt_config("stubs.hcl")
}
generate "stub_block" {
path = "stub.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
%{if local.stubs.inputs.use_system_stub}
provider "system" {
sudo = false
ssh {
host = localhost
port = 22
user = user
private_key = empty
}
}
%{endif}
EOF
} example of stubs.hclNote, each terragrunt.hcl folder should also have a stub.hcl. inputs = {
use_system_stub = true
} |
Beta Was this translation helpful? Give feedback.
-
I have updated the answer thread. |
Beta Was this translation helpful? Give feedback.
I found a solution:
This way, all module versions & provider versions are in the same place.
It will be the responsiblity of the terraform_control repository for managing the versions of everything (which is similar to other orchestration tools like Puppetfile for Puppet).
stub block in root.hcl
This section shows an example of auto-generating the stub block from per folder …