Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Shapeways/terraform-aws-vpc
Browse files Browse the repository at this point in the history
* 'master' of github.com:Shapeways/terraform-aws-vpc:
  Reverted bad merge, fixed terraform-aws-modules#33
  Set enable_dns_support=true by default
  Updated descriptions for DNS variables (closes terraform-aws-modules#14)
  Add version requirements in README.md (fixes terraform-aws-modules#32)
  Add version requirements in README.md
  make sure outputs are always valid (terraform-aws-modules#29)
  Add tags to the aws_vpc_dhcp_options resource (terraform-aws-modules#30)
  Add support for DHCP options set (terraform-aws-modules#20)
  terraform-aws-modules#22 add vpn gateway feature (terraform-aws-modules#24)
  Add cidr_block outputs to public and private subnets (terraform-aws-modules#19)
  • Loading branch information
Martin Beauchamp committed Nov 28, 2017
2 parents 5602d8b + ae76447 commit 3a3fee4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 9 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ These types of resources are supported:
* [Route table](https://www.terraform.io/docs/providers/aws/r/route_table.html)
* [Internet Gateway](https://www.terraform.io/docs/providers/aws/r/internet_gateway.html)
* [NAT Gateway](https://www.terraform.io/docs/providers/aws/r/nat_gateway.html)
* [VPN Gateway](https://www.terraform.io/docs/providers/aws/r/vpn_gateway.html)
* [VPC Endpoint](https://www.terraform.io/docs/providers/aws/r/vpc_endpoint.html) (S3 and DynamoDB)
* [RDS DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
* [DHCP Options Set](https://www.terraform.io/docs/providers/aws/r/vpc_dhcp_options.html)

Usage
-----

```hcl
provider "aws" {
version = "~> 1.0.0"
region = "eu-west-1"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
Expand All @@ -30,6 +37,7 @@ module "vpc" {
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
enable_vpn_gateway = true
tags = {
Terraform = "true"
Expand All @@ -38,6 +46,11 @@ module "vpc" {
}
```

Terraform version
-----------------

Terraform version 1.0.0 or newer is required for this version to work.

Examples
--------

Expand Down
5 changes: 5 additions & 0 deletions examples/complete-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ module "vpc" {
create_database_subnet_group = false

enable_nat_gateway = true
enable_vpn_gateway = true

enable_s3_endpoint = true
enable_dynamodb_endpoint = true

enable_dhcp_options = true
dhcp_options_domain_name = "service.consul"
dhcp_options_domain_name_servers = ["127.0.0.1", "10.10.0.2"]

tags = {
Owner = "user"
Environment = "staging"
Expand Down
36 changes: 36 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ resource "aws_vpc" "this" {
tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
}

###################
# DHCP Options Set
###################
resource "aws_vpc_dhcp_options" "this" {
count = "${var.enable_dhcp_options ? 1 : 0}"

domain_name = "${var.dhcp_options_domain_name}"
domain_name_servers = "${var.dhcp_options_domain_name_servers}"
ntp_servers = "${var.dhcp_options_ntp_servers}"
netbios_name_servers = "${var.dhcp_options_netbios_name_servers}"
netbios_node_type = "${var.dhcp_options_netbios_node_type}"

tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
}

###############################
# DHCP Options Set Association
###############################
resource "aws_vpc_dhcp_options_association" "this" {
count = "${var.enable_dhcp_options ? 1 : 0}"

vpc_id = "${aws_vpc.this.id}"
dhcp_options_id = "${aws_vpc_dhcp_options.this.id}"
}

###################
# Internet Gateway
###################
Expand Down Expand Up @@ -272,3 +297,14 @@ resource "aws_route_table_association" "public" {
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public.id}"
}

##############
# VPN Gateway
##############
resource "aws_vpn_gateway" "this" {
count = "${var.enable_vpn_gateway ? 1 : 0}"

vpc_id = "${aws_vpc.this.id}"

tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
}
16 changes: 11 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ output "database_subnets_cidr_blocks" {

output "database_subnet_group" {
description = "ID of database subnet group"
value = "${aws_db_subnet_group.database.id}"
value = "${element(concat(aws_db_subnet_group.database.*.id, list("")), 0)}"
}

output "redshift_subnets" {
Expand Down Expand Up @@ -82,7 +82,7 @@ output "elasticache_subnets_cidr_blocks" {

output "elasticache_subnet_group" {
description = "ID of elasticache subnet group"
value = "${aws_elasticache_subnet_group.elasticache.id}"
value = "${element(concat(aws_elasticache_subnet_group.elasticache.*.id, list("")), 0)}"
}

# Route tables
Expand Down Expand Up @@ -114,13 +114,13 @@ output "natgw_ids" {
# Internet Gateway
output "igw_id" {
description = "The ID of the Internet Gateway"
value = "${aws_internet_gateway.this.id}"
value = "${element(concat(aws_internet_gateway.this.*.id, list("")), 0)}"
}

# VPC Endpoints
output "vpc_endpoint_s3_id" {
description = "The ID of VPC endpoint for S3"
value = "${aws_vpc_endpoint.s3.id}"
value = "${element(concat(aws_vpc_endpoint.s3.*.id, list("")), 0)}"
}

output "vpc_endpoint_s3_pl_id" {
Expand All @@ -130,7 +130,13 @@ output "vpc_endpoint_s3_pl_id" {

output "vpc_endpoint_dynamodb_id" {
description = "The ID of VPC endpoint for DynamoDB"
value = "${aws_vpc_endpoint.dynamodb.id}"
value = "${element(concat(aws_vpc_endpoint.dynamodb.*.id, list("")), 0)}"
}

# VPN Gateway
output "vgw_id" {
description = "The ID of the VPN Gateway"
value = "${element(concat(aws_vpn_gateway.this.*.id, list("")), 0)}"
}

output "vpc_endpoint_dynamodb_pl_id" {
Expand Down
44 changes: 41 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ variable "azs" {
}

variable "enable_dns_hostnames" {
description = "Should be true if you want to use private DNS within the VPC"
description = "Should be true to enable DNS hostnames in the VPC"
default = false
}

variable "enable_dns_support" {
description = "Should be true if you want to use private DNS within the VPC"
default = false
description = "Should be true to enable DNS support in the VPC"
default = true
}

variable "enable_nat_gateway" {
Expand Down Expand Up @@ -86,6 +86,11 @@ variable "map_public_ip_on_launch" {
default = true
}

variable "enable_vpn_gateway" {
description = "Should be true if you want to create a new VPN Gateway resource and attach it to the VPC"
default = false
}

variable "private_propagating_vgws" {
description = "A list of VGWs the private route table should propagate"
default = []
Expand Down Expand Up @@ -135,3 +140,36 @@ variable "elasticache_subnet_tags" {
description = "Additional tags for the elasticache subnets"
default = {}
}

variable "enable_dhcp_options" {
description = "Should be true if you want to specify a DHCP options set with a custom domain name, DNS servers, NTP servers, netbios servers, and/or netbios server type"
default = false
}

variable "dhcp_options_domain_name" {
description = "Specifies DNS name for DHCP options set"
default = ""
}

variable "dhcp_options_domain_name_servers" {
description = "Specify a list of DNS server addresses for DHCP options set, default to AWS provided"
type = "list"
default = ["AmazonProvidedDNS"]
}

variable "dhcp_options_ntp_servers" {
description = "Specify a list of NTP servers for DHCP options set"
type = "list"
default = []
}

variable "dhcp_options_netbios_name_servers" {
description = "Specify a list of netbios servers for DHCP options set"
type = "list"
default = []
}

variable "dhcp_options_netbios_node_type" {
description = "Specify netbios node_type for DHCP options set"
default = ""
}

0 comments on commit 3a3fee4

Please sign in to comment.