From f095676071c764ae76996fae4c70014a981f5798 Mon Sep 17 00:00:00 2001 From: bcenker Date: Sat, 4 Nov 2017 01:07:44 -0400 Subject: [PATCH 1/3] Add support for DHCP options set --- README.md | 3 ++- examples/complete-vpc/main.tf | 4 ++++ main.tf | 22 ++++++++++++++++++++++ variables.tf | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45b57dcf8..ca6362d46 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ These types of resources are supported: * [NAT Gateway](https://www.terraform.io/docs/providers/aws/r/nat_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 d5bad4b93..fb30764ca 100644 --- a/examples/complete-vpc/main.tf +++ b/examples/complete-vpc/main.tf @@ -18,6 +18,10 @@ module "vpc" { enable_s3_endpoint = true enable_dynamodb_endpoint = true + enable_dhcp_options = true + dhcp_options_domain_name = "service.consul" + dhcp_options_dns_servers = ["127.0.0.1","10.10.0.2"] + tags = { Owner = "user" Environment = "staging" diff --git a/main.tf b/main.tf index 7fc4679ef..712b2fab1 100644 --- a/main.tf +++ b/main.tf @@ -10,6 +10,28 @@ 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_dns_servers}" + ntp_servers = "${var.dhcp_options_ntp_servers}" + netbios_name_servers = "${var.dhcp_options_netbios_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}" + depends_on = ["aws_vpc.this","aws_vpc_dhcp_options.this"] +} + ################### # Internet Gateway ################### diff --git a/variables.tf b/variables.tf index 1a03aa864..6be10ad82 100644 --- a/variables.tf +++ b/variables.tf @@ -124,3 +124,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_dns_servers" { + type = "list" + description = "Specify a list of DNS server addresses for DHCP options set, default to AWS provided" + default = ["AmazonProvidedDNS"] +} + +variable "dhcp_options_ntp_servers" { + type = "list" + description = "Specify a list of NTP servers for DHCP options set" + default = [] +} + +variable "dhcp_options_netbios_servers" { + type = "list" + description = "Specify a list of netbios servers for DHCP options set" + default = [] +} + +variable "dhcp_options_netbios_node_type" { + description = "Specify netbios node_type for DHCP options set" + default = "" +} From 5d9cb51c1bab615e3d19b381e624c87dabbaf976 Mon Sep 17 00:00:00 2001 From: bcenker Date: Sat, 11 Nov 2017 14:48:25 -0500 Subject: [PATCH 2/3] code cleanup --- examples/complete-vpc/main.tf | 6 +++--- main.tf | 20 +++++++++++--------- variables.tf | 10 +++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/complete-vpc/main.tf b/examples/complete-vpc/main.tf index fb30764ca..e79f78c71 100644 --- a/examples/complete-vpc/main.tf +++ b/examples/complete-vpc/main.tf @@ -18,9 +18,9 @@ module "vpc" { enable_s3_endpoint = true enable_dynamodb_endpoint = true - enable_dhcp_options = true - dhcp_options_domain_name = "service.consul" - dhcp_options_dns_servers = ["127.0.0.1","10.10.0.2"] + 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" diff --git a/main.tf b/main.tf index 712b2fab1..bd5c25a2e 100644 --- a/main.tf +++ b/main.tf @@ -14,22 +14,24 @@ resource "aws_vpc" "this" { # 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_dns_servers}" - ntp_servers = "${var.dhcp_options_ntp_servers}" - netbios_name_servers = "${var.dhcp_options_netbios_servers}" - netbios_node_type = "${var.dhcp_options_netbios_node_type}" + 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}" + count = "${var.enable_dhcp_options ? 1 : 0}" + + vpc_id = "${aws_vpc.this.id}" dhcp_options_id = "${aws_vpc_dhcp_options.this.id}" - depends_on = ["aws_vpc.this","aws_vpc_dhcp_options.this"] + depends_on = ["aws_vpc.this", "aws_vpc_dhcp_options.this"] } ################### diff --git a/variables.tf b/variables.tf index 6be10ad82..6f39304a2 100644 --- a/variables.tf +++ b/variables.tf @@ -135,21 +135,21 @@ variable "dhcp_options_domain_name" { default = "" } -variable "dhcp_options_dns_servers" { - type = "list" +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" { - type = "list" description = "Specify a list of NTP servers for DHCP options set" + type = "list" default = [] } -variable "dhcp_options_netbios_servers" { - type = "list" +variable "dhcp_options_netbios_name_servers" { description = "Specify a list of netbios servers for DHCP options set" + type = "list" default = [] } From aaddb3dc76b14994fa7256be78f6bb8efbcdb1c9 Mon Sep 17 00:00:00 2001 From: bcenker Date: Sat, 11 Nov 2017 16:06:08 -0500 Subject: [PATCH 3/3] remove unnecessary depends_on in aws_vpc_dhcp_options_association definition --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index bd5c25a2e..dbd7d1a66 100644 --- a/main.tf +++ b/main.tf @@ -31,7 +31,6 @@ resource "aws_vpc_dhcp_options_association" "this" { vpc_id = "${aws_vpc.this.id}" dhcp_options_id = "${aws_vpc_dhcp_options.this.id}" - depends_on = ["aws_vpc.this", "aws_vpc_dhcp_options.this"] } ###################