Skip to content

Commit 8b96788

Browse files
authored
Merge pull request #55 from FairwindsOps/0.12-migration
0.12 migration
2 parents 54f1c41 + b7dd2fb commit 8b96788

12 files changed

+181
-125
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
TEMPDIR := $(shell mktemp -d)
55

6-
TF_VERSION = 0.11.8
6+
TF_VERSION = 0.12.9
77
TF_PLATFORM = darwin
88
SHELL := /bin/bash
99

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This Terraform module creates a configurable general purpose [Amazon Web Services VPC](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Introduction.html). The module offers an opinionated but flexible network topography geared towards general purpose situations with separate public and private subnets. Each VPC can be configured to support one to four availability zones. Private subnet [NAT](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat.html) can be configured via [NAT Gateways](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html). A single [Internet Gateway](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html) is created to provide public routing for public subnets. The module does not configure a bastion or VPN instance for private subnet instance access.
44

5-
This module has been tested with Terraform version 0.11.8
5+
This module has been tested with Terraform version 0.12.9
66

77
## Example VPC Layout: 3 AZ's
88

@@ -14,14 +14,14 @@ This module has been tested with Terraform version 0.11.8
1414

1515
```
1616
module "vpc" {
17-
source = "git::ssh://[email protected]/FairwindsOps/terraform-vpc.git?ref=2.0.2"
17+
source = "git::ssh://[email protected]/reactiveops/terraform-vpc.git?ref=3.0.0"
1818
19-
aws_region = "${var.aws_region}"
19+
aws_region = var.aws_region
2020
21-
az_count = "${var.az_count}"
22-
aws_azs = "${var.aws_azs}"
21+
az_count = var.az_count
22+
aws_azs = var.aws_azs
2323
24-
vpc_cidr_base = "${var.vpc_cidr_base}"
24+
vpc_cidr_base = var.vpc_cidr_base
2525
2626
}
2727
```

eip.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#limitations under the License.
1414

1515
resource "aws_eip" "mod_nat" {
16-
count = "${((var.multi_az_nat_gateway * var.az_count) + (var.single_nat_gateway * 1))}"
17-
tags = "${var.global_tags}"
18-
vpc = true
16+
count = var.multi_az_nat_gateway * var.az_count + var.single_nat_gateway * 1
17+
tags = var.global_tags
18+
vpc = true
1919
}
2020

2121
output "aws_eip_nat_ips" {
22-
value = ["${aws_eip.mod_nat.*.public_ip}"]
22+
value = [aws_eip.mod_nat.*.public_ip]
2323
}
24+

internet-gateway.tf

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
#limitations under the License.
1414

1515
resource "aws_internet_gateway" "default" {
16-
vpc_id = "${aws_vpc.default.id}"
17-
tags = "${merge(var.global_tags,
18-
map("Name", "${var.aws_vpc_name}"),
19-
var.internet_gateway_tags)}"
20-
16+
vpc_id = aws_vpc.default.id
17+
tags = merge(
18+
var.global_tags,
19+
{
20+
"Name" = var.aws_vpc_name
21+
},
22+
var.internet_gateway_tags,
23+
)
2124
}
25+

nat-gateway.tf

+15-10
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
#limitations under the License.
1414

1515
resource "aws_nat_gateway" "nat_gateway" {
16-
count = "${((var.multi_az_nat_gateway * var.az_count) + (var.single_nat_gateway * 1))}"
17-
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
18-
allocation_id = "${element(aws_eip.mod_nat.*.id, count.index)}"
19-
tags = "${var.global_tags}"
20-
depends_on = ["aws_internet_gateway.default","aws_eip.mod_nat","aws_subnet.public"]
21-
lifecycle = {
22-
ignore_changes = ["tags"]
23-
}
16+
count = var.multi_az_nat_gateway * var.az_count + var.single_nat_gateway * 1
17+
subnet_id = element(aws_subnet.public.*.id, count.index)
18+
allocation_id = element(aws_eip.mod_nat.*.id, count.index)
19+
tags = var.global_tags
20+
depends_on = [
21+
aws_internet_gateway.default,
22+
aws_eip.mod_nat,
23+
aws_subnet.public,
24+
]
25+
lifecycle {
26+
ignore_changes = [tags]
27+
}
2428
}
2529

2630
output "aws_nat_gateway_count" {
27-
value = "${length(aws_nat_gateway.nat_gateway.*.id)}"
31+
value = length(aws_nat_gateway.nat_gateway.*.id)
2832
}
2933

3034
output "aws_nat_gateway_ids" {
31-
value = ["${aws_nat_gateway.nat_gateway.*.id}"]
35+
value = [aws_nat_gateway.nat_gateway.*.id]
3236
}
37+

route-table.tf

+29-19
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,53 @@
1212
#See the License for the specific language governing permissions and
1313
#limitations under the License.
1414

