-
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
Ignore resource if variable set. #2831
Comments
One way to do this today is to use the variable "number" {
default = 1
}
resource "any_resource" "foo" {
count = "${var.number}"
} You can set
|
Thanks - it feels a bit odd/quirky, but I'll def give it ago :) |
There's also a lot of chatter about conditional logic and ignoring resources over in #1604 |
@apparentlymart's strategy of |
We are using a Jenkins plugin to deploy a service onto AWS instances and created/update 'VERSION' tag for the instance(s). Unfortunately, Terraform deletes this tag unless there's a way to ignore it. Is there a way to ignore just a single tag, e.g. 'VERSION' as opposed to ignoring all tags? I'd really appreciate a response. Thanks |
Won't this method delete those resources rather than ignore them when |
Unfortunately, from what I've experienced, the
is returned. Although I think there's no way out of this (and hence the |
I'm having the same problem as @BogdanSorlea, I'm managing a couple of separate environments and some resources aren't required for part of them. So with my current configuration I'm getting an error for the resource that doesn't exist whenever I want to plan/apply anything on one of the aforementioned environments. |
@BogdanSorlea Did you ever find a solution to the problem you mentioned in this issue? |
The current "pattern" for depending on a conditional resource is like this: resource "example" "conditional" {
count = "${var.enabled ? 1 : 0}"
}
resource "example" "dependent" {
argument = "${join("", example.conditional.*.attribute)}"
} Other variants are possible to set defaults, etc, but "joining" the zero-or-one-element list is how to avoid the issue of referring to the zeroth element when there is no such element. We'll work on making this smoother in future via more language improvements. |
When lookup_latest_ami is false, data.aws_ami.latest_ecs_ami isn't created, leading to "resource not found" errors when evaluating which AMI ID to use. Apply the fix from hashicorp/terraform#2831 (comment) to ignore that resource if it's not created.
@apparentlymart can you have a look at this problem https://stackoverflow.com/questions/48306089/how-do-i-make-a-field-optional-inside-a-terraform-resource , would be a great help. |
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. |
We have a couple of extra terraform resources that need creating under certain conditions. For example we use environmental overrides to create a "dev" and a "qa" environment from the same base terraform resources. However the qa environment needs extra security_group_rules set.
Unless this can already be achieved, (if so how?) it would be useful to be able to set an override variable for the qa case which deactivates (or activates) a resource.
I would consider an implementation to be a top-level field available on every resource such as:
ignore => "${var.some_variable}"
Then we can set a default for "some_variable" of 1, and set to 0 as an override for the qa tf.variables file.
Otherwise I can see no way of having optional resources flagged for inclusion under certain circumstances.
The text was updated successfully, but these errors were encountered: