From 85a47cb3a9a21c1843b0123f0db3cc36d9f3c7f6 Mon Sep 17 00:00:00 2001 From: brian cenker Date: Sat, 11 Nov 2017 16:13:23 -0500 Subject: [PATCH] Add support for DHCP options set (#20) * Add support for DHCP options set * code cleanup * remove unnecessary depends_on in aws_vpc_dhcp_options_association definition --- README.md | 3 ++- examples/complete-vpc/main.tf | 4 ++++ main.tf | 23 +++++++++++++++++++++++ variables.tf | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 108945404..9c01f22de 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ These types of resources are supported: * [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 ----- diff --git a/examples/complete-vpc/main.tf b/examples/complete-vpc/main.tf index 80d995fb8..5161f4eaf 100644 --- a/examples/complete-vpc/main.tf +++ b/examples/complete-vpc/main.tf @@ -19,6 +19,10 @@ module "vpc" { 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 1208d4fec..3967433b9 100644 --- a/main.tf +++ b/main.tf @@ -10,6 +10,29 @@ 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}" +} + +############################### +# 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 ################### diff --git a/variables.tf b/variables.tf index 908f1461f..ce21d13ec 100644 --- a/variables.tf +++ b/variables.tf @@ -129,3 +129,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 = "" +}