-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpc.tf
154 lines (130 loc) · 4.24 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Setup management VPC for infrastructure services
//
# Make this optional
# Only environment accounts need this
# Keep same ip pattern in all accounts
# TODO:
# add tags to subnets, route tables: public|private
# avail zones should be a variable or lookup
# variable region
locals {
tags = {
Component = "${var.component}"
Environment = "${var.environment}"
#Name = "${var.account_name}-${var.environment}"
Product = "${var.product}"
Service = "${var.service}"
Team = "${var.team}"
Terraform = true
TerraformDir = "${basename(path.root)}"
}
}
module "vpc" {
source = "cloudposse/vpc/aws"
version = "0.3.6"
namespace = "${var.organization}"
stage = "${replace(var.account_name, "/.*-/", "")}"
name = "${var.environment}"
cidr_block = "${var.vpc_cidr}"
#tags = "${map("Environment", "${var.environment}")}"
tags = "${local.tags}"
providers = {
aws = "aws.member"
}
}
# TODO: look into just specifing number of subnets
locals {
availability_zones = ["${formatlist("${var.aws_region}%s", var.availability_zones)}"]
}
module "dynamic_subnets" {
source = "git::https://github.com/appzen-oss/terraform-aws-dynamic-subnets.git?ref=master"
#source = "../terraform-aws-dynamic-subnets"
#source = "cloudposse/dynamic-subnets/aws"
#version = "0.3.8"
namespace = "${var.organization}"
stage = "${replace(var.account_name, "/.*-/", "")}"
name = "${var.environment}"
region = "${var.aws_region}"
availability_zones = ["${local.availability_zones}"]
vpc_id = "${module.vpc.vpc_id}"
igw_id = "${module.vpc.igw_id}"
cidr_block = "${module.vpc.vpc_cidr_block}"
private_acl_cidr = "${var.private_acl_cidr}"
tags = "${local.tags}"
providers = {
aws = "aws.member"
}
}
/*
# Unsure why ERROR with aws_vpc_endpoint.s3_gateway: Error creating VPC Endpoint: InvalidVpcId.NotFound: The Vpc Id vpc-026a1c94071167d32 does not exist
# S3 endpoint
resource "aws_vpc_endpoint" "s3_gateway" {
vpc_id = "${module.vpc.vpc_id}"
service_name = "com.amazonaws.${var.aws_region}.s3"
#route_table_ids = ["${module.dynamic_subnets.private_route_table_ids}"]
vpc_endpoint_type = "Gateway"
# policy = ""
tags = "${merge(local.tags, map("Name", "${lookup(local.tags, "Name", "${var.account_name}-${var.environment}")}-s3-gateway"))}"
}
*/
/**/
/*
data "aws_availability_zones" "available" {}
resource "aws_vpc" "vpc" {
provider = "aws.member"
cidr_block = "${var.vpc_cidr}"
enable_dns_support = true
enable_dns_hostnames = true
tags {
Name = "${var.vpc_name}"
}
lifecycle {
create_before_destroy = true
}
}
locals {
num_azs = "3" # -> 4 ?
azs_string = "${join(",", slice(data.aws_availability_zones.available.names, 0, local.num_azs))}"
}
module "public_subnet" {
source = "git::ssh://[email protected]/appzeneng/terrazen_library.git//Modules/public_subnet"
name = "${var.vpc_name}-public-subnet"
vpc_id = "${aws_vpc.vpc.id}"
cidrs = "${var.public_subnet_cidrs}"
azs = "${local.azs_string}"
providers = {
aws = "aws.member"
}
}
resource "aws_eip" "nat" {
provider = "aws.member"
count = "${local.num_azs}"
vpc = true
lifecycle {
create_before_destroy = true
}
}
resource "aws_nat_gateway" "nat" {
provider = "aws.member"
count = "${local.num_azs}"
allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
subnet_id = "${element(split(",", module.public_subnet.subnet_ids), count.index)}"
lifecycle {
create_before_destroy = true
}
}
module "networking_private_subnet" {
source = "git::ssh://[email protected]/appzeneng/terrazen_library.git//Modules/private_subnet"
#source = "../terrazen_library//Modules/private_subnet"
name = "${var.vpc_name}-private-subnet"
vpc_id = "${aws_vpc.vpc.id}"
cidrs = "${var.private_subnet_cidrs}"
azs = "${local.azs_string}"
nat_gateway_ids = "${join(",", aws_nat_gateway.nat.*.id)}"
private_route_cidr = "${var.private_route_cidr}"
providers = {
aws = "aws.member"
}
}
/**/