How to use ingress multiple times in security group creation

Error: Attribute redefined

on Security_group.tf line 15, in resource “aws_security_group” “mysite_sg”:
15: ingress = [ {

The argument “ingress” was already set at Security_group.tf:3,5-12. Each
argument may be set only once.

I have already applied the ingress for port 22, now i need to add one more port 80 by using another ingress, but its not allowing me… throwing a error as i mentioned above.

Existing one:

ingress = [ {

  cidr_blocks = [ "0.0.0.0/0" ]

  description = ""

  from_port = 22

  ipv6_cidr_blocks = [ ]

  prefix_list_ids = [ ]

  protocol = "tcp"

  security_groups = [ ]

  self = true

  to_port = 22

} ]

I am looking how to use ingress multiple times in single SG file.

The issue here is the ‘=’ and square brackets are obsolete. I had the same issue with vscode auto-populating the ingress argument.

Simply remove the ‘=’ and the square brackets and that will sort it. See below:

ingress {
  cidr_blocks = [ "0.0.0.0/0" ]
  description = ""
  from_port = 22
  ipv6_cidr_blocks = [ ]
  prefix_list_ids = [ ]
  protocol = "tcp"
  security_groups = [ ]
  self = true
  to_port = 22
}