Backend local outputs not found

I am working on a prototype at work for using Terraform/Terragrunt with Azure. As I am still testing stuff, I am just using the local backend for my deployments.

Everything works as I want so far. However I am running into my first big hurdle that has me stupefied a bit.

Layout at the moment:

development/
  bastion/
    terragrunt.hcl
  infrastructure/
    terragrunt.hcl
  environment.tfvars
modules/
  bastion/
    main.tf
    variables.tf
  infrastructure/
    main.tf
    output.tf
    variables.tf
common.tfvars
terragrunt.hcl

The top-level terragrunt.hcl has:

terraform {
  extra_arguments "common_vars" {
    commands = get_terraform_commands_that_need_vars()

    arguments = [
      "-var-file=${get_terragrunt_dir()}/../../common.tfvars",
      "-var-file=${get_terragrunt_dir()}/../environment.tfvars"
    ]
  }
}

remote_state {
  backend = "local"
  config = {
    path = "${path_relative_to_include()}/terraform.tfstate"
  }
}

I use common.tfvars and environment.tfvars to pass along some required variables for my future DTAP setup, region, and so on.

I have a main infrastructure stack/module. From this I output a bunch of things via outputs.tf inside the module. Within one of my other stacks I add a dependency on this infrastructure stack via the terragrunt.hcl of the former with:

include {
  path = find_in_parent_folders()
}

dependency "infrastructure" {
  config_path = "../infrastructure"

  mock_outputs = {
    management_subnet = "some-id"
  }
  mock_outputs_allowed_terraform_commands = ["validate"]
}

inputs = {
  management_subnet = dependency.infrastructure.outputs.management_subnet
}

A terragrunt validate succeeds. Deployment of the infrastructure stack creates my outputs, including the one mentioned above. However, when I want to use the output in my dependent stack I get the message that it did no detect any outputs: /work/development/infrastructure/terragrunt.hcl is a dependency of /work/infrastructure/development/bastion/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 think this has to do because Terragrunt is evaluating the tfstate of infrastructure in its local .terragrunt-cache hierarchy (of the bastion subdirectory). That file has, indeed, no outputs. The file in infrastructure has outputs defined. Can I easily make this work or will I need to mess around with terraform_remote_state? Any guidance welcome.

Hello!

Thanks for your inquiry. Can you share the log output of running terragrunt plan in the bastion directory? If the output contains sensitive data, feel free to encrypt the file using keybase (my username is yorigrunt).

Best regards,
Yori

Hi @yoriy,

thank you for looking into this.

Shell output with TF_LOG=DEBUG:

% tg plan
[terragrunt] 2019/09/16 17:12:50 Reading Terragrunt config file at /work/development/bastion/terragrunt.hcl
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Reading Terragrunt config file at /work/development/infrastructure/terragrunt.hcl
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Running command: terraform --version
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Downloading Terraform configurations from file:///work/modules into /work/development/bastion/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Copying files from /work/development/infrastructure into /work/development/bastion/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw/infrastructure
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Setting working directory to /work/development/bastion/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw/infrastructure
[terragrunt] [/work/development/infrastructure] 2019/09/16 17:12:50 Running command: terraform output -json
2019/09/16 17:12:50 [INFO] Terraform version: 0.12.8
2019/09/16 17:12:50 [INFO] Go runtime version: go1.13
2019/09/16 17:12:50 [INFO] CLI args: []string{"/usr/local/bin/terraform", "output", "-json"}
2019/09/16 17:12:50 [DEBUG] Attempting to open CLI config file: /Users/asmodai/.terraformrc
2019/09/16 17:12:50 Loading CLI configuration from /Users/asmodai/.terraformrc
2019/09/16 17:12:50 [INFO] CLI command args: []string{"output", "-json"}
2019/09/16 17:12:50 [DEBUG] checking for provider in "."
2019/09/16 17:12:50 [DEBUG] checking for provider in "/usr/local/bin"
2019/09/16 17:12:50 [DEBUG] checking for provider in ".terraform/plugins/darwin_amd64"
2019/09/16 17:12:50 [DEBUG] found provider "terraform-provider-azurerm_v1.33.0_x4"
2019/09/16 17:12:50 [DEBUG] found valid plugin: "azurerm", "1.33.0", "/work/development/bastion/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw/infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-azurerm_v1.33.0_x4"
2019/09/16 17:12:50 [DEBUG] checking for provisioner in "."
2019/09/16 17:12:50 [DEBUG] checking for provisioner in "/usr/local/bin"
2019/09/16 17:12:50 [DEBUG] checking for provisioner in ".terraform/plugins/darwin_amd64"
[terragrunt] 2019/09/16 17:12:50 /work/development/infrastructure/terragrunt.hcl is a dependency of /work/development/bastion/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.
[terragrunt] 2019/09/16 17:12:50 Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Let me know if you wanted to see something else than what I provided.

Thanks for that output. Can you also share which version of terragrunt you are currently using? The output of terragrunt --version.

Thanks,
Yori

Sorry, should’ve added that from the start.

% tg --version
terragrunt version v0.19.24

Thanks for all that information. I have identified the bug and issued a PR with the fix: https://github.com/gruntwork-io/terragrunt/pull/866

You can track that to know when it is merged and released and it should fix the bug you are running into.

Best regards,
Yori

Thanks for both confirming and fixing it, @yoriy. I can compile and test it tomorrow when I am back in the office to confirm it working. :slight_smile:

@yoriy Good news, it does indeed work:

[terragrunt] 2019/09/17 09:57:52 Reading Terragrunt config file at /work/development/bastion/terragrunt.hcl
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Reading Terragrunt config file at /work/development/infrastructure/terragrunt.hcl
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Running command: terraform --version
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Downloading Terraform configurations from file:///work/modules into /work/development/infrastructure/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Copying files from /work/development/infrastructure into /work/development/infrastructure/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw/infrastructure
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Setting working directory to /work/development/infrastructure/.terragrunt-cache/j3-0zQObaar152V03ctL7vG5cSg/iIMDOkaYW_0NLtpWwVoecQk8quw/infrastructure
[terragrunt] [/work/development/infrastructure] 2019/09/17 09:57:52 Running command: terraform output -json
[terragrunt] [/work/development/bastion] 2019/09/17 09:57:52 Running command: terraform --version
[terragrunt] 2019/09/17 09:57:52 Downloading Terraform configurations from file:///work/modules into /work/development/bastion/.terragrunt-cache/T47ub617U7go6ilhG-Bwtnwzyxo/iIMDOkaYW_0NLtpWwVoecQk8quw
[terragrunt] 2019/09/17 09:57:52 Copying files from /work/development/bastion into /work/development/bastion/.terragrunt-cache/T47ub617U7go6ilhG-Bwtnwzyxo/iIMDOkaYW_0NLtpWwVoecQk8quw/bastion
[terragrunt] 2019/09/17 09:57:52 Setting working directory to /work/development/bastion/.terragrunt-cache/T47ub617U7go6ilhG-Bwtnwzyxo/iIMDOkaYW_0NLtpWwVoecQk8quw/bastion
[terragrunt] 2019/09/17 09:57:52 Running command: terraform plan -var-file=/work/development/bastion/../../common.tfvars -var-file=/work/development/bastion/../environment.tfvars
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.

Thanks for checking! I merged and released as v0.19.25: https://github.com/gruntwork-io/terragrunt/releases/tag/v0.19.25. The binaries should show up in about 20 minutes.