-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecurity_group.tf
108 lines (90 loc) · 2.48 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module "security_group_db" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
description = "Security group for db subnet"
egress_cidr_blocks = ["0.0.0.0/0"]
name = "${var.name}-db"
vpc_id = module.vpc.vpc_id
ingress_with_self = [
{
rule = "all-all"
}
]
egress_with_cidr_blocks = [
{
rule = "all-all"
}
]
tags = {
Network = var.name
Terraform = "terraform-aws-network"
}
}
module "security_group_elasticache" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
description = "Security group for elasticache subnet"
egress_cidr_blocks = ["0.0.0.0/0"]
name = "${var.name}-elasticache"
vpc_id = module.vpc.vpc_id
ingress_with_self = [
{
rule = "all-all"
}
]
egress_with_cidr_blocks = [
{
rule = "all-all"
}
]
tags = {
Network = var.name
Terraform = "terraform-aws-network"
}
}
module "security_group_private" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
description = "Security group for private subnet"
egress_cidr_blocks = ["0.0.0.0/0"]
name = "${var.name}-private"
vpc_id = module.vpc.vpc_id
ingress_with_self = [
{
rule = "all-all"
}
]
egress_with_cidr_blocks = [
{
rule = "all-all"
}
]
tags = {
Network = var.name
Terraform = "terraform-aws-network"
}
}
resource "aws_vpc_security_group_ingress_rule" "db_allow_private" {
description = "Allow private subnet to access db"
from_port = 5432
ip_protocol = "tcp"
referenced_security_group_id = module.security_group_private.security_group_id
security_group_id = module.security_group_db.security_group_id
to_port = 5432
tags = {
Network = var.name
Terraform = "terraform-aws-network"
}
}
resource "aws_vpc_security_group_ingress_rule" "elasticache_allow_private" {
description = "Allow private subnet to access elasticache"
from_port = 6379
ip_protocol = "tcp"
referenced_security_group_id = module.security_group_private.security_group_id
security_group_id = module.security_group_elasticache.security_group_id
to_port = 6379
tags = {
Network = var.name
Terraform = "terraform-aws-network"
}
}