Skip to content

Feature: Support for_each with map-based rule definitions #340

@vedantshinde

Description

@vedantshinde

Is your request related to a problem? Please describe.

Currently, the module only supports list-based rule definitions (e.g., ingress_with_cidr_blocks, ingress_with_source_security_group_id), which have several limitations:

  • Rules are tracked by their position in lists, causing unnecessary recreations when rules are added/removed from the middle of lists
  • Rules can't be easily identified or referenced by descriptive names
  • Adding or removing rules can cause a ripple effect where other rules get recreated due to index shifts

Describe the solution you'd like.

Add support for a rules_map input variable that accepts a map where each key is a descriptive rule identifier and the value contains the rule definition. For example:

  source = "terraform-aws-modules/security-group/aws"
  
  name   = "web-server"
  vpc_id = "vpc-12345678"
  
  rules_map = {
    "http-public" = {
      type        = "ingress"
      from_port   = 80
      to_port     = 80
      protocol    = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
      description = "HTTP access from internet"
    }
    "https-public" = {
      type        = "ingress"
      from_port   = 443
      to_port     = 443
      protocol    = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
      description = "HTTPS access from internet"
    }
    "ssh-admin" = {
      type                     = "ingress"
      from_port                = 22
      to_port                  = 22
      protocol                 = "tcp"
      source_security_group_id = "sg-admin123"
      description              = "SSH from admin security group"
    }
  }
}```

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions