Skip to content

Commit

Permalink
rds-postgres: fix ingress_security_groups, ingress_networks
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Dec 16, 2024
1 parent 1bf1eb3 commit 4efa5e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@
- emr
- add module for EMR ports and several security groups

* 2.5.1 -- 2024-12-16
- rds-postgres
- fix ingress_security_groups, ingress_networks

2 changes: 0 additions & 2 deletions rds-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ No modules.
| [aws_security_group.this_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
| [aws_ec2_managed_prefix_list.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source |
| [aws_ec2_managed_prefix_list.ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source |
| [aws_security_group.egress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
| [aws_security_group.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
| [aws_vpc.this_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |

## Inputs
Expand Down
32 changes: 16 additions & 16 deletions rds-postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ data "aws_vpc" "this_vpc" {
id = var.vpc_id
}

data "aws_security_group" "ingress_security_groups" {
count = length(var.ingress_security_groups)
id = element(var.ingress_security_groups, count.index)
}

data "aws_security_group" "egress_security_groups" {
count = length(var.egress_security_groups)
id = element(var.egress_security_groups, count.index)
}
## data "aws_security_group" "ingress_security_groups" {
## for_each = toset(var.ingress_security_groups))
## id = each.key
## }
##
## data "aws_security_group" "egress_security_groups" {
## for_each = toset(var.egress_security_groups)
## id = each.key
## }

locals {
vpc_networks = var.use_vpc_cidr ? [data.aws_vpc.this_vpc[0].cidr_block] : []
Expand All @@ -77,7 +77,7 @@ resource "aws_security_group" "this_security_group" {
from_port = p.value["from"]
to_port = p.value["to"]
protocol = p.value["proto"]
cidr_blocks = length(p.value["cidr"]) == 0 ? local.external_ingress_networks : p.value["cidr"]
cidr_blocks = length(local.external_ingress_networks) > 0 ? local.external_ingress_networks : p.value["cidr"]
}
}

Expand All @@ -98,14 +98,14 @@ resource "aws_security_group" "this_security_group" {

# ingress security group ids (all)
dynamic "ingress" {
for_each = local.ingress_sg
for_each = length(local.ingress_sg) > 0 ? { 1 = 1 } : {}
iterator = sg
content {
description = "${local.short_description}: ${local.ingress_sg_names[sg.value]}"
description = "${local.short_description}"
from_port = 0
to_port = 0
protocol = -1
security_groups = [sg.value]
security_groups = [local.ingress_sg]
}
}

Expand Down Expand Up @@ -136,14 +136,14 @@ resource "aws_security_group" "this_security_group" {

# egress security group ids (all)
dynamic "egress" {
for_each = local.egress_sg
for_each = length(local.egress_sg) > 0 ? { 1 = 1 } : {}
iterator = sg
content {
description = "${local.short_description}: ${local.egress_sg_names[sg]}"
description = "${local.short_description}"
from_port = 0
to_port = 0
protocol = -1
security_groups = [sg]
security_groups = [local.egress_sg]
}
}

Expand Down

0 comments on commit 4efa5e4

Please sign in to comment.