0.9.2
output "foo" {
value = "bar"
}
After adding an output and running terraform refresh, removing the output and running terraform refresh, there should be no outputs.
After removing the output and refreshing, the output is still cached in the state and queryable.
terraform refreshterraform refreshThis appears to be a regression.
Thanks for this, @sethvargo.
I think this has the same root cause as #12572 and #11716, which is that outputs are only updated when their graph nodes are visited during apply. All of these tickets are various reasons why the apply step of an output wouldn't be run. In this case, it's because the terraform refresh command doesn't intentionally doesn't run the apply walk.
If that's true, then a targeted fix for this would be to make sure the outputs get evaluated during the refresh walk too. The more comprehensive fix would be something like what I suggested in a comment in #11716: update outputs immediately whenever any of their dependencies change, rather than waiting until their graph nodes are visited.
@apparentlymart, I made an attempt at solving the related issue that outputs don't generate errors, but it turned out to be a larger problem than anticipated. I think the solution to that is to promote outputs to be (or act like) an actual resource, where they are graph nodes that we can properly order, _and destroy_, which will in turn solve this issue.
@apparentlymart @jbardin Just curious when you think this will be included into a future release?
There are no firm plans yet, since addressing this family of output-not-updating issues is likely to require a change in approach for outputs. We have had some initial discussion about different alternatives but it will take some iterations to settle on something that works well with the rest of the system while achieving these goals.
@apparentlymart Thanks for the update. If there is some way I can help test any updates please let me know. We rely on outputs heavily for our infrastructure.
As a workaround I am using the following method
Create a template_file with all values that rely on the outputs that aren't getting refreshed properly.
data "template_file" "userdata-green" {
template = "${file("${path.module}/somefile.sh.tpl")}"
vars = {
"ami_id" = "${var.green_ami_id}"
"chef_cookbook" = "${var.green_chef_cookbook}"
"code_build" = "${var.code_build_green}"
}
}
Create a null_resource with local provisioner to echo the rendered template_file on triggered changes
resource "null_resource" "green-vars {
triggers {
template = "${data.template_file.userdata-green.rendered}"
}
provisioner "local-exec" {
command = "echo \"${data.template_file.userdata-green.rendered}\" > test-green.txt"
}
}
Create a targeted plan for the null_resource. Apply the targeted plan. Repeat this step until no changes are found!
terraform plan -out=output-refresh.plan -target=null_resource.green-vars
terraform apply output-refresh.plan
Proceed with your normal targeted plan
This is fixed in master via #16599, and will be in the 0.11.0 release.
This is fixed in master via #16599, and will be in the 0.11.0 release.
I'm running into this in 0.11.7, could it be a different bug? In my base module, I rename an output and all previous names persist when doing terraform refresh and terraform output
@jeffmccune, the outputs are only written during an apply.
It would be nice if terraform refresh could update outputs as well, or at least explain why only apply updates it.
I can confirm this issue still with Terraform v0.11.13
terraform refresh still show the old state.
terraform output show the old state too.
I am not running terraform apply, just terraform plan.
confirmed this is still an issue in 11.14 and 12.0
I switched from using terraform output to custom script that queries terraform state list and terraform state show which is extremely slow, but reliable.
the outputs are only written during an
apply.
@jbardin Is there a reasoning behind it?
(I have run into it with 0.12.0 which led me to this issue.)
the outputs are only written during an
apply.@jbardin Is there a reasoning behind it?
(I have run into it with 0.12.0 which led me to this issue.)
@a13xb Using 0.12.0:
From the looks of it, terraform refresh called with the any variable file (if needed) seems to properly write the outputs. May be worth trying as well.
Note: This seems to work when adding new outputs from existing applied plans.
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.
Most helpful comment
I can confirm this issue still with Terraform v0.11.13
terraform refreshstill show the old state.terraform outputshow the old state too.I am not running
terraform apply, justterraform plan.