terragrunt
                                
                                 terragrunt copied to clipboard
                                
                                    terragrunt copied to clipboard
                            
                            
                            
                        Terragrunt Init fails if dependencies aren't initialized
I have a terragrunt environment (in a github repo) with multiple independent states where dependencies are being passed from one state to another. Terraform and Terragrunt are stored in seperate directories in the same repository. Relative paths are used to link everything. Directory structure looks like this:
- terragrunt
- storage
- foundation
- aks
 
- terraform
- storage
- foundation
- aks
 
This is what my terragrunt file looks like for aks:
terraform {
  source = "../../terraform/aks"
}
dependency "foundation" {
  config_path = "../foundation"
}
dependency "storage" {
  config_path = "../storage"
}
inputs = {
  <list of variables>
}
As you can see it's fetching the Terraform from the local directory structure as well as the dependencies.
Each of those dependencies has an output.tf that's exporting data into the terraform state.
Whenever I try to run the AKS terragrunt with terragrunt init, it fails with:
$ terragrunt init
level=warning msg=No double-slash (//) found in source URL /home/runner/work/ops-core-azure-owner/ops-core-azure-owner/terraform/storage. Relative paths in downloaded Terraform code may not work. prefix=[/home/runner/work/ops-core-azure-owner/ops-core-azure-owner/terragrunt/storage] 
time=2022-08-17T19:42:46Z level=warning msg=No double-slash (//) found in source URL /home/runner/work/ops-core-azure-owner/ops-core-azure-owner/terraform/foundation. Relative paths in downloaded Terraform code may not work. prefix=[/home/runner/work/ops-core-azure-owner/ops-core-azure-owner/terragrunt/foundation] 
╷
│ Error: Backend initialization required, please run "terraform init"
│ 
│ Reason: Initial configuration of the requested backend "azurerm"
│ 
│ The "backend" is the interface that Terraform uses to store state,
│ perform operations, etc. If this message is showing up, it means that the
│ Terraform configuration you're using is using a custom configuration for
│ the Terraform backend.
│ 
│ Changes to backend configurations require reinitialization. This allows
│ Terraform to set up the new configuration, copy existing state, etc. Please
│ run
│ "terraform init" with either the "-reconfigure" or "-migrate-state" flags
│ to
│ use the current configuration.
│ 
│ If the change reason above is incorrect, please verify your configuration
│ hasn't changed and try again. At this point, no changes to your existing
│ configuration or state have been made.
╵
╷
│ Error: Backend initialization required, please run "terraform init"
│ 
│ Reason: Initial configuration of the requested backend "azurerm"
│ 
│ The "backend" is the interface that Terraform uses to store state,
│ perform operations, etc. If this message is showing up, it means that the
│ Terraform configuration you're using is using a custom configuration for
│ the Terraform backend.
│ 
│ Changes to backend configurations require reinitialization. This allows
│ Terraform to set up the new configuration, copy existing state, etc. Please
│ run
│ "terraform init" with either the "-reconfigure" or "-migrate-state" flags
│ to
│ use the current configuration.
│ 
│ If the change reason above is incorrect, please verify your configuration
│ hasn't changed and try again. At this point, no changes to your existing
│ configuration or state have been made.
It's complaining of no init being run, twice, when I'm trying to init. I concluded that what's actually happening is its demanding to init those two dependencies - foundation and storage. Sure enough, if I go up to those terragrunts and run terragrunt init on those two folders separately, boom, the AKS one works.
The problem is I'm now trying to run these on a GitHub actions workflow, where I'm pulling a fresh copy of the file structure each time and I don't have a past history of running terragrunt init on each and every folder.
How do I get around this problem and prevent terragrunt from demanding to init every single dependency?
Have you tried running it with --include-external-dependencies?
Btw which versions of terragrunt and terraform are you using?
Hi,
was considered to run terragrunt run-all init ?
You need to add mock_outputs to all your dependency definitions.
Folks that is a really annoying problem, is there a way of making this work? I've tried --include-external-dependencies, and that didn't help (same output)
run-all init worked! Wondering if that's the best way though, as it initialized everything (even non dependencies)