-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
92 lines (77 loc) · 1.95 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
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
locals {
env_map = {
dev = "Dev"
test = "Test"
prod = "Prod"
tools = "Tools"
unclass = "UnClass"
}
environment = local.env_map[lower(var.environment)]
vpc_name = "${local.environment}_vpc"
availability_zones = ["a", "b"]
web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"]
app_subnet_names = [for az in local.availability_zones : "App_${local.environment}_az${az}_net"]
data_subnet_names = [for az in local.availability_zones : "Data_${local.environment}_az${az}_net"]
security_group_name_suffix = "_sg"
web_security_group_name = "Web${local.security_group_name_suffix}"
app_security_group_name = "App${local.security_group_name_suffix}"
data_security_group_name = "Data${local.security_group_name_suffix}"
}
data "aws_vpc" "main" {
filter {
name = "tag:Name"
values = [
local.vpc_name]
}
}
data "aws_subnets" "web" {
filter {
name = "vpc-id"
values = [data.aws_vpc.main.id]
}
filter {
name = "tag:Name"
values = local.web_subnet_names
}
}
data "aws_subnets" "app" {
filter {
name = "vpc-id"
values = [data.aws_vpc.main.id]
}
filter {
name = "tag:Name"
values = local.app_subnet_names
}
}
data "aws_subnets" "data" {
filter {
name = "vpc-id"
values = [data.aws_vpc.main.id]
}
filter {
name = "tag:Name"
values = local.data_subnet_names
}
}
data "aws_subnet" "web" {
for_each = toset(data.aws_subnets.web.ids)
id = each.value
}
data "aws_subnet" "app" {
for_each = toset(data.aws_subnets.app.ids)
id = each.value
}
data "aws_subnet" "data" {
for_each = toset(data.aws_subnets.data.ids)
id = each.value
}
data "aws_security_group" "web" {
name = local.web_security_group_name
}
data "aws_security_group" "app" {
name = local.app_security_group_name
}
data "aws_security_group" "data" {
name = local.data_security_group_name
}