-
Notifications
You must be signed in to change notification settings - Fork 2
/
subnet.tf
39 lines (33 loc) · 1.41 KB
/
subnet.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
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_subnet" "public" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 4, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = merge(local.tags, { "Name" = "public_${terraform.workspace}_${count.index}" })
lifecycle {
create_before_destroy = true
}
}
resource "aws_subnet" "private" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 4, count.index + 6)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = merge(local.tags, { "Name" = "private_${terraform.workspace}_${count.index}" })
lifecycle {
create_before_destroy = true
}
}
resource "aws_subnet" "database" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 4, count.index + 12)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = merge(local.tags, { "Name" = "database_${terraform.workspace}_${count.index}" })
lifecycle {
create_before_destroy = true
}
}