Terraform v0.20.2
I'm following along with the documentation (https://github.com/gruntwork-io/terragrunt#unapplied-dependency-and-mock-outputs), but seem to keep running into the error:
Unsupported attribute; This object does not have an attribute named "platform".
I have a pretty straightforward configuration, using mock_outputs, mock_outputs_allowed_terraform_commands, and skip_outputs:
# hosting/terragrunt.hcl
terraform {
source = "${get_terragrunt_dir()}/../../../core/hosting/module"
}
dependency "platform" {
config_path = "../platform"
mock_outputs = {
api_gateway_name = "test_api_gateway_name"
}
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
skip_outputs = true
}
inputs = {
api_gateway_name = dependency.platform.outputs.platform
}
Project structure:
root
โโโ hosting
โ โโโ terragrunt.hcl
โโโ platform
โ โโโ terragrunt.hcl
โโโ terragrunt.hcl
Is there something I'm missing?
Thanks
Hi can you share the full log, starting with the command you are running? That context helps a lot for debugging this. Thanks!
Oh wait, taking a deeper look at the config, I think I spot the problem:
In the inputs, you are referencing:
dependency.platform.outputs.platform
but in your definition of mock_outputs, you don't have a key for platform. Should this actually be: dependency.platform.outputs.api_gateway_name?
Thanks for the response @yorinasub17. You're absolutely right, I misread the documentation - I read it as mock_outputs keys are to match the keys of the inputs block. Thanks again for catching that.
@yorinasub17 It looks like even after changing the key, the issue persists:
Unsupported attribute; This object does not have an attribute named "outputs"
Here's the configuration:
# hosting/terragrunt.hcl
terraform {
source = "${get_terragrunt_dir()}/../../../core/hosting/module"
}
dependency "platform" {
config_path = "../platform"
mock_outputs = {
api_gateway_name = "test_api_gateway_name"
}
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
skip_outputs = true
}
inputs = {
api_gateway_name = dependency.platform.outputs.api_gateway_name
}
@clarklai what Terragrunt command are you using ? Can you please share the full log as @yorinasub17 suggested ?
I resolved the issue. It was because I had skip_outputs = true in the dependency definition.
That sounds like a bug, since we introduced the behavior to return the mock_outputs when skip_outputs = true in v0.19.29.
Would you be ok with sharing the logs still so we can investigate this further and make sure there isn't an issue in terragrunt itself?
From what I understood from the code, you get this error only when these 2 are true :
skip_outputs is true => you don't want to pull in states. This can make sense only with the validateIn short, if you don't want to read states and don't provide allowed commands, you can't have dependency outputs.
@yorinasub17 @clarklai can we re-open this issue until we make this clair ?
I've made some updates to the configuration since my last post, however the issue returns when adding back skip_outputs to the configuration.
[terragrunt] 2019/10/16 20:41:25 configstack.MultiError Encountered the following errors:
Cannot process module Module /Users/clark/example/deploy/dev/hosting (excluded: false, dependencies: [/Users/clark/example/deploy/dev/platform, /Users/clark/example/deploy/dev/email]) because one of its dependencies, Module /Users/clark/example/framewo
rk/deploy/dev/email (excluded: false, dependencies: [/Users/clark/example/deploy/dev/platform]), finished with an error: /Users/clark/example/deploy/dev/email/terragrunt.hcl:23,41-49: Unsupported attribute; This object does not have an attribute named "outputs"., and 2 other diagnostic(s)
/Users/clark/example/deploy/dev/email/terragrunt.hcl:23,41-49: Unsupported attribute; This object does not have an attribute named "outputs"., and 2 other diagnostic(s)
@clarklai Can you share your /Users/clark/example/deploy/dev/email/terragrunt.hcl configuration ?
@clarklai any news ? Do you still have this issue ?
@barryib Here's the configuration for email/terragrunt.hcl:
terraform {
source = "${get_terragrunt_dir()}/../../../core/email/module"
}
include {
path = find_in_parent_folders()
}
dependency "platform" {
config_path = "../platform"
mock_outputs = {
artifacts_bucket = "mock_artifacts_bucket_name"
kms_key_id = "mock_kms_key_id"
sns_dlq_name = "mock_sns_dlq_name"
}
mock_outputs_allowed_terraform_commands = ["validate"]
skip_outputs = true
}
inputs = {
artifacts_bucket = dependency.platform.outputs.artifacts_bucket
kms_key_id = dependency.platform.outputs.kms_key_id
sns_dlq_name = dependency.platform.outputs.sns_dlq_name
root_dir = "${get_parent_terragrunt_dir()}/../.."
}
Ah the issue is in this line:
mock_outputs_allowed_terraform_commands = ["validate"]
You are basically telling terragrunt that it can only use the mock_outputs if it is running terraform validate, but in the logs you were running terraform plan, so it doesn't read the mock_outputs.
You can resolve that particular error by adding plan to the list.
You can resolve that particular error by adding
planto the list.
@yorinasub17 Yes, adding plan does remove the error.
However, does this mean that future terraform plan will continue to use the mock_outputs after terraform apply has been ran at least once?
If you have skip_outputs = true, then yes. However, if you remove that line, then it will only use the mock_outputs when there are no outputs upstream.
Going to close this now given that this is intended behavior.