-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
119 lines (98 loc) · 2.38 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
variable "region" {}
variable "env" {}
variable "profile" {}
variable "vpc_cidr" {}
variable "state_bucket" {}
variable "account_id" {}
variable "private_subnets" {
type = "list"
default = []
}
variable "public_subnets" {
type = "list"
default = []
}
terraform {
required_version = ">= 0.9.9"
backend "s3" {
encrypt = true
acl = "private"
}
}
provider "aws" {
region = "${var.region}"
profile = "${var.profile}"
allowed_account_ids = ["${var.account_id}"]
}
// Builds our VPC and a CIDR range
module "vpc" {
source = "modules/vpc/"
vpc_cidr = "${var.vpc_cidr}"
env = "${var.env}"
region = "${var.region}"
}
// Returns data in a list
// Example: "us-east-2a,us-east-2b,us-east-2c"
module "azs" {
source = "modules/azs/"
}
// Generate subnets and routing tables
module "public" {
source = "modules/public/"
env = "${var.env}"
vpc_id = "${module.vpc.vpc_id}"
azs = "${module.azs.azs}"
region = "${var.region}"
vpc_cidr = "${var.vpc_cidr}"
subnets = "${var.public_subnets}"
}
// Creates an AWS managed NAT Gateway so private subnet instances can hit the internet
// This could also be handled by a t2.micro instance with an iptables ruleset
module "nat" {
source = "modules/nat/"
public_subnet_ids = "${module.public.subnet_ids}"
}
// Generate subnets and routing tables
module "private" {
source = "modules/private"
env = "${var.env}"
vpc_id = "${module.vpc.vpc_id}"
azs = "${module.azs.azs}"
nat_gateway_ids = "${module.nat.gateway_ids}"
region = "${var.region}"
vpc_cidr = "${var.vpc_cidr}"
subnets = "${var.private_subnets}"
}
output "environment" {
value = "${var.env}"
}
output "vpc_cidr" {
value = "${var.vpc_cidr}"
}
output "vpc_id" {
value = "${module.vpc.vpc_id}"
}
output "azs" {
value = "${module.azs.azs}"
}
output "nat_private_ips" {
value = "${module.nat.private_ips}"
}
output "nat_public_ips" {
value = "${module.nat.public_ips}"
}
output "nat_nic_ids" {
value = "${module.nat.nic_ids}"
}
output "public_subnet_ids" {
value = "${module.public.subnet_ids}"
}
output "public_route_tables" {
value = "${module.public.route_tables}"
}
output "private_subnet_ids" {
value = "${module.private.subnet_ids}"
}
output "private_route_tables" {
value = "${module.private.route_tables}"
}