This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.x with Terraform 0.12
- Loading branch information
Showing
17 changed files
with
1,758 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
docker-compose* | ||
.gitignore | ||
.dockerignore | ||
|
||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
**/.tfstate | ||
**/.tfstate.* | ||
|
||
# .tfvars files | ||
**/*.tfvars | ||
|
||
Jenkinsfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM puneethn/terraform-test-workhorse:0.12.25 | ||
|
||
WORKDIR /go/src/github.com/comtravo/terraform-aws-vpc | ||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
pipeline { | ||
|
||
agent { label 'worker' } | ||
|
||
options { | ||
ansiColor('gnome-terminal') | ||
buildDiscarder(logRotator(numToKeepStr: '30')) | ||
skipDefaultCheckout() | ||
timestamps() | ||
} | ||
|
||
stages { | ||
stage("Checkout SCM") { | ||
steps { | ||
script { | ||
ctCheckout(revision: getMultiBranchName(), wipeWorkspace: true, noTags: true, url: '[email protected]:comtravo/terraform-aws-vpc.git') | ||
} | ||
} | ||
} | ||
|
||
stage("Build and Test") { | ||
steps { | ||
script { | ||
try { | ||
sh(label: 'Building docker image', script: "make build") | ||
sh(label: 'Testing docker image', script: "make test-docker") | ||
} finally { | ||
sh(label: 'Cleanup', script: "make clean-all") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#! make | ||
|
||
DOCKER_COMPOSE=docker-compose -f ./docker-compose.yml | ||
DOCKER_COMPOSE_DEVELOP=$(DOCKER_COMPOSE) -f ./docker-compose.develop.yml | ||
|
||
GENERATE_DOCS_COMMAND:=terraform-docs --sort-inputs-by-required markdown table . > README.md | ||
|
||
fmt: | ||
@terraform fmt -recursive | ||
@find . -name '*.go' | xargs gofmt -w -s | ||
|
||
lint: | ||
@terraform fmt -check -recursive -diff=true | ||
@test -z $(shell find . -type f -name '*.go' | xargs gofmt -l) | ||
@tflint | ||
|
||
build: | ||
@$(DOCKER_COMPOSE) build | ||
|
||
test-localstack: | ||
@cd test && go test -tags=localstack | ||
|
||
test-all: test-localstack | ||
|
||
test-docker: | ||
@$(DOCKER_COMPOSE) run --rm terraform make lint | ||
@$(DOCKER_COMPOSE) run --rm terraform make test-all | ||
@$(DOCKER_COMPOSE) down -v | ||
|
||
develop: | ||
@$(DOCKER_COMPOSE_DEVELOP) run --rm terraform bash | ||
@$(DOCKER_COMPOSE_DEVELOP) down -v | ||
|
||
generate-docs: fmt lint | ||
@$(GENERATE_DOCS_COMMAND) | ||
|
||
clean-state: | ||
@find . -type f -name 'terraform.tfstate' | xargs rm -rf | ||
@find . -type d -name '.terraform' | xargs rm -rf | ||
|
||
clean-all: clean-state | ||
@$(DOCKER_COMPOSE) down -v | ||
|
||
logs: | ||
@$(DOCKER_COMPOSE) logs -f | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,73 @@ | ||
# terraform-aws-vpc | ||
# Terraform AWS module for creating VPC resources | ||
|
||
## Introduction: | ||
## Introduction | ||
|
||
This module creates a AWS VPC and all the resources related to it. | ||
This module is used to create VPCs in your AWS account. It is a complete rewrite of our internal Terraform AWS VPC module. see branch (1.x). | ||
|
||
## Current features | ||
* **Conditionally enable / disable VPC creation.** It is helpful when for example you want to conditionally create multiple VPCs in a single environment for reasons such as VPC peering. | ||
* This module helps **create explicit dependencies between VPCs and VPC peering** so that there is no race condition between VPC creation and VPC peering. | ||
* **Create a private Route 53 hosted zone**. | ||
* **Conditionally create a Route 53 public hosted zone**. For example, if your master account has `foo.com` and you want bar.foo.com to be terraformed in your sub account, you could specify `subdomain = "bar.foo.com"` and setup `DNS` propogation in your master account for `bar.foo.com` | ||
* Configure optionally, your private and public subnet configuration by specifying the number of subnets to be created, newbits and netnum_offset. Subnetting should be handled externally to this module. See [CIDR subnetting in terraform](https://www.terraform.io/docs/configuration-0-11/interpolation.html#cidrsubnet-iprange-newbits-netnum-) | ||
* You can **provide external elastic ips** to the terraform module and those would be used to create the NAT gateways. (useful for retaining ***"whilelisted"*** IP addresses in case you would have to teardown the VPC for some reason) | ||
|
||
*Note on Terraforming elastic IPs outside of the module. The elastic IPs should be Terraformed before specifying the vpc module. So Terraform should be applied in two phases. one for EIPs and then the VPC module.* | ||
|
||
|
||
Refer to [variable.tf](./variables.tf) for more configurable options and [outputs.tf](./outputs.tf) for exposed outputs | ||
|
||
|
||
## Usage: | ||
```hcl | ||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
resource "aws_eip" "nat" { | ||
count = 3 | ||
vpc = true | ||
tags { | ||
Name = "${terraform.workspace}-nat-gateway-eip-${count.index}" | ||
environment = "${terraform.workspace}" | ||
} | ||
} | ||
module "infra_vpc" { | ||
source = "github.com/comtravo/terraform-aws-vpc?ref=2.1.0" | ||
enable = 1 | ||
vpc_name = "${terraform.workspace}" | ||
cidr = "${var.ct_vpc_cidr}" | ||
availability_zones = "${data.aws_availability_zones.available.names}" | ||
subdomain = "${terraform.workspace}.comtravo.com" | ||
depends_id = "" | ||
private_subnets { | ||
number_of_subnets = 3 | ||
newbits = 4 | ||
netnum_offset = 0 | ||
} | ||
public_subnets { | ||
number_of_subnets = 3 | ||
newbits = 4 | ||
netnum_offset = 8 | ||
} | ||
# This **optional** config uses the provided elastic IPs instead of creating new ones | ||
# | ||
# | ||
external_elastic_ips = ["${aws_eip.nat.*.id}"] | ||
# Note: | ||
# When both elastic IPs are given and nat_gateway behavior = one_nat_per_availability_zone, | ||
# The number of NAT gateways created is min(length(elastic_ips), length(availability_zones)) | ||
# This **optional** block creates NAT gateways in all the availability zones and | ||
# creates associated route tables and assigns it to the private subnets. | ||
# | ||
nat_gateway { | ||
behavior = "one_nat_per_availability_zone" | ||
} | ||
# Note: | ||
# Default behavior: | ||
tags { | ||
environment = "${terraform.workspace}" | ||
} | ||
} | ||
``` | ||
\*\*Note on Terraforming elastic IPs outside of the module. The elastic IPs should be Terraformed before specifying the vpc module. So Terraform should be applied in two phases. one for EIPs and then the VPC module.\*\* | ||
|
||
## Usage | ||
Checkout [example.tf](./examples/example.tf) for how to use this module | ||
|
||
## Authors | ||
|
||
Module managed by [Comtravo](https://github.com/comtravo). | ||
|
||
## License | ||
|
||
MIT Licensed. See [LICENSE](LICENSE) for full details. | ||
|
||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| terraform | >= 0.12 | | ||
| aws | ~> 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws | ~> 2.0 | | ||
| null | n/a | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| availability\_zones | List of avaliability zones | `list(string)` | n/a | yes | | ||
| cidr | CIDR of the VPC | `string` | n/a | yes | | ||
| vpc\_name | Name of the VPC | `string` | n/a | yes | | ||
| assign\_generated\_ipv6\_cidr\_block | Create ipv6 CIDR block | `bool` | `true` | no | | ||
| depends\_id | Inter module dependency id | `string` | `""` | no | | ||
| enable | Enable or disable creation of resources | `bool` | `true` | no | | ||
| enable\_dns\_hostnames | Enable DNS hostmanes in VPC | `bool` | `true` | no | | ||
| enable\_dns\_support | Enable DNS support in VPC | `bool` | `true` | no | | ||
| external\_elastic\_ips | List of elastic IPs to use instead of creating within the module | `list(string)` | `[]` | no | | ||
| nat\_gateway | NAT gateway creation behavior. If `one_nat_per_availability_zone` A NAT gateway is created per availability zone. | <pre>object({<br> behavior = string<br> })</pre> | <pre>{<br> "behavior": "one_nat_per_vpc"<br>}</pre> | no | | ||
| private\_subnets | Private subnet CIDR ipv4 config | <pre>object({<br> number_of_subnets = number<br> newbits = number<br> netnum_offset = number<br> })</pre> | <pre>{<br> "netnum_offset": 0,<br> "newbits": 8,<br> "number_of_subnets": 3<br>}</pre> | no | | ||
| public\_subnets | Public subnet CIDR ipv4 config | <pre>object({<br> number_of_subnets = number<br> newbits = number<br> netnum_offset = number<br> })</pre> | <pre>{<br> "netnum_offset": 100,<br> "newbits": 8,<br> "number_of_subnets": 3<br>}</pre> | no | | ||
| subdomain | Public subdomain name | `string` | `""` | no | | ||
| tags | Map of tags to tag resources | `map` | `{}` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| depends\_id | Dependency id | | ||
| elastic\_ips | List of elastic ips | | ||
| nat\_gateway\_ids | NAT gateway ids | | ||
| net0ps\_zone\_id | Private hosted zone id | | ||
| private\_subdomain | Private hosted zone name | | ||
| private\_subnets | List of private subnets | | ||
| private\_zone\_id | Private hosted zone name | | ||
| public\_subdomain | Public hosted zone name | | ||
| public\_subdomain\_zone\_id | Public hosted zone id | | ||
| public\_subnets | List of public subnets | | ||
| subdomain\_zone\_id | Public hosted zone id | | ||
| vpc\_default\_sg | Default security group | | ||
| vpc\_id | VPC id | | ||
| vpc\_private\_routing\_table\_id | Private routing table id | | ||
| vpc\_public\_routing\_table\_id | Public routing table id | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3' | ||
|
||
services: | ||
terraform: | ||
command: bash | ||
volumes: | ||
- ./:/go/src/github.com/comtravo/terraform-aws-vpc | ||
|
||
localstack: | ||
ports: | ||
- 4566:4566 | ||
- 4584-4597:4584-4597 | ||
- 4567-4583:4567-4583 | ||
- 8080:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: '3' | ||
|
||
services: | ||
terraform: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
image: ct-terraform-aws-vpc-module:${GIT_COMMIT:-latest} | ||
environment: | ||
- AWS_REGION=us-east-1 | ||
- AWS_DEFAULT_REGION=us-east-1 | ||
- AWS_ACCESS_KEY_ID=foo | ||
- AWS_SECRET_ACCESS_KEY=bar | ||
- LOCALSTACK_HOST=localstack | ||
depends_on: | ||
- localstack | ||
|
||
localstack: | ||
image: localstack/localstack | ||
environment: | ||
- SERVICES=iam,sts,ec2,route53 | ||
- DEFAULT_REGION=us-east-1 | ||
- DOCKER_HOST=unix:///var/run/docker.sock | ||
- DATA_DIR=/tmp/localstack/data | ||
- DEBUG=1 | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock" | ||
- "localstack-data:/tmp/localstack" | ||
|
||
volumes: | ||
localstack-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "current" {} | ||
data "aws_availability_zones" "available" {} | ||
|
||
module "vpc_enabled" { | ||
source = "../../../" | ||
|
||
enable = true | ||
vpc_name = "vpc_enabled" | ||
cidr = "10.10.0.0/16" | ||
availability_zones = data.aws_availability_zones.available.names | ||
depends_id = "" | ||
|
||
tags { | ||
environment = "vpc_enabled" | ||
} | ||
} | ||
|
||
module "vpc_disabled" { | ||
source = "../../../" | ||
|
||
enable = false | ||
vpc_name = "vpc_disabled" | ||
cidr = "10.10.0.0/16" | ||
availability_zones = data.aws_availability_zones.available.names | ||
depends_id = "" | ||
|
||
tags { | ||
environment = "vpc_disabled" | ||
} | ||
} |
Oops, something went wrong.