Is it possible to use Terraform conditional with AWS Security groups like this:
securitygroup= ["${substr(terraform.workspace) == "PD" ? module1 : module2}"]
We want to create and attach Security group based of module1 only if terraform.workspace begins with "PD", and we don't want to create Security group defined in module2 if it's not required (doesn't match "PD").
We have tried this and the problem is that Terraform doesn't assign security group built by module1 if security group of module2 is not already created. Once we create both resources, it recognize and attach module1 okay, but then we are duplicating number of Security groups.
Looks like Terraform requires both resources active and created in it's conditionals?
Thanks in advance!
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/4c253591-8d40-4176-b9b7-2b296bce21ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey there!It's hard to say much without seeing more configuration. If you could share some mock up (so you don't share your actual config) that may help.It sounds like you could use this conditional in a `count` attribute:```resource "aws_security_group" "mod1_group" {count = "${substr(terraform.workspace) == "PD" ? 1 : 0}"# details..}```If I understand your scenario correctly, that kind of syntax should only create the Security Group if that substring matches.Let us know if that works!Cheers,Clint
On Thu, Mar 8, 2018 at 6:02 AM, Igor David <david...@gmail.com> wrote:
Is it possible to use Terraform conditional with AWS Security groups like this:
securitygroup= ["${substr(terraform.workspace) == "PD" ? module1 : module2}"]
We want to create and attach Security group based of module1 only if terraform.workspace begins with "PD", and we don't want to create Security group defined in module2 if it's not required (doesn't match "PD").
We have tried this and the problem is that Terraform doesn't assign security group built by module1 if security group of module2 is not already created. Once we create both resources, it recognize and attach module1 okay, but then we are duplicating number of Security groups.
Looks like Terraform requires both resources active and created in it's conditionals?
Thanks in advance!
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/4975c627-56a7-411a-98fb-637b6a7d5aea%40googlegroups.com.
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.nano"
vpc_security_group_ids = ["${substr(var.name,0,3) == "cts" ? "${"aws_security_group.g1.id}" : "${aws_security_group.g1.id}" }" ]
}
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAMN_gXEXun4sreM2ETVweh0NoEdxJELf6gyZNZXeCN_ZO5%2BkSg%40mail.gmail.com.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/TR9yBK0lObM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-tool+unsubscribe@googlegroups.com.