Skip to content

Commit 528d8b9

Browse files
authored
Merge pull request #174 from pablo19sc/main
Fixing var.azs & examples updates
2 parents 98ee2fd + 797ed62 commit 528d8b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+338
-1306
lines changed

contributing.md

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,40 @@
1-
# Developer Documentation
1+
# Contributing Guidelines
22

3-
## Outputs Methodology
3+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4+
documentation, we greatly value feedback and contributions from our community.
45

5-
This module organizes outputs by creating output collections of grouped entire resources. The benefit of this is that, most likely, attributes users want access to are already present without having to create new `output {}` for each possible attribute. The [potential] downside is that you will have to extract it yourself using HCL logic. See the [outputs.tf](https://github.com/aws-ia/terraform-aws-vpc/outputs.tf) for examples.
6+
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7+
information to effectively respond to your bug report or contribution.
68

7-
Our naming convetion attempts to make the output content clear. `route_table_attributes_by_type_by_az` is a nested map of route table resource attributes grouped by their subnet type then by the az. Example:
8-
```terraform
9-
route_table_attributes_by_type_by_az = {
10-
"private" = {
11-
"us-east-1a" = {
12-
"id" = "rtb-0e77040c0598df003"
13-
"route_table_id" = "rtb-0e77040c0598df003"
14-
"tags" = tolist([
15-
{
16-
"key" = "Name"
17-
"value" = "private-us-east-1a"
18-
},
19-
])
20-
"vpc_id" = "vpc-033e054f49409592a"
21-
}
22-
"us-east-1b" = {
23-
...
24-
}
25-
"public" = { ... }
26-
```
279

28-
## Adding new subnet types
10+
## Reporting Bugs/Feature Requests
2911

30-
*Note: All subnet types **MUST** accept both `cidrs` and `netmask` arguments.*
12+
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
3113

32-
1. Updates to variables.tf
14+
When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15+
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
3316

34-
1. Add new to `subnets` key variable validation:
17+
* A reproducible test case or series of steps
18+
* The version of our code being used
19+
* Any modifications you've made relevant to the bug
20+
* Anything unusual about your environment or deployment
3521

36-
```terraform
37-
validation {
38-
error_message = "Only valid key values \"public\", \"private\", or \"transit_gateway\"."
39-
condition = length(setsubtract(keys(var.subnets), [
40-
"public",
41-
"private",
42-
"transit_gateway",
43-
"<new type here>"
44-
])) == 0
45-
}
46-
```
4722

48-
1. Specify keys allowed in new variable type map. Copy an existing one and edit the keys to match what you expect users to input:
23+
## Contributing via Pull Requests
24+
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
4925

50-
```terraform
51-
# All var.subnets.public valid keys
52-
validation {
53-
error_message = "Invalid key in public subnets. Valid options include: \"cidrs\", \"netmask\", \"name_prefix\", \"nat_gateway_configuration\", \"tags\"."
54-
condition = length(setsubtract(keys(try(var.subnets.public, {})), [
55-
"cidrs",
56-
"netmask",
57-
"name_prefix",
58-
"nat_gateway_configuration",
59-
"tags"
60-
])) == 0
61-
}
62-
```
26+
1. You are working against the latest source on the *master* branch.
27+
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28+
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
6329

64-
1. Include in description:
30+
To send us a pull request, please:
6531

66-
```terraform
67-
**private subnet type options:**
68-
- All shared keys above
69-
- `connect_to_public_natgw` = (Optional|bool) <>
70-
```
32+
1. Fork the repository.
33+
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34+
3. Ensure local tests pass.
35+
4. Commit to your fork using clear commit messages.
36+
5. Send us a pull request, answering any default questions in the pull request interface.
37+
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
7138

72-
2. Write configuration code
73-
74-
*Note: each for_each loop must account for if a user does not want to create the particular subnet type. Follow examples from other subnet types in main.tf*
75-
76-
* Create new `aws_subnet`
77-
* Create new `aws_route_table`
78-
* Create new `aws_route_table_association`
79-
* Consider and create appropriate `aws_route`
80-
81-
82-
3. Create appropriate outputs
83-
84-
1. `output "<new subnet type>_subnet_attributes_by_az"`
85-
1. add new type to `route_table_attributes_by_type_by_az`
39+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40+
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).

