Skip to content

Commit 42ccd24

Browse files
feat: Allow security group rules to reference the security group created by the module (#51)
Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
1 parent d7ed9d7 commit 42ccd24

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.99.5
3+
rev: v1.100.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_workspace_remote'
2424
- id: terraform_validate
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v5.0.0
26+
rev: v6.0.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

examples/redis-cluster/main.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ module "elasticache" {
3838
# Security Group
3939
vpc_id = module.vpc.vpc_id
4040
security_group_rules = {
41-
ingress_vpc = {
42-
# Default type is `ingress`
43-
# Default port is based on the default engine port
44-
description = "VPC traffic"
45-
cidr_ipv4 = module.vpc.vpc_cidr_block
41+
ingress-self-redis = {
42+
type = "ingress"
43+
referenced_security_group_id = "self"
44+
description = "Allow traffic from this security group to itself."
4645
}
4746
}
4847

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ resource "aws_vpc_security_group_ingress_rule" "this" {
330330
description = try(each.value.description, null)
331331
from_port = try(each.value.from_port, local.port)
332332
prefix_list_id = lookup(each.value, "prefix_list_id", null)
333-
referenced_security_group_id = lookup(each.value, "referenced_security_group_id", null)
333+
referenced_security_group_id = lookup(each.value, "referenced_security_group_id", null) == "self" ? aws_security_group.this[0].id : lookup(each.value, "referenced_security_group_id", null)
334334
to_port = try(each.value.to_port, local.port)
335335

336336
tags = merge(local.tags, var.security_group_tags, try(each.value.tags, {}))
@@ -349,7 +349,7 @@ resource "aws_vpc_security_group_egress_rule" "this" {
349349
description = try(each.value.description, null)
350350
from_port = try(each.value.from_port, null)
351351
prefix_list_id = lookup(each.value, "prefix_list_id", null)
352-
referenced_security_group_id = lookup(each.value, "referenced_security_group_id", null)
352+
referenced_security_group_id = lookup(each.value, "referenced_security_group_id", null) == "self" ? aws_security_group.this[0].id : lookup(each.value, "referenced_security_group_id", null)
353353
to_port = try(each.value.to_port, null)
354354

355355
tags = merge(local.tags, var.security_group_tags, try(each.value.tags, {}))

0 commit comments

Comments
 (0)