15-
1615
# Routing table for public subnets
1716
resource "aws_route_table" "public" {
18-
vpc_id = "${aws_vpc.default.id}"
19-
tags = "${merge(var.global_tags,
20-
map("Name", "public"),
21-
var.public_route_table_tags)}"
17+
vpc_id = aws_vpc.default.id
18+
tags = merge(
19+
var.global_tags,
20+
{
21+
"Name" = "public"
22+
},
23+
var.public_route_table_tags,
24+
)
2225
}
2326

2427
output "aws_route_table_public_ids" {
25-
value = ["${aws_route_table.public.id}"]
28+
value = [aws_route_table.public.id]
2629
}
2730

2831
resource "aws_route" "public_internet_gateway" {
29-
route_table_id = "${aws_route_table.public.id}"
32+
route_table_id = aws_route_table.public.id
3033
destination_cidr_block = "0.0.0.0/0"
31-
gateway_id = "${aws_internet_gateway.default.id}"
34+
gateway_id = aws_internet_gateway.default.id
3235
}
3336

34-
3537
# Routing table for private subnets
3638
resource "aws_route_table" "private" {
37-
count = "${((var.multi_az_nat_gateway * var.az_count) + (var.single_nat_gateway * 1))}"
38-
vpc_id = "${aws_vpc.default.id}"
39-
tags = "${merge(var.global_tags,
40-
map("Name", "private_az${(count.index +1)}"),
41-
var.private_route_table_tags)}"
39+
count = var.multi_az_nat_gateway * var.az_count + var.single_nat_gateway * 1
40+
vpc_id = aws_vpc.default.id
41+
tags = merge(
42+
var.global_tags,
43+
{
44+
"Name" = "private_az${count.index + 1}"
45+
},
46+
var.private_route_table_tags,
47+
)
4248
}
4349

4450
output "aws_route_table_private_ids" {
45-
value = ["${aws_route_table.private.*.id}"]
51+
value = [aws_route_table.private.*.id]
4652
}
4753

4854
resource "aws_route" "private_nat_gateway" {
49-
count = "${((var.multi_az_nat_gateway * var.az_count) + (var.single_nat_gateway * 1))}"
50-
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
51-
nat_gateway_id = "${element(aws_nat_gateway.nat_gateway.*.id, count.index)}"
55+
count = var.multi_az_nat_gateway * var.az_count + var.single_nat_gateway * 1
56+
route_table_id = element(aws_route_table.private.*.id, count.index)
57+
nat_gateway_id = element(aws_nat_gateway.nat_gateway.*.id, count.index)
5258
destination_cidr_block = "0.0.0.0/0"
53-
depends_on = ["aws_route_table.private","aws_nat_gateway.nat_gateway"]
59+
depends_on = [
60+
aws_route_table.private,
61+
aws_nat_gateway.nat_gateway,
62+
]
5463
}
64+

subnets.tf

+61-44
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,98 @@
1717
#
1818

1919
resource "aws_subnet" "admin" {
20-
count = "${var.az_count}"
21-
vpc_id = "${aws_vpc.default.id}"
22-
cidr_block = "${var.vpc_cidr_base}${lookup(var.admin_subnet_cidrs, format("zone%d", count.index))}"
23-
availability_zone = "${element(split(", ", var.aws_azs), count.index)}"
24-
tags = "${merge(var.global_tags,
25-
map("Name", "admin_az${(count.index +1)}"),
26-
var.admin_subnet_tags)}"
20+
count = var.az_count
21+
vpc_id = aws_vpc.default.id
22+
cidr_block = "${var.vpc_cidr_base}${var.admin_subnet_cidrs[format("zone%d", count.index)]}"
23+
availability_zone = element(split(", ", var.aws_azs), count.index)
24+
tags = merge(
25+
var.global_tags,
26+
{
27+
"Name" = "admin_az${count.index + 1}"
28+
},
29+
var.admin_subnet_tags,
30+
)
2731
}
2832

2933
output "aws_subnet_admin_ids" {
30-
value = ["${aws_subnet.admin.*.id}"]
34+
value = [aws_subnet.admin.*.id]
3135
}
3236

3337
resource "aws_route_table_association" "private_admin" {
34-
count = "${var.az_count}"
35-
subnet_id = "${element(aws_subnet.admin.*.id, count.index)}"
36-
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
38+
count = var.az_count
39+
subnet_id = element(aws_subnet.admin.*.id, count.index)
40+
route_table_id = element(aws_route_table.private.*.id, count.index)
3741
}
3842