examples/advanced/.header.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# VPC module - Example: Advanced VPC
2+
3+
This example builds an Amazon VPC with advanced functionality:
4+
5+
* IPv4-only VPC.
6+
* NAT gateway configured only in 1 AZ.
7+
* 4 VPC subnets - 1 public (dual-stack), 3 private (IPv4-only, dual-stack, and IPv6-only)
8+
* Subnet CIDRs calculated to optimize IPv4 adress space (variable `optimize_subnet_cidr_ranges`)
9+
* Flow logs enabled (destination Amazon S3)
10+
* Secondary IPv4 CIDR block.
11+
* Routing - egress traffic through NAT gateways in private subnets (check also the configuration on NAT gateway routing when building the subnets with secondary CIDR block).

examples/advanced/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
# VPC module - Example: Advanced VPC
3+
4+
This example builds an Amazon VPC with advanced functionality:
5+
6+
* IPv4-only VPC.
7+
* NAT gateway configured only in 1 AZ.
8+
* 4 VPC subnets - 1 public (dual-stack), 3 private (IPv4-only, dual-stack, and IPv6-only)
9+
* Subnet CIDRs calculated to optimize IPv4 adress space (variable `optimize_subnet_cidr_ranges`)
10+
* Flow logs enabled (destination Amazon S3)
11+
* Secondary IPv4 CIDR block.
12+
* Routing - egress traffic through NAT gateways in private subnets (check also the configuration on NAT gateway routing when building the subnets with secondary CIDR block).
13+
14+
## Requirements
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
19+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
20+
21+
## Providers
22+
23+
No providers.
24+
25+
## Modules
26+
27+
| Name | Source | Version |
28+
|------|--------|---------|
29+
| <a name="module_secondary_cidr_block"></a> [secondary\_cidr\_block](#module\_secondary\_cidr\_block) | ../.. | n/a |
30+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../.. | n/a |
31+
32+
## Resources
33+
34+
No resources.
35+
36+
## Inputs
37+
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region. | `string` | `"eu-west-1"` | no |
41+
42+
## Outputs
43+
44+
No outputs.
45+
<!-- END_TF_DOCS -->

examples/advanced/main.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
locals {
3+
azs = ["eu-west-1a", "eu-west-1c"]
4+
}
5+
6+
# ---------- AMAZON VPC ----------
7+
module "vpc" {
8+
source = "../.."
9+
10+
name = "advanced-example-vpc"
11+
cidr_block = "10.0.0.0/16"
12+
azs = local.azs
13+
14+
optimize_subnet_cidr_ranges = true
15+
16+
subnets = {
17+
public = {
18+
netmask = 28
19+
nat_gateway_configuration = "single_az"
20+
}
21+
private = { netmask = 24 }
22+
database = { netmask = 27 }
23+
infrastructure = { netmask = 28 }
24+
}
25+
26+
vpc_flow_logs = {
27+
log_destination_type = "s3"
28+
destination_options = {
29+
file_format = "parquet"
30+
}
31+
}
32+
}
33+
34+
# ---------- VPC SECONDARY CIDR ----------
35+
module "secondary_cidr_block" {
36+
source = "../.."
37+
38+
name = "advanced-example-secondary-cidr"
39+
vpc_id = module.vpc.vpc_attributes.id
40+
create_vpc = false
41+
vpc_secondary_cidr = true
42+
43+
cidr_block = "10.100.0.0/16"
44+
azs = [local.azs[0]]
45+
46+
vpc_secondary_cidr_natgw = { for k, v in module.vpc.nat_gateway_attributes_by_az : k => { id = v.id } }
47+
48+
subnets = {
49+
private_secondary_cidr = {
50+
netmask = 28
51+
connect_to_public_natgw = true
52+
}
53+
}
54+
}
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
variable "aws_region" {
3-
description = "AWS Region."
43
type = string
4+
description = "AWS Region."
55

6-
default = "eu-west-2"
6+
default = "eu-west-1"
77
}

examples/basic/.header.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# VPC module - Example: Basic VPC
2+
3+
This example builds an Amazon VPC with basic functionality:
4+
5+
* Dual-stack VPC (IPv4 & IPv6)
6+
* Egress-only Internet gateway configured.
7+
* 4 VPC subnets - 1 public (dual-stack), 3 private (IPv4-only, dual-stack, and IPv6-only)
8+
* NAT gateways placed in all the public subnets.
9+
* Flow logs enabled (destination Amazon CloudWatch)
10+
* Routing:
11+
* IPv4 egress enabled in public subnets (through Internet gateway) and private subnets (through NAT gateways)
12+
* IPv6 egress enabled in private subnets (through Egress-only Internet gateway)

examples/basic/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
# VPC module - Example: Basic VPC
3+
4+
This example builds an Amazon VPC with basic functionality:
5+
6+
* Dual-stack VPC (IPv4 & IPv6)
7+
* Egress-only Internet gateway configured.
8+
* 4 VPC subnets - 1 public (dual-stack), 3 private (IPv4-only, dual-stack, and IPv6-only)
9+
* NAT gateways placed in all the public subnets.
10+
* Flow logs enabled (destination Amazon CloudWatch)
11+
* Routing:
12+
* IPv4 egress enabled in public subnets (through Internet gateway) and private subnets (through NAT gateways)
13+
* IPv6 egress enabled in private subnets (through Egress-only Internet gateway)
14+
15+
## Requirements
16+
17+
| Name | Version |
18+
|------|---------|
19+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
20+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
21+
22+
## Providers
23+
24+
No providers.
25+
26+
## Modules
27+
28+
| Name | Source | Version |
29+
|------|--------|---------|
30+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../.. | n/a |
31+
32+
## Resources
33+
34+
No resources.
35+
36+
## Inputs
37+
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region. | `string` | `"eu-west-1"` | no |
41+
42+
## Outputs
43+
44+
No outputs.
45+
<!-- END_TF_DOCS -->
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11

2-
# VPC module
2+
# ---------- AMAZON VPC ----------
33
module "vpc" {
44
source = "../.."
55

6-
name = "vpc-ipv6-generated"
7-
cidr_block = "10.0.0.0/16"
6+
name = "basic-example-vpc"
7+
cidr_block = "10.0.0.0/16"
8+
az_count = 2
9+
810
vpc_assign_generated_ipv6_cidr_block = true
911
vpc_egress_only_internet_gateway = true
10-
az_count = 2
1112

1213
subnets = {
1314
public = {
1415
netmask = 24
1516
nat_gateway_configuration = "all_azs"
1617
assign_ipv6_cidr = true
1718
}
18-
ipv4 = {
19+
private_ipv4_only = {
1920
netmask = 24
2021
connect_to_public_natgw = true
2122
}
22-
dualstack = {
23+
private_dualstack = {
2324
netmask = 24
2425
connect_to_public_natgw = true
2526
assign_ipv6_cidr = true
2627
connect_to_eigw = true
2728
}
28-
ipv6 = {
29-
ipv6_native = true
29+
private_ipv6_only = {
3030
assign_ipv6_cidr = true
31+
ipv6_native = true
3132
connect_to_eigw = true
3233
}
3334
}
35+
36+
vpc_flow_logs = {
37+
name_override = "basic-vpc-flowlogs"
38+
log_destination_type = "cloud-watch-logs"
39+
retention_in_days = 7
40+
}
3441
}

0 commit comments

Comments
 (0)