-
-
Notifications
You must be signed in to change notification settings - Fork 997
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
errors block doesn't seem to be used for output lookup #3661
Comments
Hey @MichaelFoleyFZ , I don't have a Terraform Cloud account, so I can't reproduce your issue, exactly. In a setup like this: $ fd -tf -x bash -c 'echo "# {}" && cat {} && echo'
# ./unit2/terragrunt.hcl
dependency "unit1" {
config_path = "../unit1"
mock_outputs_allowed_terraform_commands = ["plan", "validate"]
mock_outputs = {
data = "def456"
}
}
inputs = {
unit_a_data = dependency.unit1.outputs.data
}
# ./unit1/main.tf
resource "terraform_data" "data" {
input = "abc123"
}
output "data" {
value = terraform_data.data.output
}
# ./unit1/terragrunt.hcl
# ./unit2/main.tf
variable "unit_a_data" {
type = string
}
resource "terraform_data" "unit_a_data" {
input = var.unit_a_data
}
output "data" {
value = terraform_data.unit_a_data.output
}
I'm able to do a $ terragrunt output -json
10:49:14.346 STDOUT tofu: Initializing the backend...
10:49:14.347 STDOUT tofu: Initializing provider plugins...
10:49:14.347 STDOUT tofu: - terraform.io/builtin/terraform is built in to OpenTofu
10:49:14.348 STDOUT tofu: OpenTofu has been successfully initialized!
10:49:14.348 STDOUT tofu:
10:49:14.348 STDOUT tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
10:49:14.348 STDOUT tofu: any changes that are required for your infrastructure. All OpenTofu commands
10:49:14.348 STDOUT tofu: should now work.
10:49:14.348 STDOUT tofu: If you ever set or change modules or backend configuration for OpenTofu,
10:49:14.348 STDOUT tofu: rerun this command to reinitialize your working directory. If you forget, other
10:49:14.348 STDOUT tofu: commands will detect it and remind you to do so if necessary.
{}
You can see there that an empty JSON object is returned even though I haven't applied yet. Terragrunt uses that to determine that it should be mocking inputs from another unit. Note that in this scenario, Terragrunt hasn't encountered any error running What do you see when you try to run |
Looks like terraform cloud fails to return an empty object and errors instead
Terraform cloud seems to only return outputs if you have run at least one apply against the cloud., other wise it fails on the output return |
To close the loop on this, I'm not sure the Other providers don't encounter this issue, and I'm inclined to say it's a bug in the Terraform cloud remote backend, as it breaks the pattern established by other remote backends. I wouldn't want dependencies to treat empty stdout with stderr content as the same thing as an empty json object, as that would indicate a problem with the backend for everything else. For now, I think your options are to:
|
Yeah totally fair call, it felt like a bit of a cludge in using errors for something that the user has no control over with the outputs lookup. |
Describe the bug
We are currently using terraform cloud to manage state storage and when we need to setup new set of units with dependencies we get an error when the outputs are looked up
This makes sense since we don't have terraform cloud workspace state created yet, so I added mock outputs in to our dependency check to hopefully get around it
But terragrunt still fails since its running
terraform output -json
before using the mock outputs.skip_outputs
was an option but creates issues with when it should be enabled or disabled (i.e. when the terraform workspace exists it shouldn't skip )So I tried the new errors block.
But it looks like the errors block doesn't get evaluated when running the output look ups. Since it still fails and doesn't produce anything to say that the error has been ignored.
Steps To Reproduce
terragrunt.hcl
unit1/terragrunt.hcl
unit1/main.tf
unit2/terragrunt.hcl
unit2/main.tf
Then at the root of this workspace run
Expected behavior
When running the plan step the outputs are attempted to be looked up and if the terraform workspace doesn't have outputs the mock outputs are returned because the error
Error: could not read state version outputs: resource not found
was ignored in the errors blockNice to haves
Versions
Additional context
This might quite be the right approach as a bug, but the errors block feels like the right spot for it to be handled.
The text was updated successfully, but these errors were encountered: