Skip to content

GurdipSCode/devops-terraform-modules-nsx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

devops-terraform-modules-nsx

VMware NSX-T Terraform Provider Version

🌐 Terraform Module for VMware NSX-T

A comprehensive Terraform module for managing VMware NSX-T Data Center infrastructure using the Policy API.

License IaC Platform API Status


πŸ“¦ Architecture

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

🧩 Resources Managed

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

βœ… Prerequisites

Requirement Version / Detail
NSX-T NSX-T Data Center 3.x or 4.x
Terraform Terraform >= 1.5.0
Provider VMware NSX-T Terraform Provider >= 3.4.0

Infrastructure required:

  • πŸ”€ Existing Tier-0 gateway
  • πŸ–₯️ Existing Edge Cluster
  • 🌐 Existing Overlay Transport Zone

πŸš€ Quick Start

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
        }
      ]
    }
  }
}

πŸ“₯ Input Variables

Variable Type Required Description
nsx_manager_host string required NSX Manager FQDN or IP
nsx_username string required NSX Manager username
nsx_password string required NSX Manager password
overlay_transport_zone_name string required Overlay transport zone name
tier0_gateway_name string required Existing Tier-0 gateway name
edge_cluster_name string required Edge cluster name
tier1_gateways map(any) optional Tier-1 gateways to create
segments map(any) optional Overlay segments to create
security_groups map(any) optional Security groups to create
firewall_policies map(any) optional DFW policies with rules
load_balancers map(any) optional Load balancer configurations
default_tags map(string) optional Default tags for all resources

πŸ“€ Outputs

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

πŸ›‘οΈ Security Group Criteria Types

The module supports three types of group membership criteria:

🏷️ Tag-based (most common for micro-segmentation)

{ condition_type = "Tag", tag = "web", scope = "tier", member_type = "VirtualMachine" }

🌍 IP Address-based

{ condition_type = "IPAddress", ip_addresses = ["10.0.0.0/24", "10.0.1.0/24"] }

πŸ”— Segment-based

{ condition_type = "Segment", tag = "production" }

πŸ”₯ Firewall Rule Services

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.


πŸ—οΈ Example: 3-Tier Application

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

πŸ“„ License

License

This module is licensed under the Apache License 2.0.

About

OPA Policies for NSX Terraform module

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages