-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
plan -detailed-exitcode returns 2 with external provider even if there is no change #16055
Comments
Hi @sjwl! At present using data "external" "foo" {
program = ["bash", "${path.module}/test.sh"]
query = {
# useless extra argument to create the implicit dependency
dep = "${null_resource.test.id}"
}
}
resource "null_resource" "test" {
}
output "foo" {
value = "${data.external.foo.result["foo"]}"
} Creating that implicit dependency via the This has the unfortunate side-effect of passing a useless extra query argument to your external program, which it must then ignore. With all of that said, this is of course not intuitive and what you've encountered here is the intersection of a few different things:
The reason for Terraform exiting with code 2 here is a subtle one: since the result of a data source refresh is kept in the state, a data source read is actually an action, and so it does need to be applied in order to actually take effect in the state. Most of the time this subtlety makes no difference, but in cases like your example -- where the data source result is used in an output -- the change to the output is sometimes actually the main side-effect we're looking for. For example, if the result is being consumed elsewhere using So what Terraform is saying here is: you need to run The problem arises because Terraform currently treats data source updates in an imprecise way... it can't distinguish cases where refreshing the data source produces the same result, and the Resolving both #11806 and #15419 would have the side-effect of curing the weird behavior you saw here, and I don't think there's any immediate action we can take here to address this specific issue... adding a special case for this scenario would break the situation where we do need to apply a data source update. I hope for now the above workaround gives you a way past this bug until we're able to address these other two deeper issues. Sorry again for the weirdness here. |
thanks @apparentlymart your workaround is working for me! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
0.10.4
Terraform Configuration Files
(test.sh)
Expected Behavior
terraform plan -detailed-exitcode
should return 0 in this case.Actual Behavior
it's returning 2
Steps to Reproduce
terraform init
terraform apply
terraform plan -detailed-exitcode
echo $?
Notes
If
depends_on
is removed from the external provider stanza, then the exit code becomes 0. However, that is not a viable workaround whendepends_on
is actually necessary.The text was updated successfully, but these errors were encountered: