terramate-io / terramate

Terramate CLI is an open-source Infrastructure as Code (IaC) Orchestration and Code Generation tool for Terraform, OpenTofu and Terragrunt.
https://terramate.io
Mozilla Public License 2.0
3.12k stars 85 forks source link

[BUG] root config found outside root dir #1768

Closed damienleger closed 1 week ago

damienleger commented 1 week ago

Describe the bug I have a local copy of git repo in: /home/dleger/git/devsecops I put my terramate code in subdirectory: /home/dleger/git/devsecops/terramate

/home/dleger/git/devsecops/terramate has the following filetree (depth=1)

drwxrwxr-x   - dleger dleger 21 juin  10:22 .
drwxrwxr-x   - dleger dleger 21 juin  07:44 ├── modules
drwxrwxr-x   - dleger dleger 21 juin  08:44 ├── stacks
.rw-rw-r-- 498 dleger dleger 21 juin  09:22 ├── backend.tm.hcl
.rw-rw-r-- 460 dleger dleger 21 juin  09:05 ├── config.tm.hcl
.rw-rw-r-- 974 dleger dleger 21 juin  10:22 └── terramate.tm.hcl

When I run terramate run tofu plan in /home/dleger/git/devsecops/terramate I have the following message:

2024-06-21T10:06:31Z WRN ignoring root config error="root config found outside root dir" projectRoot=/home/dleger/git/devsecops rootConfig=/home/dleger/git/devsecops/terramate
2024-06-21T10:06:31Z WRN error="/home/dleger/git/devsecops/terramate/terramate.tm.hcl:2,3-19: terramate schema error: attribute terramate.required_version can only be declared at the project root directory" action=TerramateParser.checkConfigSanity()
2024-06-21T10:06:31Z WRN error="/home/dleger/git/devsecops/terramate/terramate.tm.hcl:5,5-23: terramate schema error: attribute terramate.config.disable_safeguards can only be declared at the project root directory" action=TerramateParser.checkConfigSanity()
2024-06-21T10:06:31Z WRN error="/home/dleger/git/devsecops/terramate/terramate.tm.hcl:33,5-16: terramate schema error: attribute terramate.config.experiments can only be declared at the project root directory" action=TerramateParser.checkConfigSanity()
Error: repository has untracked files

How can I make /home/dleger/git/devsecops/terramate project&root dir and make those errors disappear? I tried -C/-B flag without success.

To Reproduce

Mimic the file tree above

Expected behavior

A flag to configure project&root dir

Log Output

On describe the bug section

Environment (please complete the following information): Ubuntu Server 24.04, terramate 0.9.0

Additional context

n/a

rexprimer commented 1 week ago

Try moving the terramate.tm.hcl file from /home/dleger/git/devsecops/terramate to the root directory, /home/dleger/git/devsecops.

If you recently added or modified files in your project, you'll need to track them with Git using git add before committing changes. However, this warning shouldn't prevent Terramate from functioning unless the untracked files are directly related to its configuration.

damienleger commented 1 week ago

Thanks @rexprimer. I've did that during my tests and it's working (the terramate.tm.hcl is loaded), but that's look like a workaround and not a real solution for what I've tried to achieve: having all the terramate configuration in a subdirectory.

As for the Git tracking error, I've deactivated the check through disable_safeguards so this part is good.

i4ki commented 1 week ago

Hi @damienleger

At the moment we require that some terramate root config to be at the repository root but this won't be the case in the future. We plan to implement a "projects" feature, where multiple terramate projects can be defined in the same repo, similarly how you did by having a terramate block with root config in it.

We are tracking this feature in this ticket: https://github.com/terramate-io/terramate/issues/466

So I'm gonna close this as duplicate. Please reopen if you believe this is not the case and more discussion is needed here!