Skip to content

ingress_with_cidr_blocks do not use prefix_list_ids from map entry #281

@Remy-Mollandin-SK5

Description

@Remy-Mollandin-SK5

Description

Complete example shows a map entry named "prefix_list_ids". However, the code shows that only var.ingress_prefix_list_ids is used..

  • ✋ I have searched the open/closed issues and my issue is not listed.

Versions

  • Module version [Required]: 4.17
  • Terraform version: 1.3.9
  • Provider version(s): 4.60

Reproduction Code [Required]

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_ec2_managed_prefix_list" "one" {
  address_family = "IPv4"
  max_entries    = 1
  name           = "pl-one"
}

resource "aws_ec2_managed_prefix_list" "two" {
  address_family = "IPv4"
  max_entries    = 1
  name           = "pl-two"
}

module "prefix_list" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "~> 4.17"

  name        = "pl-sg"
  description = "Security group with prefix list"
  vpc_id      = aws_vpc.main.id

  ingress_with_cidr_blocks = [
    {
      from_port       = 9100
      to_port         = 9100
      protocol        = 6 # "tcp"
      description     = "Arbitrary TCP port"
      prefix_list_ids = join(",", [aws_ec2_managed_prefix_list.one.id, aws_ec2_managed_prefix_list.two.id])
    },
  ]
}

Steps to reproduce the behavior:

terraform init && terraform apply

Expected behavior

Security group rule using prefix_list_ids mentioned in the map

Actual behavior

Security group rule with empty prefix_list_ids. Apply running for 5 minutes before crashing:

╷
│ Error: waiting for Security Group (sg-01bb4ea80ed15aede) Rule (sgrule-3779539315) create: couldn't find resource
│ 
│   with module.prefix_list.aws_security_group_rule.ingress_with_cidr_blocks[0],
│   on .terraform/modules/prefix_list/main.tf line 191, in resource "aws_security_group_rule" "ingress_with_cidr_blocks":
│  191: resource "aws_security_group_rule" "ingress_with_cidr_blocks" {
│ 

Rule during plan:

  # module.prefix_list.aws_security_group_rule.ingress_with_cidr_blocks[0] will be created
  + resource "aws_security_group_rule" "ingress_with_cidr_blocks" {
      + cidr_blocks              = []
      + description              = "Arbitrary TCP port"
      + from_port                = 9100
      + id                       = (known after apply)
      + prefix_list_ids          = []
      + protocol                 = "tcp"
      + security_group_id        = (known after apply)
      + security_group_rule_id   = (known after apply)
      + self                     = false
      + source_security_group_id = (known after apply)
      + to_port                  = 9100
      + type                     = "ingress"
    }

Terminal Output Screenshot(s)

Additional context

This is troublesome if we have multiple ingress_with_cidr_blocks or ingress_with_source_security_group_id for the same port as it will try to add the prefix list rule to each.

Example:

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_ec2_managed_prefix_list" "one" {
  address_family = "IPv4"
  max_entries    = 1
  name           = "pl-one"
}

resource "aws_ec2_managed_prefix_list" "two" {
  address_family = "IPv4"
  max_entries    = 1
  name           = "pl-two"
}

resource "aws_security_group" "one" {
  vpc_id = aws_vpc.main.id
}

resource "aws_security_group" "two" {
  vpc_id = aws_vpc.main.id
}

module "prefix_list" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "~> 4.17"

  name        = "pl-sg"
  description = "Security group with prefix list"
  vpc_id      = aws_vpc.main.id

  ingress_prefix_list_ids = [
    aws_ec2_managed_prefix_list.one.id,
    aws_ec2_managed_prefix_list.two.id
  ]
  ingress_with_source_security_group_id = [
    {
      from_port       = 9100
      to_port         = 9100
      protocol        = 6 # "tcp"
      description     = "Arbitrary TCP port"
      source_security_group_id = aws_security_group.one.id
    },
    {
      from_port       = 9100
      to_port         = 9100
      protocol        = 6 # "tcp"
      description     = "Arbitrary TCP port"
      source_security_group_id = aws_security_group.two.id
    }
  ]
}

Results:

│ Error: [WARN] A duplicate Security Group rule was found on (sg-01bb4ea80ed15aede). This may be
│ a side effect of a now-fixed Terraform issue causing two security groups with
│ identical attributes but different source_security_group_ids to overwrite each
│ other in the state. See https://github.com/hashicorp/terraform/pull/2376 for more
│ information and instructions for recovery. Error: InvalidPermission.Duplicate: the specified rule "peer: pl-09b782041201388e9, TCP, from port: 9100, to port: 9100, ALLOW" already exists
│       status code: 400, request id: 02bc7f1d-35d9-483b-945b-f4ec90164cb1
│ 
│   with module.prefix_list.aws_security_group_rule.ingress_with_source_security_group_id[1],
│   on .terraform/modules/prefix_list/main.tf line 103, in resource "aws_security_group_rule" "ingress_with_source_security_group_id":
│  103: resource "aws_security_group_rule" "ingress_with_source_security_group_id" {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions