A comprehensive Terraform module for managing VMware NSX-T Data Center infrastructure using the Policy API.
terraform-nsx-module/
βββ main.tf # Root module - composes sub-modules
βββ variables.tf # Root input variables
βββ outputs.tf # Root outputs
βββ README.md
βββ modules/
β βββ tier1_gateway/ # π Tier-1 gateway management
β βββ segments/ # π Overlay segment management
β βββ security_groups/ # π‘οΈ NS Group / security group management
β βββ firewall_rules/ # π₯ Distributed Firewall (DFW) policy & rules
β βββ load_balancer/ # βοΈ LB service, pools, monitors, virtual servers
βββ examples/
βββ three-tier-app.tf # π Full 3-tier application example
| Sub-Module | NSX-T Resources | |
|---|---|---|
| π | tier1_gateway | nsxt_policy_tier1_gateway |
| π | segments | nsxt_policy_segment with optional DHCP |
| π‘οΈ | security_groups | nsxt_policy_group (tag, IP, segment criteria) |
| π₯ | firewall_rules | nsxt_policy_security_policy with dynamic rules |
| βοΈ | load_balancer | nsxt_policy_lb_service, nsxt_policy_lb_pool, nsxt_policy_lb_monitor, nsxt_policy_lb_virtual_server |
| Requirement | Version / Detail |
|---|---|
| NSX-T Data Center 3.x or 4.x | |
| Terraform >= 1.5.0 | |
| VMware NSX-T Terraform Provider >= 3.4.0 |
Infrastructure required:
- π Existing Tier-0 gateway
- π₯οΈ Existing Edge Cluster
- π Existing Overlay Transport Zone
module "nsx" {
source = "./terraform-nsx-module"
nsx_manager_host = "nsx-manager.example.com"
nsx_username = var.nsx_username
nsx_password = var.nsx_password
overlay_transport_zone_name = "overlay-tz"
tier0_gateway_name = "tier0-gateway"
edge_cluster_name = "edge-cluster-01"
tier1_gateways = {
"t1-web" = {
description = "Web Tier Gateway"
}
}
segments = {
"seg-web" = {
tier1_gateway = "t1-web"
subnet_cidr = "10.10.1.1/24"
}
}
security_groups = {
"sg-web-servers" = {
criteria = [
{ condition_type = "Tag", tag = "web", scope = "tier" }
]
}
}
firewall_policies = {
"policy-web" = {
category = "Application"
rules = [
{
display_name = "allow-http"
action = "ALLOW"
destination_groups = ["sg-web-servers"]
services = ["HTTP", "HTTPS"]
logged = true
}
]
}
}
}| Output | Description |
|---|---|
tier1_gateways |
π Map of Tier-1 gateway paths and IDs |
segments |
π Map of segment paths and IDs |
security_groups |
π‘οΈ Map of security group paths and IDs |
firewall_policies |
π₯ Map of firewall policy paths |
load_balancers |
βοΈ Map of LB service IDs and virtual servers |
The module supports three types of group membership criteria:
{ condition_type = "Tag", tag = "web", scope = "tier", member_type = "VirtualMachine" }{ condition_type = "IPAddress", ip_addresses = ["10.0.0.0/24", "10.0.1.0/24"] }{ condition_type = "Segment", tag = "production" }Rules reference NSX built-in services by display name. The module automatically resolves these to their policy paths.
| Service Name | Protocol |
|---|---|
"HTTP" |
TCP/80 |
"HTTPS" |
TCP/443 |
"SSH" |
TCP/22 |
"DNS" |
TCP+UDP/53 |
"ICMP ALL" |
ICMP |
π‘ Tip: Any service defined in NSX Manager can be referenced by its display name β these are just common examples.
See examples/three-tier-app.tf for a complete deployment that creates:
- π 2 Tier-1 gateways (web & app tiers)
- π 3 overlay segments (web, app, db)
- π‘οΈ 3 security groups with tag-based criteria
- π₯ DFW micro-segmentation policies
- βοΈ Web tier load balancer with health monitoring
This module is licensed under the Apache License 2.0.