Skip to content
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

Mechanism for updating output variables #17280

Closed
ezyang opened this issue Feb 5, 2018 · 8 comments
Closed

Mechanism for updating output variables #17280

ezyang opened this issue Feb 5, 2018 · 8 comments

Comments

@ezyang
Copy link

ezyang commented Feb 5, 2018

Terraform Version

Terraform v0.11.3
+ provider.archive v1.0.0
+ provider.aws v1.5.0

Terraform Configuration Files

resource "aws_route53_record" "jenkins-worker-c5-xlarge" {
  count   = 16
  zone_id = "${data.aws_route53_zone.primary.zone_id}"
  name    = "${element(aws_instance.jenkins-worker-c5-xlarge.*.tags.Name, count.index)}.${var.ossci_infra_domain}"
  type    = "A"
  ttl     = "60"
  records = ["${element(aws_instance.jenkins-worker-c5-xlarge.*.public_ip, count.index)}"]
}

output "jenkins-worker-c5-xlarge-dns" {
  value = ["${aws_route53_record.jenkins-worker-c5-xlarge.*.name}"]
}

Expected Behavior

Suppose I make a modification to output "jenkins-worker-c5-xlarge-dns", but for some reason or another I am unable to run a global terraform apply. I'd like to be able to say terraform apply -target jenkins-worker-c5-xlarge-dns to update the output variable.

Actual Behavior

I have to make some edit to a dependency of the output and apply before the change is picked up.

Steps to Reproduce

  1. Make an output variable
  2. terraform apply
  3. Edit the output variable
  4. terraform apply -target ???
@jbardin
Copy link
Member

jbardin commented Feb 6, 2018

Hi @ezyang,

This was brought up recently for automated workflows, where the absence of a plan meant there were no changes, and the new output could not be applied.

If you're working from the CLI, this should work by executing terraform apply directly. In earlier versions this could have been unsafe if other resources had changed in the meantime, but the current versions always require confirmation for changes in an apply without a plan file -- though if there's only changes to an output it will apply immediately.

@apparentlymart
Copy link
Contributor

Hi @ezyang,

Following on from what @jbardin said here, the proposal in #15419 is relevant to what you requested here, and we're planning to look more closely at that (or, more accurately, on the general area of the CLI workflow) after we finish our current work on configuration language improvements.

In the mean time, terraform refresh may help you get what you need in the mean time. Unlike terraform apply it doesn't have the prompt to review the changes and approve them (that's what #15419 aims to address) but it will read the latest data from each resource and then update all of the outputs in terms of those updates, which includes re-evaluating your output expression to incorporate any changes.

@ezyang
Copy link
Author

ezyang commented Feb 7, 2018

Awesome, I'll try terraform refresh.

(The usual reason one can't run terraform apply is usually because some parts of your terraform config are in a bad state and running a global update would break prod.)

@apparentlymart
Copy link
Contributor

Thanks for following up, @ezyang.

I think what you're asking for here will end up covered by a combination of #15419 and #17034, which are both related ideas about integrating this sort of action into the primary terraform apply workflow. In particular #17034 discusses the idea of a possible terraform apply -read-only option that could behave similarly to terraform refresh but still incorporate the explicit approval step.

Those are both still just design sketches and so details may change before final release, but since those two issues already cover this use-case I'm going to close this just to consolidate the discussion to those proposals. Thanks for sharing this use-case, and I hope terraform refresh is a suitable substitute in the mean time!

@rcmorano
Copy link

rcmorano commented Feb 4, 2019

Just for the record: I use s3 as remote storage backend and new outputs are not uploaded unless you strictly apply a plan that imply changes.
Since I do use the terraform outputs from s3 as input for some other tasks (ansible ones, to be exact), I usually find myself performing dummy changes to force "output updates".

I think It would be nice if we could force this somehow from terraform refresh!

@kknd22
Copy link

kknd22 commented Mar 1, 2019

I think I ran into similar issues but might be even worse: after terraform refresh all output are gone.
util I use terraform apply again!

terraform output
The state file either has no outputs defined, or all the defined
outputs are empty. Please define an output in your configuration
with the `output` keyword and run `terraform refresh` for it to
become available. If you are using interpolation, please verify
the interpolated value is not empty. You can use the 
`terraform console` command to assist.

@vide
Copy link

vide commented Mar 14, 2019

In my case I had to update an output which was now a concat of two variables. What worked for me: terraform apply -target=resource.foo where resource.foo didn't absolutely change. But just going through the apply cycle updated the output.

@ghost
Copy link

ghost commented Aug 13, 2019

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.

@ghost ghost locked and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants