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.09k stars 981 forks source link

Dependencies output lookup does not use download_dir path #3417

Open 1azunna opened 1 month ago

1azunna commented 1 month ago

I tested the 0.67.6 version and version 0.58.10 and i'm getting the same behaviour.

I am trying to use a dependency in my terragrunt resource but i keep getting this error even though the dependent resource has been applied successfully.

level=error msg=/<path>/network/terragrunt.hcl is a dependency of /<path>/database/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.

I've confirmed that the module has outputs so i'm not sure what's the problem here.

Here is my root terragrunt.hcl

....
## Centralise plugin caching
terraform {
  before_hook "before_cache" {
    commands     = [get_terraform_command()]
    execute      = ["mkdir", "-p", abspath("${get_repo_root()}/.terraform/plugins")]
  }

  before_hook "workspace" {
    commands = ["plan", "state", "apply", "destroy", "refresh", "output"]
    execute  = [abspath("${get_repo_root()}/scripts/terragrunt-hook-workspace.sh"), local.workspace]
  }

  after_hook "destroy" {
    commands = ["destroy"]
    execute  = [abspath("${get_repo_root()}/scripts/terragrunt-hook-destroy.sh"), local.workspace]
  }

  extra_arguments "terragrunt_plugins" {
    commands = [get_terraform_command()]
    env_vars = {
      TF_PLUGIN_CACHE_DIR = abspath("${get_repo_root()}/.terraform/plugins")
    }
  }
}
download_dir = abspath("${get_repo_root()}/.terragrunt-cache")

Then i have a resource terragrunt.hcl with this setup

dependency "vpc" {
  config_path = "../network"
  mock_outputs = {
    network_self_link = "https://www.googleapis.com/compute/v1/projects/project-name/global/networks/vpc-name"
  }

  mock_outputs_allowed_terraform_commands = ["plan"]
  mock_outputs_merge_strategy_with_state = "shallow"
}

The folder structure is as follows

root
     |_ folder
        |_ subfolder
           |_ resource_1 
           |        terragrunt.hcl
           |_ resource_2
                   terragrunt.hcl
   terragrunt.hcl

I have attached both log files below: v0.58.10.log v0.67.6.log

Originally posted by @1azunna in https://github.com/gruntwork-io/terragrunt/issues/3156#issuecomment-2354127019

yhakbar commented 1 month ago

Hey @1azunna ,

I'm not sure either, but I will say that provider plugin caching is a pretty nuanced subject, and you might be using a solution that's a lot more complicated than it needs to be. Have you tried using the built-in Provider Cache Server? That's the most reliable (and well tested) way to re-use provider plugins across terragrunt.hcl files.