-
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
Conditionally create resource if variable is set #15281
Comments
Hi @nodesocket, We try to keep questions out of the github issues because it's harder for people in future to find the answers, so I'd ask that in future questions be directed to one of the forums on the Community page. Here's one way to achieve what you're looking for here, though: variable "google_vpc_cidr" {
description = "Google Compute Engine VPC CIDR"
default = ""
}
resource "aws_security_group" "queue" {
name = "queue"
description = "Queue role"
}
resource "aws_security_group_rule" "rabbitmq_tcp_5672_google" {
count = "${var.google_vpc_cidr != "" ? 1 : 0}"
type = "ingress"
from_port = 5672
to_port = 5672
protocol = "tcp"
cidr_blocks = [
"${var.google_vpc_cidr}"
]
security_group_id = "${aws_security_group.queue.id}"
} If you have any further questions about the above, please refer to the community page, since it's hard for us to track ongoing Q&A within the github issues UI. Thanks! |
@apparentlymart I just followed up in the gitter https://gitter.im/hashicorp-terraform/Lobby. Seems like if |
Even doing:
Still breaks, which it should not. If |
Using the count trick then force you to do the splat, split, join, and element dance in the outputs, I think a meta attribute that enables and disables a resource is pretty logical thing to have. See #17617 for example. |
Does closing this issue mean that we'll have to wrap all the references to a conditional resource in |
Also, this "solution" does not integrate well with tools that auto-generate the variables documentation, like terraform-docs. |
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. |
I'd like to create the following resource only if the variable
var.google_vpc_cidr
is setnot empty
. How is this possible?The text was updated successfully, but these errors were encountered: