diff --git a/README.md b/README.md index 45b57dcf8..65e6c7e57 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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" @@ -38,6 +46,11 @@ module "vpc" { } ``` +Terraform version +----------------- + +Terraform version 1.0.0 or newer is required for this version to work. + Examples -------- diff --git a/examples/complete-vpc/main.tf b/examples/complete-vpc/main.tf index f752f18b2..e23a50570 100644 --- a/examples/complete-vpc/main.tf +++ b/examples/complete-vpc/main.tf @@ -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" diff --git a/main.tf b/main.tf index 08e555936..0f333d58a 100644 --- a/main.tf +++ b/main.tf @@ -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 ################### @@ -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)))}" +} diff --git a/outputs.tf b/outputs.tf index d6db81b82..4e147428a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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" { @@ -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 @@ -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" { @@ -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" { diff --git a/variables.tf b/variables.tf index 84b7a7807..61803b823 100644 --- a/variables.tf +++ b/variables.tf @@ -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" { @@ -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 = [] @@ -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 = "" +}