2
votes

Following is the terraform script.

variable "vpc_ids" {
  default = [
    "vpc-**********",
    "vpc-**********",
    "vpc-**********",
    "vpc-**********",
  ]

  type = "list"
}

data "aws_security_groups" "test" {
  filter {
    name   = "vpc-id"
    values = "${var.vpc_ids}"
  }
}

data "aws_security_group" "selected" {
  count = "${length(data.aws_security_groups.test.ids)}"
  id    = "${element(data.aws_security_groups.test.ids, count.index)}"
}

output "sec_groups" {
  value = "${data.aws_security_group.selected.0.description}"

  //  value = "${join(",", data.aws_security_group.selected.*.description)}"
}

In the last, I am using description but it is not giving the inbound and outbound rules for the security group.

Is anyone know how to ge the inbound and outbound rules using datasource ?

That code looks like it would just grab the same group each iteration.Matt Schuchard
@MattSchuchard value = "${data.aws_security_group.selected.0.description}" in this line that index 0 will always fetch the description of the first group and that was intentional for testing purpose. Actually, the problem is that I am not getting the inbound and outbound rules for the security group. I think you got what I am trying to say...RogerUma
Came here to find a way to append ingress rules to existing sg. Ended up creating an sg void of ingress rules and a new ingress rule resource to associate with existing sg.Parag Doke