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: Remove prefix_list_ids attribute from _with_cidr_blocks & specific prefix list for each rules on _with_prefix_list_ids #325

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ module "prefix_list" {
vpc_id = data.aws_vpc.default.id

ingress_prefix_list_ids = [data.aws_prefix_list.s3.id, data.aws_prefix_list.dynamodb.id]
ingress_with_cidr_blocks = [
ingress_with_prefix_list_ids = [
{
from_port = 9100
to_port = 9100
Expand Down
65 changes: 57 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ resource "aws_security_group_rule" "ingress_with_cidr_blocks" {
join(",", var.ingress_cidr_blocks),
),
))
prefix_list_ids = var.ingress_prefix_list_ids

description = lookup(
var.ingress_with_cidr_blocks[count.index],
"description",
Expand All @@ -214,11 +214,13 @@ resource "aws_security_group_rule" "ingress_with_cidr_blocks" {
"from_port",
var.rules[lookup(var.ingress_with_cidr_blocks[count.index], "rule", "_")][0],
)

to_port = lookup(
var.ingress_with_cidr_blocks[count.index],
"to_port",
var.rules[lookup(var.ingress_with_cidr_blocks[count.index], "rule", "_")][1],
)

protocol = lookup(
var.ingress_with_cidr_blocks[count.index],
"protocol",
Expand All @@ -241,7 +243,7 @@ resource "aws_security_group_rule" "computed_ingress_with_cidr_blocks" {
join(",", var.ingress_cidr_blocks),
),
))
prefix_list_ids = var.ingress_prefix_list_ids

description = lookup(
var.computed_ingress_with_cidr_blocks[count.index],
"description",
Expand All @@ -257,6 +259,7 @@ resource "aws_security_group_rule" "computed_ingress_with_cidr_blocks" {
"_",
)][0],
)

to_port = lookup(
var.computed_ingress_with_cidr_blocks[count.index],
"to_port",
Expand All @@ -266,6 +269,7 @@ resource "aws_security_group_rule" "computed_ingress_with_cidr_blocks" {
"_",
)][1],
)

protocol = lookup(
var.computed_ingress_with_cidr_blocks[count.index],
"protocol",
Expand Down Expand Up @@ -437,7 +441,15 @@ 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 = compact(split(
",",
lookup(
var.ingress_with_prefix_list_ids[count.index],
"prefix_list_ids",
join(",", var.ingress_prefix_list_ids)
)
))

description = lookup(
var.ingress_with_prefix_list_ids[count.index],
"description",
Expand All @@ -449,11 +461,13 @@ resource "aws_security_group_rule" "ingress_with_prefix_list_ids" {
"from_port",
var.rules[lookup(var.ingress_with_prefix_list_ids[count.index], "rule", "_")][0],
)

to_port = lookup(
var.ingress_with_prefix_list_ids[count.index],
"to_port",
var.rules[lookup(var.ingress_with_prefix_list_ids[count.index], "rule", "_")][1],
)

protocol = lookup(
var.ingress_with_prefix_list_ids[count.index],
"protocol",
Expand All @@ -468,7 +482,15 @@ 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 = compact(split(
",",
lookup(
var.ingress_with_prefix_list_ids[count.index],
"prefix_list_ids",
join(",", var.ingress_prefix_list_ids)
)
))

description = lookup(
var.ingress_with_prefix_list_ids[count.index],
"description",
Expand All @@ -480,11 +502,13 @@ resource "aws_security_group_rule" "computed_ingress_with_prefix_list_ids" {
"from_port",
var.rules[lookup(var.ingress_with_prefix_list_ids[count.index], "rule", "_")][0],
)

to_port = lookup(
var.ingress_with_prefix_list_ids[count.index],
"to_port",
var.rules[lookup(var.ingress_with_prefix_list_ids[count.index], "rule", "_")][1],
)

protocol = lookup(
var.ingress_with_prefix_list_ids[count.index],
"protocol",
Expand Down Expand Up @@ -639,7 +663,7 @@ resource "aws_security_group_rule" "egress_with_cidr_blocks" {
join(",", var.egress_cidr_blocks),
),
))
prefix_list_ids = var.egress_prefix_list_ids

description = lookup(
var.egress_with_cidr_blocks[count.index],
"description",
Expand All @@ -651,11 +675,13 @@ resource "aws_security_group_rule" "egress_with_cidr_blocks" {
"from_port",
var.rules[lookup(var.egress_with_cidr_blocks[count.index], "rule", "_")][0],
)

to_port = lookup(
var.egress_with_cidr_blocks[count.index],
"to_port",
var.rules[lookup(var.egress_with_cidr_blocks[count.index], "rule", "_")][1],
)

protocol = lookup(
var.egress_with_cidr_blocks[count.index],
"protocol",
Expand All @@ -678,7 +704,7 @@ resource "aws_security_group_rule" "computed_egress_with_cidr_blocks" {
join(",", var.egress_cidr_blocks),
),
))
prefix_list_ids = var.egress_prefix_list_ids

description = lookup(
var.computed_egress_with_cidr_blocks[count.index],
"description",
Expand All @@ -694,6 +720,7 @@ resource "aws_security_group_rule" "computed_egress_with_cidr_blocks" {
"_",
)][0],
)

to_port = lookup(
var.computed_egress_with_cidr_blocks[count.index],
"to_port",
Expand All @@ -703,6 +730,7 @@ resource "aws_security_group_rule" "computed_egress_with_cidr_blocks" {
"_",
)][1],
)

protocol = lookup(
var.computed_egress_with_cidr_blocks[count.index],
"protocol",
Expand Down Expand Up @@ -875,7 +903,15 @@ 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 = compact(split(
",",
lookup(
var.egress_with_prefix_list_ids[count.index],
"prefix_list_ids",
join(",", var.egress_prefix_list_ids)
))
)

description = lookup(
var.egress_with_prefix_list_ids[count.index],
"description",
Expand All @@ -891,6 +927,7 @@ resource "aws_security_group_rule" "egress_with_prefix_list_ids" {
"_",
)][0],
)

to_port = lookup(
var.egress_with_prefix_list_ids[count.index],
"to_port",
Expand All @@ -900,6 +937,7 @@ resource "aws_security_group_rule" "egress_with_prefix_list_ids" {
"_",
)][1],
)

protocol = lookup(
var.egress_with_prefix_list_ids[count.index],
"protocol",
Expand All @@ -919,7 +957,16 @@ resource "aws_security_group_rule" "computed_egress_with_prefix_list_ids" {
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 = compact(split(
",",
lookup(
var.computed_egress_with_prefix_list_ids[count.index],
"prefix_list_ids",
join(",", var.egress_prefix_list_ids)
)
))

description = lookup(
var.computed_egress_with_prefix_list_ids[count.index],
"description",
Expand All @@ -935,6 +982,7 @@ resource "aws_security_group_rule" "computed_egress_with_prefix_list_ids" {
"_",
)][0],
)

to_port = lookup(
var.computed_egress_with_prefix_list_ids[count.index],
"to_port",
Expand All @@ -944,6 +992,7 @@ resource "aws_security_group_rule" "computed_egress_with_prefix_list_ids" {
"_",
)][1],
)

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