Skip to content

Commit 3460feb

Browse files
authored
Refactor, added ec2 instance connect endpoint and added example for bootstrap routing (#2)
* refactored and added ec2 instance connect endpoint * adjusted simple example * added bootstrap routing example * fmt * docs update
1 parent acd8b03 commit 3460feb

File tree

19 files changed

+402
-49
lines changed

19 files changed

+402
-49
lines changed

.config/header.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ managed within the footer file
5454
module "simple_vpc" {
5555
5656
source = "ishuar/vpc/aws"
57-
version = "~> 1.0"
57+
version = "~> 2.0"
5858
59-
prefix = "simple"
60-
env = "dev"
61-
region = eu-central-1
62-
cidr_block = "10.1.0.0/16"
59+
prefix = "simple"
60+
env = "dev"
61+
region = "eu-central-1"
62+
cidr_block = "10.1.0.0/16"
6363
6464
## Subnets
65-
public_subnet = [
65+
public_subnets = [
6666
{
6767
name = "subnet01"
6868
cidr_block = "10.1.1.0/24"
@@ -71,10 +71,11 @@ module "simple_vpc" {
7171
# {
7272
# name = "subnet02"
7373
# cidr_block = "10.1.3.0/24"
74+
# availability_zone = "eu-central-1b"
7475
# }
7576
]
7677
77-
private_subnet = [
78+
private_subnets = [
7879
{
7980
name = "subnet01"
8081
cidr_block = "10.1.2.0/24"
@@ -83,6 +84,7 @@ module "simple_vpc" {
8384
# {
8485
# name = "subnet02"
8586
# cidr_block = "10.1.4.0/24"
87+
# availability_zone = "eu-central-1b"
8688
# }
8789
]
8890
}
@@ -94,5 +96,6 @@ module "simple_vpc" {
9496
Examples are availabe in `examples` directory.
9597

9698
- [simple](/example/simple)
99+
- [bootstrap-routing](/example/bootstrap-routing)
97100

98101
## Submodule

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,30 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
57

8+
## [v2.0.0]
9+
10+
### Breaking
11+
12+
Change in variable definitions, Update them as following.
13+
14+
- From `public_subnet` to `public_subnets`
15+
- From `private_subnet` to `private_subnets`
16+
- From `private_routes` to `private_subnet_routes`
17+
- From `public_routes` to `public_subnet_routes`
18+
19+
### Features
20+
21+
- Default route to Internet gateway in public Subnets.
22+
- Optional Configurable custom routes in public subnets.
23+
- Optional EC2 Instance Connect Endpoint in the first private subnet.
24+
25+
### Added
26+
27+
- Example for VPC with bootstrap routing.
28+
- Update Docs
629
## [v1.0.0]
730

831
### Added

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
.Phony: docs validate
1+
.Phony: docs validate format fmt
22

33
docs:
4-
terraform-docs .
4+
terraform-docs .
5+
6+
format:
7+
terraform fmt -recursive
8+
9+
fmt:format

README.md

Lines changed: 20 additions & 11 deletions
Large diffs are not rendered by default.

bootstrap-routing.tf

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
21
locals {
3-
enable_private_routing = var.create_private_route_table
4-
route_to_igw = length(var.public_subnet) > 0 && var.use_created_igw_for_public_routing
2+
route_to_igw = length(var.public_subnets) > 0 && var.use_created_igw_for_public_routing
53
}
64

75
resource "aws_route_table" "private" {
8-
count = local.enable_private_routing ? 1 : 0
6+
count = var.create_private_route_table ? 1 : 0
97

108
vpc_id = aws_vpc.this.id
119
tags = merge(var.tags,
@@ -15,7 +13,7 @@ resource "aws_route_table" "private" {
1513
}
1614

1715
resource "aws_route_table" "public" {
18-
count = length(var.public_subnet) > 0 ? 1 : 0
16+
count = length(var.public_subnets) > 0 ? 1 : 0
1917

2018
vpc_id = aws_vpc.this.id
2119
tags = merge(var.tags,
@@ -25,7 +23,7 @@ resource "aws_route_table" "public" {
2523
}
2624

2725
resource "aws_route" "private" {
28-
for_each = local.enable_private_routing ? var.private_routes : {}
26+
for_each = var.create_private_route_table ? var.private_subnet_routes : {}
2927

3028
route_table_id = aws_route_table.private[0].id
3129
destination_cidr_block = each.value.destination_cidr_block
@@ -39,25 +37,35 @@ resource "aws_route" "private" {
3937
vpc_peering_connection_id = each.value.vpc_peering_connection_id
4038
}
4139

40+
resource "aws_route" "public_subnet_default_to_igw" {
41+
count = local.route_to_igw ? 1 : 0
42+
43+
route_table_id = aws_route_table.public[0].id
44+
destination_cidr_block = "0.0.0.0/0"
45+
gateway_id = aws_internet_gateway.this[0].id
46+
}
47+
4248
resource "aws_route" "public" {
43-
for_each = length(var.public_subnet) > 0 ? var.public_routes : {}
49+
for_each = length(var.public_subnets) > 0 ? var.public_subnet_routes : {}
4450

4551
route_table_id = aws_route_table.public[0].id
4652
destination_cidr_block = each.value.destination_cidr_block
4753
destination_prefix_list_id = each.value.destination_prefix_list_id
48-
gateway_id = local.route_to_igw ? aws_internet_gateway.this[0].id : each.value.gateway_id
49-
egress_only_gateway_id = each.value.egress_only_gateway_id
54+
network_interface_id = each.value.network_interface_id
55+
vpc_peering_connection_id = each.value.vpc_peering_connection_id
56+
transit_gateway_id = each.value.transit_gateway_id
57+
vpc_endpoint_id = each.value.vpc_endpoint_id
58+
carrier_gateway_id = each.value.carrier_gateway_id
5059
}
5160

5261
resource "aws_route_table_association" "private" {
53-
for_each = { for subnet in var.private_subnet : subnet.name => subnet if local.enable_private_routing }
62+
for_each = { for subnet in var.private_subnets : subnet.name => subnet if var.create_private_route_table }
5463
subnet_id = aws_subnet.private_subnet[(each.value.name)].id
5564
route_table_id = aws_route_table.private[0].id
5665
}
5766

5867
resource "aws_route_table_association" "public" {
59-
for_each = { for subnet in var.public_subnet : subnet.name => subnet if(length(var.public_subnet) > 0) }
68+
for_each = { for subnet in var.public_subnets : subnet.name => subnet if(length(var.public_subnets) > 0) }
6069
subnet_id = aws_subnet.public_subnet[(each.value.name)].id
6170
route_table_id = aws_route_table.public[0].id
6271
}
63-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
formatter: md
2+
header-from: "./.config/header.md"
3+
footer-from: "./.config/footer.md"
4+
output:
5+
file: README.md
6+
mode: replace
7+
template: |-
8+
{{ .Content }}
9+
sort:
10+
enabled: true
11+
by: required
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## License
2+
3+
MIT License. See [LICENSE](https://github.com/ishuar/terraform-aws-vpc/blob/main/LICENSE) for full details.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Bootstrap Routing VPC
2+
3+
Configuration in this directory creates following components
4+
5+
- VPC
6+
- Public and Private Subnets as defined.
7+
- Nat Gateway and respective Elastic IP out of module scope.
8+
- Public and Private Route Tables.
9+
- Default route to internet Gateway for Public Subnets.
10+
- Default route to nat gateway in private subnets.
11+
12+
Routing has to be adjusted as required.
13+
14+
## Usage
15+
16+
To run this example you need to execute:
17+
```bash
18+
$ terraform init
19+
$ terraform plan
20+
$ terraform apply
21+
```
22+
23+
## Destroying Resources
24+
25+
To destroy the resources created by this Terraform configuration, run the following command.
26+
27+
```bash
28+
terraform destroy -auto-approve # ignore "-auto-approve" if you don't want to autoapprove.
29+
```

examples/bootstrap-routing/.terraform.lock.hcl

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../Makefile

0 commit comments

Comments
 (0)