3943
resource "aws_subnet" "public" {
40-
count = "${var.az_count}"
41-
vpc_id = "${aws_vpc.default.id}"
42-
cidr_block = "${var.vpc_cidr_base}${lookup(var.public_subnet_cidrs, format("zone%d", count.index))}"
43-
availability_zone = "${element(split(", ", var.aws_azs), count.index)}"
44-
tags = "${merge(var.global_tags,
45-
map("Name", "public_az${(count.index +1)}"),
46-
var.public_subnet_tags)}"
44+
count = var.az_count
45+
vpc_id = aws_vpc.default.id
46+
cidr_block = "${var.vpc_cidr_base}${var.public_subnet_cidrs[format("zone%d", count.index)]}"
47+
availability_zone = element(split(", ", var.aws_azs), count.index)
48+
tags = merge(
49+
var.global_tags,
50+
{
51+
"Name" = "public_az${count.index + 1}"
52+
},
53+
var.public_subnet_tags,
54+
)
4755
}
4856

4957
output "aws_subnet_public_ids" {
50-
value = ["${aws_subnet.public.*.id}"]
58+
value = [aws_subnet.public.*.id]
5159
}
5260

5361
resource "aws_route_table_association" "public_public" {
54-
count = "${var.az_count}"
55-
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
56-
route_table_id = "${aws_route_table.public.id}"
62+
count = var.az_count
63+
subnet_id = element(aws_subnet.public.*.id, count.index)
64+
route_table_id = aws_route_table.public.id
5765
}
5866

5967
resource "aws_subnet" "private_prod" {
60-
count = "${var.az_count}"
61-
vpc_id = "${aws_vpc.default.id}"
62-
cidr_block = "${var.vpc_cidr_base}${lookup(var.private_prod_subnet_cidrs, format("zone%d", count.index))}"
63-
availability_zone = "${element(split(", ", var.aws_azs), count.index)}"
64-
tags = "${merge(var.global_tags,
65-
map("Name", "private_prod_az${(count.index +1)}"),
66-
var.private_prod_subnet_tags)}"
68+
count = var.az_count
69+
vpc_id = aws_vpc.default.id
70+
cidr_block = "${var.vpc_cidr_base}${var.private_prod_subnet_cidrs[format("zone%d", count.index)]}"
71+
availability_zone = element(split(", ", var.aws_azs), count.index)
72+
tags = merge(
73+
var.global_tags,
74+
{
75+
"Name" = "private_prod_az${count.index + 1}"
76+
},
77+
var.private_prod_subnet_tags,
78+
)
6779
}
6880

6981
output "aws_subnet_private_prod_ids" {
70-
value = ["${aws_subnet.private_prod.*.id}"]
82+
value = [aws_subnet.private_prod.*.id]
7183
}
7284

7385
resource "aws_route_table_association" "private_private_prod" {
74-
count = "${var.az_count}"
75-
subnet_id = "${element(aws_subnet.private_prod.*.id, count.index)}"
76-
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
86+
count = var.az_count
87+
subnet_id = element(aws_subnet.private_prod.*.id, count.index)
88+
route_table_id = element(aws_route_table.private.*.id, count.index)
7789
}
7890

7991
resource "aws_subnet" "private_working" {
80-
count = "${var.az_count}"
81-
vpc_id = "${aws_vpc.default.id}"
82-
cidr_block = "${var.vpc_cidr_base}${lookup(var.private_working_subnet_cidrs, format("zone%d", count.index))}"
83-
availability_zone = "${element(split(", ", var.aws_azs), count.index)}"
84-
tags = "${merge(var.global_tags,
85-
map("Name", "private_working_az${(count.index +1)}"),
86-
var.private_working_subnet_tags)}"
92+
count = var.az_count
93+
vpc_id = aws_vpc.default.id
94+
cidr_block = "${var.vpc_cidr_base}${var.private_working_subnet_cidrs[format("zone%d", count.index)]}"
95+
availability_zone = element(split(", ", var.aws_azs), count.index)
96+
tags = merge(
97+
var.global_tags,
98+
{
99+
"Name" = "private_working_az${count.index + 1}"
100+
},
101+
var.private_working_subnet_tags,
102+
)
87103
}
88104

89105
output "aws_subnet_private_working_ids" {
90-
value = ["${aws_subnet.private_working.*.id}"]
106+
value = [aws_subnet.private_working.*.id]
91107
}
92108

93109
resource "aws_route_table_association" "private_private_working" {
94-
count = "${var.az_count}"
95-
subnet_id = "${element(aws_subnet.private_working.*.id, count.index)}"
96-
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
110+
count = var.az_count
111+
subnet_id = element(aws_subnet.private_working.*.id, count.index)
112+
route_table_id = element(aws_route_table.private.*.id, count.index)
97113
}
114+

tests/provider.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ variable "aws_access_key" {}
22
variable "aws_secret_key" {}
33

44
provider "aws" {
5-
access_key = "${var.aws_access_key}"
6-
secret_key = "${var.aws_secret_key}"
7-
region = "${var.aws_region}"
5+
access_key = var.aws_access_key
6+
secret_key = var.aws_secret_key
7+
region = var.aws_region
88
}

0 commit comments

Comments
 (0)