-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
83 lines (67 loc) · 2.38 KB
/
vpc.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
module "vpc_label" {
enabled = "${var.enabled}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "vpc"
attributes = ["replica"]
tags = "${var.tags}"
}
resource "aws_vpc" "replica" {
count = "${var.enabled == "true" ? 1 : 0}"
cidr_block = "${var.cidr}"
tags = "${module.vpc_label.tags}"
}
locals {
zone_1_az = "${element(data.aws_availability_zones.available.names, 0)}"
zone_2_az = "${element(data.aws_availability_zones.available.names, 1)}"
zone_3_az = "${element(data.aws_availability_zones.available.names, 2)}"
}
module "zone_1_label" {
enabled = "${var.enabled}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
name = "${local.zone_1_az}"
attributes = ["private"]
stage = "${var.stage}"
tags = "${var.tags}"
}
resource "aws_subnet" "zone_1" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${aws_vpc.replica.id}"
availability_zone = "${local.zone_1_az}"
cidr_block = "${cidrsubnet(aws_vpc.replica.cidr_block, 2, 0)}"
tags = "${module.zone_1_label.tags}"
}
module "zone_2_label" {
enabled = "${var.enabled}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
name = "${local.zone_2_az}"
attributes = ["private"]
stage = "${var.stage}"
tags = "${var.tags}"
}
resource "aws_subnet" "zone_2" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${aws_vpc.replica.id}"
availability_zone = "${local.zone_2_az}"
cidr_block = "${cidrsubnet(aws_vpc.replica.cidr_block, 2, 1)}"
tags = "${module.zone_2_label.tags}"
}
module "zone_3_label" {
enabled = "${var.enabled}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
name = "${local.zone_3_az}"
attributes = ["private"]
stage = "${var.stage}"
tags = "${var.tags}"
}
resource "aws_subnet" "zone_3" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${aws_vpc.replica.id}"
availability_zone = "${local.zone_3_az}"
cidr_block = "${cidrsubnet(aws_vpc.replica.cidr_block, 2, 2)}"
tags = "${module.zone_3_label.tags}"
}