-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
54 lines (50 loc) · 2.15 KB
/
main.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
resource "aws_security_group" "this" {
name = "${var.project}-${var.env}-${var.name}-sg"
vpc_id = var.vpc_id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group_rule" "ingress_sg_target" {
for_each = { for idx, value in var.ingress_port_sg_targets : idx => value }
type = "ingress"
security_group_id = aws_security_group.this.id
from_port = each.value.port
to_port = each.value.port
protocol = each.value.protocol
description = lookup(each.value, "description", null)
source_security_group_id = each.value.security_group_id
}
resource "aws_security_group_rule" "ingress_cidr_target" {
for_each = { for idx, value in var.ingress_port_cidr_targets : idx => value }
type = "ingress"
security_group_id = aws_security_group.this.id
protocol = each.value.protocol
from_port = each.value.port
to_port = each.value.port
description = lookup(each.value, "description", null)
cidr_blocks = each.value.cidr_blocks
}
resource "aws_security_group_rule" "ingress_range_sg_target" {
for_each = { for idx, value in var.ingress_range_sg_targets : idx => value }
type = "ingress"
security_group_id = aws_security_group.this.id
protocol = each.value.protocol
from_port = each.value.from_port
to_port = each.value.to_port
description = lookup(each.value, "description", null)
source_security_group_id = each.value.security_group_id
}
resource "aws_security_group_rule" "ingress_range_cidr_target" {
for_each = { for idx, value in var.ingress_range_cidr_targets : idx => value }
type = "ingress"
security_group_id = aws_security_group.this.id
protocol = each.value.protocol
from_port = each.value.from_port
to_port = each.value.to_port
description = lookup(each.value, "description", null)
cidr_blocks = each.value.cidr_blocks
}