-
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
Unable to use var for ignore_changes or prevent_destroy #10730
Comments
We don't support variables in those since they need to be parsed and handled very early on in Terraform (before interpolations can be processed). We hope to loosen this requirement one day. In the mean time, I'm going to change the issue to be a bug in order to add better validation and error messages to this case. |
It sucks that you can't use a variable here as after you introduced |
Is this a duplicate of #3116? |
#3116 is locked, otherwise I would have replied over there. These two issues do seem to be duplicates. I was trying to use @zero-below offers a potential solution in that you can create a The problem is that I'd still like to be able to really override It turns out you can
variable "prevent_machine_destroy" {
description = "Set lifecycle.prevent_destroy on machines"
default = true
}
resource "random_id" "protector" {
count = "${ var.prevent_machine_destroy ? 1 : 0 }"
byte_length = 8
keepers = {
ids = "${join(",", null_resource.foo.*.id)}"
}
lifecycle {
prevent_destroy = true
}
}
resource "null_resource" "foo" {
count = "2"
provisioner "local-exec" {
command = "date"
}
} |
I'd also like to see variables usable in lifecycle blocks, not for prevent_destroy, but for AMI updates. It would be nice to have ignore_changes = ["ami"] set so that Amazon releasing a new AMI doesn't surprise me, then setting an "ok_to_update_ami" variable in the tfvars file when I am ready to have all my instances rebuilt with the latest AMI. |
Hi all! Looking back at the history here, it seems that the intended distinction between this issue and #3116 is that #3116 represents the feature request of supporting dynamic Since Terraform 0.12 includes specialized error messages for these scenarios, we're going to close out this one and leave #3116 to represent the feature request. |
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
Terraform v0.7.13
Affected Resource(s)
lifecycle block
ignore_changes and prevent_destroy arguments
Terraform Configuration Files
lifecycle block within aws_instance
lifecycle {
prevent_destroy = "${var.prevent_destroy}"
ignore_changes = "${var.ignore_changes}"
}
vars.tf
variable "prevent_destroy" {
description = "Block destruction of this resource, typically for DB boxes"
default = true
}
variable "ignore_changes" {
description = "list of strings to ignore differences of"
type = "list"
default = [ "ami", "user_data" ]
}
NOTE: Tried with 'true' both quoted and unquoted, same issue
Expected Behavior
should have applied with no error, ignore changes in the ami or user_data variables
Actual Behavior
Error parsing lifecycle for aws_instance[gis]: 2 error(s) decoding:
exit status 1
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform plan
NOTE: not using variables and using:
lifecycle {
prevent_destroy = true
ignore_changes = [ "ami", "user_data" ]
}
in main.tf results in no error and correct behavior (ignoring changes in AMI anduser_data)
The text was updated successfully, but these errors were encountered: