forked from bcgov/terraform-octk-aws-sea-network-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
70 lines (62 loc) · 1.48 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.11"
}
}
}
locals {
env_map = {
dev = "Dev"
test = "Test"
prod = "Prod"
sandbox = "Sandbox"
unclass = "UnClass"
}
environment = local.env_map[lower(var.environment)]
vpc_name = "${local.environment}_vpc"
availability_zones = list("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"]
}
data "aws_vpc" "main" {
filter {
name = "tag:Name"
values = [local.vpc_name]
}
}
data "aws_subnet_ids" "web" {
vpc_id = data.aws_vpc.main.id
filter {
name = "tag:Name"
values = local.web_subnet_names
}
}
data "aws_subnet_ids" "app" {
vpc_id = data.aws_vpc.main.id
filter {
name = "tag:Name"
values = local.app_subnet_names
}
}
data "aws_subnet_ids" "data" {
vpc_id = data.aws_vpc.main.id
filter {
name = "tag:Name"
values = local.data_subnet_names
}
}
data "aws_subnet" "web" {
for_each = data.aws_subnet_ids.web.ids
id = each.value
}
data "aws_subnet" "app" {
for_each = data.aws_subnet_ids.app.ids
id = each.value
}
data "aws_subnet" "data" {
for_each = data.aws_subnet_ids.app.ids
id = each.value
}