Skip to content

Commit bc39060

Browse files
committed
streamlining the module documentation and upgrading the example
1 parent fd7a148 commit bc39060

File tree

5 files changed

+49
-180
lines changed

5 files changed

+49
-180
lines changed

README.md

Lines changed: 11 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ The subnets are dished out across availability zones in a round robin fashion. Y
3030
The most common use case is to specify the VPC Cidr, the number of public and private subnets.
3131

3232

33-
## Run the Examples | VPC Network
34-
35-
You can test-drive this VPC and su
36-
33+
---
3734

38-
## [Examples and Tests](test-vpc.network)
3935

40-
**[This terraform module has runnable example integration tests](test-vpc.network)**. Read the instructions on how to clone the project and run the integration tests.
36+
## [Run the Example](https://github.com/devops4me/terraform-aws-vpc-network/tree/master/example)
4137

38+
You can run the example to see this module create a number of VPCs with varying attributes such as the number of private/public subnets.
4239

4340
## Module Inputs
4441

@@ -48,9 +45,13 @@ You can test-drive this VPC and su
4845
| **in_num_private_subnets** | Integer | Number of private subnets to create across availability zones | 3 |
4946
| **in_num_public_subnets** | Integer | Number of public subnets to create across availability zones. If one or more an internet gateway and route to the internet will be created regardless of the value of the in_create_gateway boolean variable. | 3 |
5047
| **in_create_gateway** | Boolean | If set to true an internet gateway and route will be created even when no public subnets are requested. | false |
51-
| **in_subnets_max** | Integer | 2 to the power of this is the max number of carvable subnets | 4 (16 subnets) |
48+
| **[in_subnets_max](https://www.devopswiki.co.uk/vpc/network-cidr)** | Integer | 2 to the power of this is the max number of carvable subnets | 4 (16 subnets) |
5249
| **in_ecosystem** | String | the class name of the ecosystem being built here | eco-system |
5350

51+
52+
---
53+
54+
5455
## subnets into availability zones | round robin
5556

5657
You can create **more or less subnets** than there are availability zones in the VPC's region. You can ask for **6 private subnets** in a **3 availability zone region**. The subnets are distributed into the availability zones like dealing a deck of cards.
@@ -62,51 +63,9 @@ Every permutation of subnets and availability zones is catered for so you can de
6263
- that **no subnets** (public and/or private) get created
6364
- nothing - and each availability zone will get one public and one private subnet
6465

65-
---
66-
67-
## in_subnets_max | variable
68-
69-
This variable defines the maximum number of subnets that can be carved out of your VPC (you do not need to use them all). It then combines with the VPC Cidr to define the number of **addresses available in each subnet's** pool.
70-
71-
### 2<sup>32 - (in_vpc_cidr + in_subnets_max)</sup> = number of subnet addresses
72-
73-
A **vpc_cidr of 21 (eg 10.42.0.0/21)** and **subnets_max of 5** gives a pool of **2<sup>32-(21+5)</sup> = 64 addresses** in each subnet. (Note it is actually 2 less). We can carve out **2<sup>5</sup> = 32 subnets** as in_subnets_max is 5.
74-
75-
### Dividing VPC Addresses into Subnet Blocks
76-
77-
| vpc cidr | subnets max | number of addresses per subnet | max subnets | vpc addresses total |
78-
|:---------:|:-----------:|:------------------------------------------------------- |:--------------------------- |:------------------------------------ |
79-
| /16 | 6 | 2<sup>32-(16+6)</sup> = 2<sup>10</sup> = 1024 addresses | 2<sup>6</sup> = 64 subnets | 2<sup>32-16</sup> = 65,536 addresses |
80-
| /16 | 4 | 2<sup>32-(16+4)</sup> = 2<sup>12</sup> = 4096 addresses | 2<sup>4</sup> = 16 subnets | 2<sup>32-16</sup> = 65,536 addresses |
81-
| /20 | 8 | 2<sup>32-(20+8)</sup> = 2<sup>4</sup> = 16 addresses | 2<sup>8</sup> = 256 subnets | 2<sup>32-20</sup> = 4,096 addresses |
82-
| /20 | 2 | 2<sup>32-(20+2)</sup> = 2<sup>10</sup> = 1024 addresses | 2<sup>2</sup> = 4 subnets | 2<sup>32-20</sup> = 4,096 addresses |
83-
84-
Check the below formula holds true for every row in the above table.
85-
86-
<pre><code>addresses per subnet * number of subnets = total available VPC addresses</code></pre>
8766

8867
---
8968

90-
## in_subnets_max | in_vpc_cidr
91-
92-
**How many addresses will each subnet contain** and **how many subnets can be carved out of the VPC's IP address pool**? These questions are answered by the vpc_cidr and the subnets_max variable.
93-
94-
The VPC Cidr default is 16 giving 65,536 total addresses and the subnets max default is 4 so **16 subnets** can be carved out with each subnet ready to issue 4,096 addresses.
95-
96-
Clearly the addresses per subnet multiplied by the number of subnets cannot exceed the available VPC address pool. To keep your powder dry, ensure **in_vpc_cidr plus in_subnets_max does not exceed 31**.
97-
98-
## number of subnets constraint
99-
100-
It is unlikely **in_num_private_subnets + in_num_public_subnets** will exceed the maximum number of subnets that can be carved out of the VPC. Usually it is a lot less but be prudent and ensure that **in_num_private_subnets + in_num_public_subnets < 2<sup>in_subnets_max</sup>**
101-
102-
103-
## subnet cidr blocks | cidrsubnet function
104-
105-
You do not need to specify each subnet's CIDR block because they are calculated by passing the VPC Cidr (in_vpc_cidr), the Subnets Max (in_subnets_max) and the present subnet's index (count.index) into Terraform's **cidrsubnet function**.
106-
107-
The behaviour of Terraform's **cidrsubnet function** is involved but slightly outside the scope of this VPC/Subnet module document. Read **[Understanding the Terraform Cidr Subnet Function](http://www.devopswiki.co.uk/wiki/devops/terraform/terraform-cidrsubnet-function)** for a fuller coverage of cidrsubnet's behaviour.
108-
109-
---
11069

11170
## internet gateway and route
11271

@@ -115,6 +74,9 @@ This module **senses** whether you wish to **create an internet gateway** (in) a
11574
If **in_num_public_subnets is greater than zero** it automatically creates an internet gateway and a route along with the public subnets. This behaviour can be switched off by setting **in_ignore_public** to true.
11675

11776

77+
---
78+
79+
11880
## output variables
11981

12082
Here are the most popular **output variables** exported from this VPC and subnet creating module.
@@ -126,81 +88,3 @@ Here are the most popular **output variables** exported from this VPC and subnet
12688
**out_subnet_ids** | List of Strings | [ "subnet-545123498798345", "subnet-83507325124987" ] | list of **all private and public** subnet ids
12789
**out_private_subnet_ids** | List of Strings | [ "subnet-545123498798345", "subnet-83507325124987" ] | list of **private** subnet ids
12890
**out_public_subnet_ids** | List of Strings | [ "subnet-945873408204034", "subnet-8940202943031" ] | list of **public** subnet ids
129-
130-
## vpc subnets | module tests
131-
132-
**[This terraform module has runnable example integration tests](test-vpc.network)**. Read the instructions on how to clone the project and run the unit tests.
133-
134-
## vpc subnets | version | v0.1.0002
135-
136-
**v0.1.0002** is the current stable version of this Terraform module. To avoid say **testing with one version and going into production with another** you can employ the ref tag as shown below.
137-
138-
module vpc-network
139-
{
140-
source = "github.com/devops4me/terraform-aws-vpc-network?ref=v0.1.0002"
141-
in_vpc_cidr = "10.245.0.0/16"
142-
in_num_private_subnets = 6
143-
in_num_public_subnets = 3
144-
in_ecosystem = "kubernetes-cluster"
145-
}
146-
147-
Or you can use the version parameter that is more explicit and affords you the opportunity to detail a **[range of versions that are acceptable](https://www.terraform.io/docs/modules/usage.html)** by employing **version constraint syntax**.
148-
149-
module vpc-network
150-
{
151-
source = "github.com/devops4me/terraform-aws-vpc-network"
152-
version = "~> v0.1.0"
153-
in_vpc_cidr = "10.123.0.0/16"
154-
in_ecosystem = "kubernetes-cluster"
155-
}
156-
157-
158-
## Infrastructure Tests | Dockerfile
159-
160-
The quality and viability of this Terraform module is assured via a continuous integration process.
161-
162-
### See 4 Yourself | docker run
163-
164-
Why not see 4 yourself by building and running the test. You simply pass in **[[IAM user credentials]](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html)** as **environment variables** to the docker container and Terraform will use these credentials to create the infrastructure.
165-
166-
```bash
167-
git clone https://github.com/devops4me/terraform-aws-vpc-network
168-
cd terraform-aws-vpc-network
169-
docker build -t vpc.network.image .
170-
```
171-
172-
### The AWS 5 VPC's Limit
173-
174-
The default VPC limit is just 5 and this test needs at least 10 so take yourself to the support section and request extension to say 25 - it will be done automatically in less than 5 minutes.
175-
176-
## Test Automation | Jenkinsfile
177-
178-
179-
### Contributing
180-
181-
Bug reports and pull requests are welcome on GitHub at the https://github.com/devops4me/terraform-aws-vpc-network page. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
182-
183-
License
184-
-------
185-
186-
MIT License
187-
Copyright (c) 2006 - 2014
188-
189-
Permission is hereby granted, free of charge, to any person obtaining
190-
a copy of this software and associated documentation files (the
191-
'Software'), to deal in the Software without restriction, including
192-
without limitation the rights to use, copy, modify, merge, publish,
193-
distribute, sublicense, and/or sell copies of the Software, and to
194-
permit persons to whom the Software is furnished to do so, subject to
195-
the following conditions:
196-
197-
The above copyright notice and this permission notice shall be
198-
included in all copies or substantial portions of the Software.
199-
200-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
201-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
202-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
203-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
204-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
205-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
206-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

example/Dockerfile

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,4 @@
1-
2-
# --->
3-
# ---> Going with Ubuntu's Long Term Support (lts)
4-
# ---> version which is currently 18.04.
5-
# --->
6-
7-
FROM ubuntu:18.04
8-
9-
10-
# --->
11-
# ---> Assume the root user and install git, terraform,
12-
# ---> a time zone manipulator and pythonic tools for
13-
# ---> testing the AWS based infrastructure.
14-
# --->
15-
16-
USER root
17-
18-
RUN apt-get update && apt-get --assume-yes install -qq -o=Dpkg::Use-Pty=0 \
19-
curl \
20-
git \
21-
unzip
22-
23-
24-
# --->
25-
# ---> Install the Terraform binary.
26-
# --->
27-
28-
RUN \
29-
curl -o /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.12.8/terraform_0.12.8_linux_amd64.zip && \
30-
unzip /tmp/terraform.zip -d /usr/local/bin && \
31-
chmod a+x /usr/local/bin/terraform && \
32-
rm /tmp/terraform.zip && \
33-
terraform --version
34-
35-
36-
USER ubuntu
37-
WORKDIR /home/ubuntu
1+
FROM hashicorp/terraform:light
2+
RUN mkdir -p /terraform-work
3+
WORKDIR /terraform-work
4+
VOLUME /terraform-work

example/README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11

2-
# Example | Creating a VPC Network
2+
# Example | Create an AWS VPC Network
33

44
This example creates a VPC, subnets and the networking backbone to allow traffic to be routed in and also routed out to service endpoints on the internet. Let's first use docker then do the same thing with terraform installed on your machine.
55

66

77
## Docker | Create VPC Networks
88

9-
With docker, you need not worry about which Terraform version is installed on your machine. All you need is docker and your AWS access credentials.
9+
With docker, you need not worry about which Terraform version is installed on your machine. All you need are your AWS access credentials.
10+
1011

1112
```
12-
```
13+
docker build --rm --no-cache --tag devops4me/vpc-network .
14+
15+
### This Actually Works (But the next problem is - CAN WE DESTROY)
16+
### ALSO this prompts - we need to add -auto-approve to the docker file
17+
docker run -i -e AWS_DEFAULT_REGION=eu-west-1 -e AWS_ACCESS_KEY_ID=XXXXXXXXXXXXX -e AWS_SECRET_ACCESS_KEY=XXXXXXX -e TF_VAR_in_role_arn=ZZZZZZZZZZZZ -t devops4me/vpc-network apply
18+
19+
20+
21+
22+
23+
24+
docker run -i -t devops4me/vpc-network \
25+
--env AWS_DEFAULT_REGION=eu-west-1 apply
26+
1327
14-
This **[Jenkinsfile](example/Jenkinsfile)** is used to continuously integrate this module thus guaranteeing correctness and reusability. Ensure you pin the (semantic) version of this module to avoid breaking change failures as it evolves both its functionality and keeps up with Terraform's rapid developmental pace.
1528
16-
For even more peace of mind you can clone this project and use your own continuous integration facilities. Send a pull request for any changes that will benefit the Terraform community.
29+
git clone github.com/devops4me/terraform-aws-vpc-network
30+
cd terraform-aws-vpc-network/example
31+
docker build --rm --no-cache --tag devops4me/vpc-network .
32+
docker images
33+
docker run \
34+
--detach \
35+
--name vm.vpc \
36+
--network host \
37+
--volume ${PWD}:/home/ubuntu \
38+
devops4me/vpc-network;
39+
```
1740

1841

1942
## How to Run the Example
@@ -50,15 +73,7 @@ If you are using an IAM role as the AWS access mechanism then pass it as in_role
5073
Individuals and small businesses who don't have hundreds of AWS accounts can omit the variable and thanks to dynamic assignment the assume_role block will cease to exist.
5174

5275

53-
docker run \
54-
--detach \
55-
--name vm.vpc-network \
56-
--network host \
57-
--volume ${PWD}:/home/ubuntu \
58-
postgres:11.2;
59-
60-
61-
76+
### The AWS 5 VPC's Limit
6277

63-
## Related Modules
78+
The default VPC limit is just 5 and this test needs at least 10 so take yourself to the support section and request extension to say 25 - it will be done automatically in less than 5 minutes.
6479

example/vpc.network-example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ locals {
120120
ecosystem_name = "virtual-net"
121121
timestamp = formatdate( "YYMMDDhhmmss", timestamp() )
122122
date_time = formatdate( "EEEE, DD-MMM-YY hh:mm:ss ZZZ", timestamp() )
123-
description = "was created by jenkins on ${ local.date_time }."
123+
description = "was created by me on ${ local.date_time }."
124124
}

vpc.network-variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ variable in_create_private_gateway {
7474

7575
variable in_ecosystem {
7676
description = "Creational stamp binding all infrastructure components created on behalf of this ecosystem instance."
77+
default = "vpc-network"
7778
}
7879

7980

@@ -83,6 +84,7 @@ variable in_ecosystem {
8384

8485
variable in_timestamp {
8586
description = "A timestamp for resource tags in the format ymmdd-hhmm like 80911-1435"
87+
default = local.timestamp
8688
}
8789

8890

@@ -92,6 +94,7 @@ variable in_timestamp {
9294

9395
variable in_description {
9496
description = "Ubiquitous note detailing who, when, where and why for every infrastructure component."
97+
default = "This VPC network was created on ${ local.date_time }."
9598
}
9699

97100

0 commit comments

Comments
 (0)