generated from production-ready-toolkit/terraform-module-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsecurity.tf
52 lines (40 loc) · 1.74 KB
/
security.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
resource "aws_security_group" "main" {
name = format("%s", var.name)
description = var.name
vpc_id = var.vpc
tags = var.tags
}
resource "aws_security_group_rule" "inbound_cidrs" {
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = length(var.cidrs_to_allow) > 0 ? var.cidrs_to_allow : data.aws_vpc.main.cidr_block_associations[*].cidr_block
security_group_id = aws_security_group.main.id
}
resource "aws_security_group_rule" "outbound_cidrs" {
type = "egress"
from_port = 0
to_port = 0
protocol = "tcp"
cidr_blocks = length(var.cidrs_to_allow) > 0 ? var.cidrs_to_allow : data.aws_vpc.main.cidr_block_associations[*].cidr_block
security_group_id = aws_security_group.main.id
}
resource "aws_security_group_rule" "inbound_sgs" {
count = length(var.security_groups_to_allow)
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
source_security_group_id = var.security_groups_to_allow[count.index]
security_group_id = aws_security_group.main.id
}
resource "aws_security_group_rule" "outbound_sgs" {
count = length(var.security_groups_to_allow)
type = "egress"
from_port = 0
to_port = 0
protocol = "tcp"
source_security_group_id = var.security_groups_to_allow[count.index]
security_group_id = aws_security_group.main.id
}