Skip to main content
Knowledge Base

Help to create structure

Answer

Hi Community, I'm looking for a way to manage multiple servers (each with the same application) with a "terragrunt run-all plan/apply". I've written my own terraform provider which is already working quite well. At the moment I'm stuck with the conception of the path structures and the automation part :) Here the idea: . ├── instance │ ├── common_vars.hcl │ ├── dev │ │ ├── serverA │ │ │ └── terragrunt.hcl │ │ ├── serverB │ │ │ └── terragrunt.hcl │ │ ├── serverC │ │ │ └── terragrunt.hcl │ ├── prod │ │ ├── serverX │ │ │ └── terragrunt.hcl │ │ ├── serverY │ │ │ └── terragrunt.hcl │ │ ├── serverZ │ │ │ └── terragrunt.hcl ├── main.tf └── terragrunt.hcl I was hoping I could define in the main.tf the provider and the required resources. In the common_vars.hcl I was thinking to define default values for the resources. In the terragrung.hcl in the subdirectories I'd like to define variables in case I want to override any from the common_vars. Can you please advise me if this expectation is doable with the way I'm approaching ? Or do I have to set it up differently ? --- <ins datetime="2022-10-14T08:28:34Z"> <p><a href="https://support.gruntwork.io/hc/requests/109371">Tracked in ticket #109371</a></p> </ins>

Hi, to reduce duplications, `terraform` block and default inputs can be extracted in HCL file in the root directory: ``` # root.hcl # common terraform module terraform { source = "${get_terragrunt_dir()}/../module" } # default input inputs = { file = "${get_terragrunt_dir()}/file.txt" } # server1/terragrunt.hcl include "root" { path = find_in_parent_folders("root.hcl") } inputs = { content = "server1" } # server2/terragrunt.hcl include "root" { path = find_in_parent_folders("root.hcl") } inputs = { content = "server2" } ``` Created simplified example in: https://github.com/denis256/terragrunt-tests/tree/master/common-module