Skip to content

Commit

Permalink
- vcd_nsxt_network_dhcp Module Release Version 2.0.0
Browse files Browse the repository at this point in the history
- Moved the dhcp_mode, listener_ip_address, lease_time, and dns_servers variables into the segments variable map.

- Terraform Users will now be able to customize DHCP Modes, DNS Servers and DHCP Lease Times by Org Network Segment.

- Updated the README and Example Code to support the new updates.
  • Loading branch information
scafeman committed Jun 27, 2023
1 parent c14c610 commit 176bc1d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 107 deletions.
103 changes: 44 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,78 @@
## DHCP Terraform Module for Routed Data Center Group Networks
# VCD NSX-T DHCP Terraform Module

This Terraform module will deploy DHCP Pools for Routed Data Center Group Networks into an existing VMware Cloud Director (VCD) Environment. This module can be used to provsion new DHCP Pools into [Rackspace Technology SDDC Flex](https://www.rackspace.com/cloud/private/software-defined-data-center-flex) VCD Data Center Regions.
This Terraform module deploys NSX-T DHCP Pools into an existing VMware Cloud Director (VCD) environment. This module can be used to provision new NSX-T DHCP Pools into [Rackspace Technology SDDC Flex](https://www.rackspace.com/cloud/private/software-defined-data-center-flex) VCD Data Center Regions.

## Requirements

| Name | Version |
|-----------|---------|
| terraform | ~> 1.2 |
| vcd | ~> 3.8.2 |
| Name | Version |
|------|---------|
| terraform | >= 1.2 |
| vcd | >= 3.8.2 |

## Resources

| Name | Type |
|------------------------------------------------------------------|-----------|
| [vcd_vdc_group](https://registry.terraform.io/providers/vmware/vcd/3.8.2/docs/data-sources/vdc_group) | data source |
| [vcd_nsxt_edgegateway](https://registry.terraform.io/providers/vmware/vcd/3.8.2/docs/data-sources/nsxt_edgegateway) | data source |
| [vcd_network_routed_v2](https://registry.terraform.io/providers/vmware/vcd/3.8.2/docs/data-sources/network_routed_v2) | data source |
| [vcd_nsxt_network_dhcp](https://registry.terraform.io/providers/vmware/vcd/3.8.2/docs/resources/nsxt_network_dhcp) | resource |
| Name | Type |
|----------------------------------------------------------------------|--------------|
| [vcd_nsxt_edgegateway](https://registry.terraform.io/providers/vmware/vcd/latest/docs/data-sources/nsxt_edgegateway) | Data Source |
| [vcd_vdc_group](https://registry.terraform.io/providers/vmware/vcd/latest/docs/data-sources/vdc_group) | Data Source |
| [vcd_network_routed_v2](https://registry.terraform.io/providers/vmware/vcd/latest/docs/data-sources/network_routed_v2) | Data Source |
| [vcd_nsxt_network_dhcp](https://registry.terraform.io/providers/vmware/vcd/latest/docs/resources/nsxt_network_dhcp) | Resource |

## Inputs

| Name | Description | Type | Default | Required |
|-------------------------------|----------------------------------------------------------------------|--------|-------------------|----------|
| vdc_org_name | The name of the Data Center Group Organization in VCD | string | `"Organization Name Format: <Account_Number>-<Region>-<Account_Name>"` | yes |
| vdc_group_name | The name of the Data Center Group in VCD | string | `"Data Center Group Name Format: <Account_Number>-<Region>-<Account_Name> <datacenter group>"` | yes |
| vdc_edge_name | Name of the NSX-T Edge Gateway | string | `"Edge Gateway Name Format: <Account_Number>-<Region>-<Edge_GW_Identifier>-<edge>"` | yes |
| dhcp_mode | DHCP service mode. Valid values are "EDGE" (default), "NETWORK" or "RELAY". | string | "EDGE" | no |
| listener_ip_address | A map of DHCP listener IP addresses | string | null | no |
| lease_time | DHCP lease time in seconds. | string | "2592000" | no |
| dns_servers | A list of DNS server IP addresses to be assigned by this DHCP service. Maximum two values. | list(string) | null | yes |
| segments | A map of network segments to configure DHCP on. The key is the name of the network segment and the value is a map of the segment properties. Valid segment properties are "gateway" (required), "prefix_length" (required), "dns_suffix" (required), "listener_ip_address" (optional), "pool_ranges" (optional). | map(object({ gateway = string, prefix_length = number, dns_suffix = string, listener_ip_address = string, pool_ranges = list(map(string)) })) | `{"Segment-01" = {gateway = "192.168.0.1", prefix_length = 24, dns_suffix = "domain.com", listener_ip_address = null, pool_ranges = [{start_address = "192.168.0.101", end_address = "192.168.0.200"}]}, "Segment-02" = {gateway = "192.168.1.1", prefix_length = 24, dns_suffix = "domain.com", listener_ip_address = null, pool_ranges = [{start_address = "192.168.1.101", end_address = "192.168.1.200"}]}}` | yes |

`NOTE:` Each object in the `segments` map must have the following attributes:

`gateway`: The gateway IP address for the segment.
`prefix_length`: The CIDR notation prefix length for the segment.
`dns_suffix`: The DNS suffix for the segment.
`listener_ip_address` (optional): The IP address of the DHCP listener for the segment. Listener IP Address is required when your are using the "NETWORK" DHCP Mode Only.
`pool_ranges` (optional): A list of IP address ranges to be used for DHCP pools in the segment. If not specified, the module will automatically calculate a pool based on
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|----------|
| vdc_org_name | The name of the Data Center Group Organization in VCD | string | - | yes |
| vdc_edge_name | Name of the Data Center Group Edge Gateway | string | - | yes |
| vdc_group_name | The name of the Data Center Group in VCD | string | - | yes |
| segments | Map of network segments to configure DHCP on | map(object({ gateway = string, prefix_length = number, dns_suffix = string, listener_ip_address = string, pool_ranges = list(map(string)), dns_servers = list(string), dhcp_mode = string, lease_time = number })) | {} | yes |

## Outputs

| Name | Description |
|--------------|-------------------------|
| dhcp_pools | A map of DHCP pool ranges by segment name. |
| dhcp_dns_servers | The DNS server IP addresses assigned by this DHCP service. |
| dhcp_listener_ips | A map of DHCP listener IP addresses by segment name. |
| dhcp_mode | DHCP service mode. |
| Name | Description |
|------|-------------|
| dhcp_pools | The pool ranges, DNS servers, DHCP mode, and listener IP address for each network segment |

## Example Usage

This is an example of a `main.tf` file that uses the `vcd_nsxt_network_dhcp` module to configure DHCP Services on Two Data Center Group Routed Networks that are using "EDGE" DHCP Mode in a VMware Cloud Director environment:

```terraform
module "vcd_nsxt_network_dhcp" {
source = "github.com/global-vmware/vcd_nsxt_network_dhcp.git?ref=v1.1.0"
vdc_org_name = "<US1-VDC-ORG-NAME>"
vdc_group_name = "<US1-VDC-GRP-NAME>"
vdc_edge_name = "<US1-VDC-EDGE-NAME>"
dhcp_mode = "EDGE"
source = "github.com/global-vmware/vcd_nsxt_network_dhcp.git?ref=v2.0.0"
dns_servers = ["192.168.255.228"]
vdc_org_name = "<VDC-ORG-NAME>"
vdc_group_name = "<VDC-GRP-NAME>"
vdc_edge_name = "<VDC-EDGE-NAME>"
segments = {
"US1-Segment-01" = {
gateway = "172.16.0.1"
prefix_length = 24
dns_suffix = "mydomain.com"
listener_ip_address = ""
pool_ranges = [
gateway = "172.16.0.1"
prefix_length = 24
dns_suffix = "mydomain.com"
listener_ip_address = "172.16.0.10"
pool_ranges = [
{
start_address = "172.16.0.101"
end_address = "172.16.0.200"
start_address = "172.16.0.101"
end_address = "172.16.0.200"
}
]
},
]
dns_servers = ["192.168.255.228"]
dhcp_mode = "NETWORK"
lease_time = 2592000
},
"US1-Segment-02" = {
gateway = "172.16.1.1"
prefix_length = 24
dns_suffix = "mydomain.com"
listener_ip_address = ""
listener_ip_address = null
pool_ranges = [
{
start_address = "172.16.1.101"
end_address = "172.16.1.200"
start_address = "172.16.1.101"
end_address = "172.16.1.200"
}
]
]
dns_servers = ["192.168.255.228"]
dhcp_mode = "EDGE"
lease_time = 2592000
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = "~> 1.2"
required_version = ">= 1.2"

required_providers {
vcd = {
source = "vmware/vcd"
version = "~> 3.8"
version = ">= 3.8.2"
}
}
}
Expand Down Expand Up @@ -32,13 +32,13 @@ resource "vcd_nsxt_network_dhcp" "dhcp" {
for_each = var.segments
org = var.vdc_org_name
org_network_id = data.vcd_network_routed_v2.network[each.key].id
mode = var.dhcp_mode
listener_ip_address = var.dhcp_mode == "NETWORK" ? each.value.listener_ip_address : null
lease_time = var.lease_time
dns_servers = var.dhcp_mode == "RELAY" ? null : var.dns_servers
mode = each.value.dhcp_mode
listener_ip_address = each.value.dhcp_mode == "NETWORK" ? each.value.listener_ip_address : null
lease_time = each.value.lease_time
dns_servers = each.value.dhcp_mode == "RELAY" ? null : each.value.dns_servers

dynamic "pool" {
for_each = var.dhcp_mode == "RELAY" ? [] : each.value.pool_ranges
for_each = each.value.dhcp_mode == "RELAY" ? [] : each.value.pool_ranges
content {
start_address = pool.value.start_address
end_address = pool.value.end_address
Expand All @@ -52,3 +52,5 @@ resource "vcd_nsxt_network_dhcp" "dhcp" {





18 changes: 4 additions & 14 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ output "dhcp_pools" {
start_address = pool.start_address
end_address = pool.end_address
}
]
],
dns_servers = segment.dns_servers,
dhcp_mode = segment.dhcp_mode
listener_ip_address = segment.listener_ip_address
}
}
}

output "dhcp_dns_servers" {
value = var.dhcp_mode == "RELAY" ? null : var.dns_servers
}

output "dhcp_listener_ips" {
value = { for segment, dhcp in vcd_nsxt_network_dhcp.dhcp : segment => dhcp.listener_ip_address if var.dhcp_mode == "NETWORK" }
}


output "dhcp_mode" {
value = var.dhcp_mode
}
34 changes: 7 additions & 27 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,17 @@ variable "vdc_edge_name" {}

variable "vdc_group_name" {}

variable "dhcp_mode" {
type = string
default = "EDGE"
}

variable "listener_ip_address" {
type = string
default = null
}

variable "lease_time" {
type = number
default = "2592000"
}

variable "dns_servers" {
type = list(string)
description = "The DNS server IPs to be assigned by this DHCP service. Maximum two values."
default = null
}

variable "segments" {
type = map(object({
gateway = string
prefix_length = number
dns_suffix = string
gateway = string
prefix_length = number
dns_suffix = string
listener_ip_address = string
pool_ranges = list(map(string))
pool_ranges = list(map(string))
dns_servers = list(string)
dhcp_mode = string
lease_time = number
}))

description = "Map of network segments to configure DHCP on"
}


0 comments on commit 176bc1d

Please sign in to comment.