-
Hey all! Thanks for the great project! I have this directory structure: .
├── environments
│ ├── common
│ │ └── config.tm.hcl
│ ├── prod
│ │ └── config.tm.hcl
│ └── staging
│ └── config.tm.hcl
├── services
│ ├── backend.tm.hcl
│ ├── config.tm.hcl
│ ├── demo-service
│ │ ├── common
│ │ │ ├── _backend.tf
│ │ │ ├── _k8s_namespace.tf
│ │ │ ├── _providers.tf
│ │ │ ├── _psql_db.tf
│ │ │ ├── _vars.tf
│ │ │ ├── _versions.tf
│ │ │ └── stack.tm.hcl
│ │ ├── config.tm.hcl
│ │ ├── prod
│ │ │ ├── _backend.tf
│ │ │ ├── _k8s_namespace.tf
│ │ │ ├── _providers.tf
│ │ │ ├── _psql_db.tf
│ │ │ ├── _vars.tf
│ │ │ ├── _versions.tf
│ │ │ └── stack.tm.hcl
│ │ └── staging
│ │ ├── _backend.tf
│ │ ├── _k8s_namespace.tf
│ │ ├── _providers.tf
│ │ ├── _psql_db.tf
│ │ ├── _vars.tf
│ │ ├── _versions.tf
│ │ └── stack.tm.hcl
│ ├── modules.tm.hcl
│ ├── providers.tm.hcl
│ ├── vars.tm.hcl
│ └── versions.tm.hcl
└── terramate.tm.hcl
The idea behind this is to have a monorepo that houses the Terraform configuration for microservices. Each service being in A set of common globals for a single environment is found in To have some common set of globals for all environments I utilize the
The issue I'm seeing is that Terramate then ignores the globals I have set in Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi @ottramst, Glad to know you are enjoying Terramate ! Importing globals should not affect any other globals defined on your hierarchy if there are no name clashes, the setup you are describing should just work. For example, if on
And on
On the stack
What could be happening is that if any globals have the same name, then the imported globals will override/shadow the inherited globals. The order of overriding being I hope this helps, if the globals are indeed different and they are just being "lost" then that would be a bug, if you could provide a little more details on the contents of the files maybe we can reproduce the issue (so far the described behavior seems to be working). |
Beta Was this translation helpful? Give feedback.
-
Hi @ottramst On first sight without knowing any details about the contents and information you want to share i would suggest trying if the following would make sense for your desired setup: Instead of having a list of services that run in various environments, why not care about environments running a bunch of services each. It's the reverse of your setup that i would propose:
This allows for several nice features:
I hope this helps a bit. Please let us know if you need follow up details ;) |
Beta Was this translation helpful? Give feedback.
-
Hey guys! First off, thanks for the suggestions! I'll give a bit more background on this. So the first thing - why we implemented a "service-based" set of stacks instead of "env-based"? Next - there's always a static set of configuration for each environment, which doesn't change regardless of the service. For example - Kubernetes provider context is always I understand that there are tradeoffs and gains for both approaches, but in terms of allowing the end user add more services to this structure, the "service-based" approach seems a bit less error-prone and easier. I will also mention that I understand that Terramate is not all-mighty and my desires to implement the structure this way may be a bit utopian. But, let me try to explain what I'm currently observing. Dir/files structure:
However running
|
Beta Was this translation helpful? Give feedback.
-
Hi @ottramst, It seems that on
That define the same global attribute "environment". Terramate implements a similar semantic as Terraform where all files are "merged" and then handled as a single configuration (more details here). Just as would happen with Terraform I realize this is somewhat confusing/non-intuitive because you imported a single file, not a directory, but Terramate by default parses all directories in a project that have any .tm/*.tm.hcl files, that is why the error happens even before doing any importing, when Terramate is just trying to list all available stacks. If the objective of Hope this was helpful, let me know if I got something wrong. |
Beta Was this translation helpful? Give feedback.
Hi @ottramst,
It seems that on
terramate/environments
you have two files:dev.tm.hcl
staging.tm.hcl
That define the same global attribute "environment". Terramate implements a similar semantic as Terraform where all files are "merged" and then handled as a single configuration (more details here). Just as would happen with Terraform
local
block, if you redefine a global you get an error since there is no clear semantic to how to handle this, there is no explicit ordering on HCL/Terramate files, so there is no way for one name to shadow/override the other.I realize this is somewhat confusing/non-intuitive because you imported a single file, not a directory, but Terramate by default pars…