How to keep variables declarations DRY
Closed this issue · 1 comments
vitorfhc commented
First of all, I would like to thank you for this tool.
Problem
I am having a problem trying to keep the variables.tf
file DRY. Here's my directories structure:
.
├── common.shared.yaml
└── iam
│ ├── role-01
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── terragrunt.hcl
│ │ └── variables.tf
│ └── role-02
│ ├── main.tf
│ ├── outputs.tf
│ ├── terragrunt.hcl
│ └── variables.tf
└ terragrunt.hcl
In my root terragrunt.hcl
:
...
locals {
common_vars_yaml = "common.shared.yaml"
}
inputs = merge(
yamldecode(
file(
find_in_parent_folders(local.common_vars_yaml)
)
)
)
...
Even though I import these inputs
in every terragrunt.hcl
for each service, I still need to repeat all variables declarations.
Example
# common.shared.yaml
obj:
str: value
# variables.tf
variable "obj" {
type = object({
str = string
})
}
The last part above (variables.tf
) is copied and pasted for every service that needs variables present in common.shared.yaml
.
How could I solve it? Are there any patterns or built-in functions?
vitorfhc commented
Just realized I posted in wrong repo