Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow the creation of prefix-list rules, passing in unique prefix list IDs on a per rule basis #318

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,12 @@ resource "aws_security_group_rule" "ingress_with_prefix_list_ids" {
security_group_id = local.this_sg_id
type = "ingress"

prefix_list_ids = var.ingress_prefix_list_ids
prefix_list_ids = lookup(
var.ingress_with_prefix_list_ids[count.index], "include_base_prefix_list_ids", true
) ? concat(
var.ingress_prefix_list_ids, lookup(var.ingress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])
) : lookup(var.ingress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])

description = lookup(
var.ingress_with_prefix_list_ids[count.index],
"description",
Expand Down Expand Up @@ -468,7 +473,12 @@ resource "aws_security_group_rule" "computed_ingress_with_prefix_list_ids" {
security_group_id = local.this_sg_id
type = "ingress"

prefix_list_ids = var.ingress_prefix_list_ids
prefix_list_ids = lookup(
var.ingress_with_prefix_list_ids[count.index], "include_base_prefix_list_ids", true
) ? concat(
var.ingress_prefix_list_ids, lookup(var.ingress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])
) : lookup(var.ingress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])

description = lookup(
var.ingress_with_prefix_list_ids[count.index],
"description",
Expand Down Expand Up @@ -875,7 +885,12 @@ resource "aws_security_group_rule" "egress_with_prefix_list_ids" {
security_group_id = local.this_sg_id
type = "egress"

prefix_list_ids = var.egress_prefix_list_ids
prefix_list_ids = lookup(
var.egress_with_prefix_list_ids[count.index], "include_base_prefix_list_ids", true
) ? concat(
var.egress_prefix_list_ids, lookup(var.egress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])
) : lookup(var.egress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])

description = lookup(
var.egress_with_prefix_list_ids[count.index],
"description",
Expand Down Expand Up @@ -911,15 +926,19 @@ resource "aws_security_group_rule" "egress_with_prefix_list_ids" {
)
}

# Computed - Security group rules with "source_security_group_id", but without "cidr_blocks", "self" or "source_security_group_id"
# Computed - Security group rules with "egress_prefix_list_ids", but without "cidr_blocks", "self" or "source_security_group_id"
resource "aws_security_group_rule" "computed_egress_with_prefix_list_ids" {
count = var.create ? var.number_of_computed_egress_with_prefix_list_ids : 0

security_group_id = local.this_sg_id
type = "egress"

source_security_group_id = var.computed_egress_with_prefix_list_ids[count.index]["source_security_group_id"]
prefix_list_ids = var.egress_prefix_list_ids
prefix_list_ids = lookup(
var.egress_with_prefix_list_ids[count.index], "include_base_prefix_list_ids", true
) ? concat(
var.egress_prefix_list_ids, lookup(var.egress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])
) : lookup(var.egress_with_prefix_list_ids[count.index]["prefix_list_ids"], [])

description = lookup(
var.computed_egress_with_prefix_list_ids[count.index],
"description",
Expand Down
Loading