Terraform: Outputs are removed from state file after a targeted apply

Created on 21 Feb 2017  ยท  11Comments  ยท  Source: hashicorp/terraform

Terraform Version

$ terraform -v
Terraform v0.8.7

Affected Resource(s)

It affects all outputs that are not touched by the current targets.

Expected Behavior

After a targeted apply the outputs that have not changed should still be there.

This breaks the terraform output command as well as the terraform_remote_state data source.

Actual Behavior

After the apply outputs that have previously existed should still exist in the state file.

# module.foo does not have any outputs but there are other outputs defined for
# the root module
$ terraform apply -target module.foo

$ terraform output
The state file has no outputs defined. Define an output
in your configuration with the `output` directive and re-run
`terraform apply` for it to become available.

Steps to Reproduce

  1. terraform apply -target <any resource>
  2. terraform output

References

This might be related to #10911

bug core

Most helpful comment

+1
I get the same results when I run
terraform output -module=module.foo

This works fine in 0.8.5

All 11 comments

+1
I get the same results when I run
terraform output -module=module.foo

This works fine in 0.8.5

As a workaround, running refresh after your targeted apply will put the outputs back.

I'm also seeing this issue, pretty sure it was working fine in 0.8.5 but on 0.8.8 I get this bug.

@wr0ngway Thanks for posting, the workaround of running terraform refresh works to put the outputs back.

I'm having the same issue with terraform 0.8.7. Running terraform refresh fixes the problem.

Same issue here on 0.9.5. I have been executing a refresh, but this is inconvenient and takes too much time on larger environments. When using -target, it should not overwrite what already exists.

No developer comments?

Same problem
terraform 0.9.5

Same problem!
This is a big issue if you are having multiple developers working, and if you have cross environment dependencies. The outputs being deleted....

Hi everyone! Sorry for the issue here.

I think this is the same issue as was being discussed in #14186, which we fixed in #14378, and in turn released in version 0.9.6. If one of you could give this a try in 0.9.6 or newer and see if the problem still persists, that'd be much appreciated.

There is no issue in 0.9.6 for me
Thanks!

Thanks for testing @agurinov! In that case, I'm going to close this.

As some context on what we did here: in #14378 we added a new capability to the targeting system to allow certain graph node types to be _implicitly_ targeted if anything they depend on is targeted, and then made outputs behave in this way. This means that if an output foo depends on a resource aws_instance.foo, the output will be targeted implicitly if aws_instance.foo is targeted. This then ensures the expected behavior: an output value is updated any time something it depends on is updated, but skipped if nothing it depends on has been targeted.

If anyone still sees problems that seems similar to this, I'd ask that they open a new top-level issue for it with some reproduction details, since the details are likely to be different even if symptoms are similar.

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.

Was this page helpful?
0 / 5 - 0 ratings