Commit 07654cff authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Added possibility to create VPC conditionally (#74)

* Added possibility to create VPC conditionally

* Added editorconfig and pre-commit hooks
parent 2985eba4
......@@ -10,9 +10,9 @@ jobs:
<<: *terraform
steps:
- checkout
- run:
name: Add github.com to ~/.ssh/known_hosts
command: mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# - run:
# name: Add github.com to ~/.ssh/known_hosts
# command: mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
- run:
name: terraform init
command: terraform init -input=false
......
# EditorConfig is awesome: http://EditorConfig.org
# Uses editorconfig to maintain consistent coding styles
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.{tf,tfvars}]
indent_size = 2
indent_style = space
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
[Makefile]
tab_width = 2
indent_style = tab
[COMMIT_EDITMSG]
max_line_length = 0
\ No newline at end of file
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
sha: v1.4.0
hooks:
- id: terraform_fmt
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v1.2.0
hooks:
- id: check-merge-conflict
......@@ -19,16 +19,13 @@ These types of resources are supported:
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
* [Redshift Subnet Group](https://www.terraform.io/docs/providers/aws/r/redshift_subnet_group.html)
* [DHCP Options Set](https://www.terraform.io/docs/providers/aws/r/vpc_dhcp_options.html)
* [Main VPC Routing Table](https://www.terraform.io/docs/providers/aws/r/main_route_table_assoc.html)
* [Default VPC Routing Table](https://www.terraform.io/docs/providers/aws/r/default_route_table.html)
Usage
-----
```hcl
provider "aws" {
version = "~> 1.0.0"
region = "eu-west-1"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
......@@ -85,6 +82,21 @@ Note that in the example we allocate 3 IPs because we will be provisioning 3 NAT
If, on the other hand, `single_nat_gateway = true`, then `aws_eip.nat` would only need to allocate 1 IP.
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}"]`.
Conditional creation
--------------------
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`.
```hcl
# This VPC will not be created
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
create_vpc = false
# ... omitted
}
```
Terraform version
-----------------
......
This diff is collapsed.
# VPC
output "vpc_id" {
description = "The ID of the VPC"
value = "${aws_vpc.this.id}"
value = "${element(concat(aws_vpc.this.*.id, list("")), 0)}"
}
output "vpc_cidr_block" {
description = "The CIDR block of the VPC"
value = "${aws_vpc.this.cidr_block}"
value = "${element(concat(aws_vpc.this.*.cidr_block, list("")), 0)}"
}
output "default_security_group_id" {
description = "The ID of the security group created by default on VPC creation"
value = "${aws_vpc.this.default_security_group_id}"
value = "${element(concat(aws_vpc.this.*.default_security_group_id, list("")), 0)}"
}
output "default_network_acl_id" {
description = "The ID of the default network ACL"
value = "${aws_vpc.this.default_network_acl_id}"
value = "${element(concat(aws_vpc.this.*.default_network_acl_id, list("")), 0)}"
}
output "default_route_table_id" {
description = "The ID of the default route table"
value = "${aws_vpc.this.default_route_table_id}"
value = "${element(concat(aws_vpc.this.*.default_route_table_id, list("")), 0)}"
}
# Subnets
......
variable "create_vpc" {
description = "Controls if VPC should be created (it affects almost all resources)"
default = true
}
variable "name" {
description = "Name to be used on all the resources as identifier"
default = ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment