I am trying to configure my terraform for Dev and QA environments, each of which have their own Security Groups, which I specify with the data
tag:
data "aws_security_group" "ssh" {
name = "SG-SSH"
}
data "aws_security_group" "postgres" {
name = "SG-Postgres"
}
Is there a way to specify which security groups get pulled in based on which environment is being targeted? I tried this:
locals {
sgs = {
dev = ["${data.aws_security_group.postgres.id}", "${data.aws_security_group.ssh.id}"]
qa = ["${data.aws_security_group.postgres.id}"]
}
}
Which I then reference with "${local.sgs[var.env]}"
. However, the ssh
security group only exists in the Dev environment so when I target the QA environment, I still get:
data.aws_security_group.ssh: data.aws_security_group.ssh: no matching SecurityGroup found