Skip to content

Commit 07654cf

Browse files
authored
Added possibility to create VPC conditionally (terraform-aws-modules#74)
* Added possibility to create VPC conditionally * Added editorconfig and pre-commit hooks
1 parent 2985eba commit 07654cf

File tree

7 files changed

+111
-45
lines changed

7 files changed

+111
-45
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
<<: *terraform
1111
steps:
1212
- checkout
13-
- run:
14-
name: Add github.com to ~/.ssh/known_hosts
15-
command: mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
13+
# - run:
14+
# name: Add github.com to ~/.ssh/known_hosts
15+
# command: mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
1616
- run:
1717
name: terraform init
1818
command: terraform init -input=false

.editorconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
# Uses editorconfig to maintain consistent coding styles
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
insert_final_newline = true
14+
max_line_length = 80
15+
trim_trailing_whitespace = true
16+
17+
[*.{tf,tfvars}]
18+
indent_size = 2
19+
indent_style = space
20+
21+
[*.md]
22+
max_line_length = 0
23+
trim_trailing_whitespace = false
24+
25+
[Makefile]
26+
tab_width = 2
27+
indent_style = tab
28+
29+
[COMMIT_EDITMSG]
30+
max_line_length = 0

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
sha: v1.4.0
4+
hooks:
5+
- id: terraform_fmt
6+
- repo: git://github.com/pre-commit/pre-commit-hooks
7+
sha: v1.2.0
8+
hooks:
9+
- id: check-merge-conflict

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ These types of resources are supported:
1919
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
2020
* [Redshift Subnet Group](https://www.terraform.io/docs/providers/aws/r/redshift_subnet_group.html)
2121
* [DHCP Options Set](https://www.terraform.io/docs/providers/aws/r/vpc_dhcp_options.html)
22+
* [Main VPC Routing Table](https://www.terraform.io/docs/providers/aws/r/main_route_table_assoc.html)
23+
* [Default VPC Routing Table](https://www.terraform.io/docs/providers/aws/r/default_route_table.html)
2224

2325
Usage
2426
-----
2527

2628
```hcl
27-
provider "aws" {
28-
version = "~> 1.0.0"
29-
region = "eu-west-1"
30-
}
31-
3229
module "vpc" {
3330
source = "terraform-aws-modules/vpc/aws"
3431
@@ -85,6 +82,21 @@ Note that in the example we allocate 3 IPs because we will be provisioning 3 NAT
8582
If, on the other hand, `single_nat_gateway = true`, then `aws_eip.nat` would only need to allocate 1 IP.
8683
Passing the IPs into the module is done by setting two variables `reuse_nat_ips = true` and `external_nat_ip_ids = ["${aws_eip.nat.*.id}"]`.
8784

85+
Conditional creation
86+
--------------------
87+
88+
Sometimes you need to have a way to create VPC resources conditionally but Terraform does not allow to use `count` inside `module` block, so the solution is to specify argument `create_vpc`.
89+
90+
```hcl
91+
# This VPC will not be created
92+
module "vpc" {
93+
source = "terraform-aws-modules/vpc/aws"
94+
95+
create_vpc = false
96+
# ... omitted
97+
}
98+
```
99+
88100
Terraform version
89101
-----------------
90102

0 commit comments

Comments
 (0)