Murakami
Murakami

Reputation: 3760

Terragrunt - variables declarations

I have a two directories: in first one I'm keeping modules (basically terraform template configurations) in the second one I'm keeping terragrunt modules implementations. In the second one there is a terragrunt hcl file with inputs inside (one for every particular project). So far I declared variables in modules directory (in variables.tf) but I don't like that as variables change depending on the implementation (project). So keeping all variables (for all projects) in the modules dir seems to be not the best idea.

My question is: how can I declare those variables on the terragrunt (aka implementations) level? Is a generate function way to go?

Upvotes: 1

Views: 766

Answers (1)

GeF
GeF

Reputation: 81

You can use HCL files to store you variables on Terragrunt level. For instance, keep you project level variables in config.hcl:

locals {
    env = "dev"
}

And then load it in your terragrunt.hcl:

locals {
    config = read_terragrunt_config(find_in_parent_folders("config.hcl")).locals
    env = local.config.env
}

inputs = {
    env = local.env
}

Upvotes: 2

Related Questions