-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_group.tf
31 lines (31 loc) · 1.3 KB
/
security_group.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "custom_sg" {
name = "${var.name}_allow_inbound_access"
description = "manage traffic for ${var.name}"
vpc_id = module.vpc.vpc.id
tags = {
"Name" = "${var.name}-sg"
}
# checkov:skip=CKV2_AWS_5: "Ensure that Security Groups are attached to another resource"
# This security group is attached to the Amazon ElastiCache Serverless resource
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "ingress_custom_sg" {
description = "allow traffic to the cache cluster"
type = "ingress"
from_port = 11211
to_port = 11211
protocol = "tcp"
cidr_blocks = [var.vpc_cidr]
security_group_id = aws_security_group.custom_sg.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "egress_custom_sg" {
description = "allow traffic to reach outside the vpc"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [var.vpc_cidr]
security_group_id = aws_security_group.custom_sg.id
}