Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terragrunt-info does not work with mock outputs #2885

Closed
caspar-ds opened this issue Jan 11, 2024 · 3 comments · Fixed by #2901
Closed

terragrunt-info does not work with mock outputs #2885

caspar-ds opened this issue Jan 11, 2024 · 3 comments · Fixed by #2901
Labels
bug Something isn't working

Comments

@caspar-ds
Copy link

Describe the bug
terragrunt-info fails to work with mock outputs of a dependency

To Reproduce

Module A

# config/module-a/terragrunt.hcl
terraform {
  source = ".//"
}

# config/module-a/main.tf
output "test_var" {
  value = "hello"
} 

Module B

# config/module-b/terragrunt.hcl
terraform {
  source = ".//"
}

dependency "module_a" {
  config_path                             = "../module-a"
  mock_outputs_allowed_terraform_commands = ["init", "plan", "validate"]
  mock_outputs_merge_strategy_with_state  = "shallow"
  mock_outputs = {
    test_mock = "abc"
  }
}

inputs = {
  test_var = dependency.module_a.outputs.test_mock
}

# config/module-b/main.tf
variable "test_var" {
  type = string
}

output "result" {
  value = var.test_var
}

Working:
cd config/module-b && terragrunt plan

INFO[0000] Downloading Terraform configurations from file:///my-home/terragrunt-info-test/config/module-a into /my-home/terraform.d/.terragrunt-cache/AnwNMwh9yg0XKSaMbmsxdNYr1BI/o12cAWD2nsVQ_xmslaEWdI5j6Fs  prefix=[/my-home/terragrunt-info-test/config/module-a] 

Initializing the backend...

Initializing provider plugins...

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.

Changes to Outputs:
  + result = "abc"

You can apply this plan to save these new output values to the Terraform
state, without changing any real infrastructure.

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

Failing:
cd config/module-b && terragrunt terragrunt-info

terragrunt terragrunt-info 

ERRO[0000] /my-home/terragrunt-info-test/config/module-a/terragrunt.hcl is a dependency of /my-home/Developer/oss/terragrunt-info-test/config/module-b/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. 
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 

Expected behavior
terragrunt-info should use the mock outputs when running

Versions

  • Terragrunt version: 0.54.12
  • Terraform version: 1.6
  • Environment details (Ubuntu 20.04, Windows 10, etc.):

Additional context
The same happens with an initialised and applied module where the output is new and has not yet been applied and saved to state. This will result in the outputs object not containing any mock outputs.

@caspar-ds caspar-ds added the bug Something isn't working label Jan 11, 2024
@caspar-ds
Copy link
Author

Is there a method to get the working dir without terragrunt-info?

@denis256
Copy link
Member

denis256 commented Apr 4, 2024

@caspar-ds
Copy link
Author

Thanks @denis256!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants