gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.07k stars 980 forks source link

Terrragrunt run-all init does not work if a dependency backend is uninitialized #2258

Open x-Xymos opened 2 years ago

x-Xymos commented 2 years ago

I have the following project structure:

All services depends on some outputs from the k8s component, when I try to run terragrunt run-all init inside of environments/dev/local and none of the modules or their backends have been initialized, the stack groups are not shown I get an error

root@master:/tmp/environments/local/dev# terragrunt run-all init
ERRO[0006] Module /tmp/environments/local/dev/service1 specifies /tmp/environments/local/dev/service1/../k8s/ as a dependency, but that dependency was not one of the ones found while scanning subfolders: [/tmp/environments/local/dev/service1/terragrunt.hcl
ERRO[0006] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 

I can work around this by: cd into k8s folder, run terragrunt init

root@master:/tmp/environments/local/dev/k8s# terragrunt init

Initializing the backend...

Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Finding latest version of hashicorp/azurerm...
- Installing hashicorp/local v2.2.3...
- Installed hashicorp/local v2.2.3 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.20.0...
- Installed hashicorp/azurerm v3.20.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Group 2

This is not ideal as I can't initialize everything with a single command and I have to implement custom functionality into my script to work around this.

sergiojoker11 commented 1 year ago

Any light on this issue? I am coming across the very same thing. One might think it is looking for exact path matches, however, even if you use absolute paths it still displays the same error.

ERRO[0008] Module /home/sergiojoker11/github-repos/terragrunt/environments/flexys/pentest/aiven_keystores specifies /home/sergiojoker11/github-repos/terragrunt/environments/flexys/pentest/project/ as a dependency, but that dependency was not one of the ones found while scanning subfolders: [
...omitted sublist...
 /home/sergiojoker11/github-repos/terragrunt/environments/flexys/pentest/project/terragrunt.hcl 
]
tpokki commented 1 year ago

I came across with this same issue, and noticed that as a workaround I could just create some dummy .tf file in the dependency project.

touch environments/local/dev/k8s/something.tf

And the terragrunt run-all init should work.

michal-maslaniec-tf commented 9 months ago

I had the same issue: Module $module_name specifies $deps_path as a dependency, but that dependency was not one of the ones found while scanning subfolders:

after mocking output and adding .tf file to module folder problem was solved, but i think it should be fixed.