VMware Cloud Director Terraform Provider

repository·main·Indexed 41 days ago

https://github.com/vmware/terraform-provider-vcd

The official Terraform provider for VMware Cloud Director (vCD), enabling infrastructure-as-code management of vCD resources using the go-vcloud-director SDK. It supports managing resources such as Data Solution Extensions (DSE), catalogs, vApp templates, and media items.

Tokens
292.2K
Snippets
780
Records
1.3K
Agent score
100%

What's inside VMware Cloud Director Terraform Provider

  1. Overview of VMware Avi Load Balancer in VCD

    main

    Starting with VCD version 10.2, VMware Cloud Director supports load balancing services via VMware Avi Load Balancer for VDCs backed by NSX-T.

    Key Concepts:

    • Controllers: Act as the central control plane. They must be registered with VCD to be managed.
    • Service Engine Groups: Organize the load balancing compute infrastructure. Multiple groups can be assigned to a single NSX-T Edge Gateway.
    • Scope: Load balancing services are associated with NSX-T Edge Gateways, which can be scoped to an organization VDC or a VDC Group.

    Requirements:

    • VCD version 10.2 or later.
    • Avi Load Balancer configured with NSX-T.
    • Terraform provider VCD version 3.4+ for Provider operations.
    • Terraform provider VCD version 3.5+ for Tenant operations.
  2. Manage NSX-T Security Groups with vcd_nsxt_security_group

    main

    The vcd_nsxt_security_group resource allows you to manage NSX-T Security Groups. Security Groups are collections of data center group networks used to apply distributed firewall rules. Grouping networks in this way reduces the total number of firewall rules required.

    Requirements:

    • Provider version v3.3+
    • VCD 10.1+ with NSX-T backed VDCs.

    Note on VDC Groups: Starting with provider version v3.6.0, support for VDC Groups was added. The vdc argument is deprecated. Instead, the resource now inherits VDC Group or VDC membership from the parent Edge Gateway specified via the edge_gateway_id field.

    resource "vcd_nsxt_security_group" "example" {
      edge_gateway_id = "some-edge-gateway-id"
      name            = "my-security-group"
      member_org_network_ids = ["network-id-1", "network-id-2"]
    }
  3. Manage VMware Cloud Director external networks with vcd_external_network

    main

    The vcd_external_network resource allows you to create and delete external networks in VMware Cloud Director. This resource requires system administrator privileges and is supported in provider version v2.2+.

    Note: This resource is deprecated in favor of vcd_external_network_v2. Use the v2 resource for new implementations.

    Key capabilities:

    • Define multiple ip_scope blocks to support different IP ranges.
    • Define multiple vsphere_network blocks to back the network with different vSphere objects.
    • Control whether network resources (like IP/MAC of a router) are retained across deployments using retain_net_info_across_deployments (defaults to false).
    provider "vcd" {
      user     = var.admin_user
      password = var.admin_password
      org      = "System"
      url      = "https://Vcd/api"
    }
    
    resource "vcd_external_network" "net" {
      name        = "my-ext-net"
      description = "Reference for vCD external network"
    
      ip_scope {
        gateway    = "192.168.30.49"
        netmask    = "255.255.255.240"
        dns1       = "192.168.0.164"
        dns2       = "192.168.0.196"
        dns_suffix = "mybiz.biz"
    
        static_ip_pool {
          start_address = "192.168.30.51"
          end_address   = "192.168.30.62"
        }
      }
    
      vsphere_network {
        name    = "myNetwork"
        type    = "DV_PORTGROUP"
        vcenter = "vcenter-name"
      }
    
      retain_net_info_across_deployments = false
    }
  4. Manage vApp firewall rules with vcd_vapp_firewall_rules

    main

    The vcd_vapp_firewall_rules resource allows you to create, modify, and delete firewall settings and rules within a VMware Cloud Director vApp network. These rules can be applied to vApp networks connected to Org networks or vApp org networks that are fenced.

    Warning: Using this resource overrides any existing firewall rules on the target vApp network. To avoid unintended rule deletion, it is recommended to have only one vcd_vapp_firewall_rules resource per vApp and vApp network.

    resource "vcd_vapp_firewall_rules" "vapp-fw" {
      vapp_id        = vcd_vapp.web.id
      network_id     = vcd_vapp_network.vapp-net.id
      default_action = "drop"
    
      rule {
        name             = "drop-ftp-out"
        policy           = "drop"
        protocol         = "tcp"
        destination_port = "21"
        destination_ip   = "any"
        source_port      = "any"
        source_ip        = "10.10.0.0/24"
      }
    
      rule {
        name             = "allow-outbound"
        policy           = "allow"
        protocol         = "any"
        destination_port = "any"
        destination_ip   = "any"
        source_port      = "any"
        source_ip        = "10.10.0.0/24"
      }
    }
  5. Manage NSX-T ALB Virtual Services with vcd_nsxt_alb_virtual_service

    main

    The vcd_nsxt_alb_virtual_service resource manages ALB Virtual services for a specific NSX-T Edge Gateway. A virtual service advertises an IP address and ports to the external world and directs incoming client traffic to members in an ALB Pool.

    Requirements:

    • Provider version: v3.5+
    • VCD version: 10.2+ with NSX-T and ALB enabled.

    Key Concepts:

    • Virtual IP: The service listens on a specific IP (virtual_ip_address or ipv6_virtual_ip_address).
    • Application Profile: Defines the traffic type via application_profile_type (e.g., HTTP, HTTPS, L4, L4_TLS).
    • Service Ports: You must define one or more service_port blocks to specify ports, ranges, and traffic types (e.g., TCP_PROXY).
    resource "vcd_nsxt_alb_virtual_service" "test" {
      org = "my-org"
      name = "new-virtual-service"
      edge_gateway_id = data.vcd_nsxt_edgegateway.existing.id
      pool_id = vcd_nsxt_alb_pool.test.id
      service_engine_group_id = vcd_nsxt_alb_edgegateway_service_engine_group.assignment.service_engine_group_id
      virtual_ip_address = tolist(data.vcd_nsxt_edgegateway.existing.subnet)[0].primary_ip
      application_profile_type = "HTTP"
      service_port {
        start_port = 80
        type = "TCP_PROXY"
      }
    }
  6. Read NSX-V firewall rules with vcd_nsxv_firewall_rule

    main

    The vcd_nsxv_firewall_rule data source allows you to retrieve information about an existing VMware Cloud Director firewall rule on an advanced edge gateway (NSX-V). Once retrieved, you can use the rule's attributes in other Terraform resources.

    Note: This data source requires an advanced edge gateway.

    data "vcd_nsxv_firewall_rule" "my-rule" {
      org          = "my-org"
      vdc          = "my-org-vdc"
      edge_gateway = "my-edge-gw"
    
      rule_id = "133048" # real firewall rule ID, not the UI number
    }
  7. Manage NSX-T Edge Gateway L2 VPN Tunnels with vcd_nsxt_edgegateway_l2_vpn_tunnel

    main

    The vcd_nsxt_edgegateway_l2_vpn_tunnel resource manages NSX-T Edge Gateway L2 VPN Tunnel sessions. This resource is supported in provider v3.11+ and VCD 10.4+ with NSX-T.

    Key Concepts

    • Session Modes: An Edge Gateway can function in either SERVER or CLIENT mode, but not both. You must create separate resources for the server-side and client-side sessions.
    • Endpoint IPs: The local_endpoint_ip must be sub-allocated on the Edge Gateway where the tunnel is being configured.
    • Peer Code Dependency: For CLIENT mode sessions, the peer_code argument is required. This value is computed by the SERVER mode session. Because the peer_code is updated when the server session changes, you may need to run terraform apply twice to ensure the client session correctly synchronizes with the server's configuration.
    • Stretched Networks: You can associate one or more stretched networks with the tunnel. In CLIENT mode, you must explicitly define a tunnel_id for every stretched network.
    # Example of a SERVER session
    resource "vcd_nsxt_edgegateway_l2_vpn_tunnel" "server-session" {
      org             = "datacloud"
      edge_gateway_id = data.vcd_nsxt_edgegateway.server-testing.id
      name            = "server-session"
      session_mode    = "SERVER"
      local_endpoint_ip  = "10.10.50.2"
      remote_endpoint_ip = "1.2.2.3"
      pre_shared_key     = "secret_passphrase"
    
      stretched_network {
        network_id = data.vcd_network_routed_v2.test_network_server.id
      }
    }
    
    # Example of a CLIENT session connecting to the server
    resource "vcd_nsxt_edgegateway_l2_vpn_tunnel" "client-session" {
      org             = "datacloud"
      edge_gateway_id = data.vcd_nsxt_edgegateway.client-testing.id
      name            = "client-session"
      session_mode     = "CLIENT"
      local_endpoint_ip  = "101.22.30.3"
      remote_endpoint_ip = "1.2.2.3"
    
      stretched_network {
        network_id = data.vcd_network_routed_v2.test_network_client.id
        tunnel_id  = 1
      }
    
      # Reference the computed peer_code from the server session
      peer_code = vcd_nsxt_edgegateway_l2_vpn_tunnel.server-session.peer_code
    }
  8. Manage VMware Cloud Director VM internal disks with vcd_vm_internal_disk

    main

    The vcd_vm_internal_disk resource allows you to create, update, and delete internal disks on existing Virtual Machines in VMware Cloud Director.

    Important Constraints:

    • VDC Fast Provisioning: Managing disks in a VM is only possible when VDC fast provisioning is disabled.
    • New VM Disk Configuration: To adjust disk parameters during the initial creation of a new VM, use the override_template_disk argument within the vapp_vm resource instead of this resource.
    • Disk Order: Bus and unit numbers do not guarantee the order in which the operating system detects disks. To ensure a specific disk presentation order, use Terraform depends_on clauses between disk resources.
    • Provider Version: Supported in provider v2.7+.
    • NVMe Support: nvme bus type requires provider v3.4.0+ and VCD 10.2.1+ or later.
    resource "vcd_vm_internal_disk" "disk1" {
      vapp_name       = "my-vapp"
      vm_name         = "my-vm1"
      bus_type        = "sata"
      size_in_mb      = "13333"
      bus_number      = 0
      unit_number     = 1
      storage_profile = "Development"
      allow_vm_reboot = true
      depends_on      = [vcd_vapp_vm.web1]
    }
  9. Manage Runtime Defined Entities with vcd_rde

    main

    The vcd_rde resource allows you to create, update, and delete Runtime Defined Entities (RDEs) in VMware Cloud Director.

    Important Note on Uniqueness: VCD allows multiple RDEs of the same RDE Type to share the same name. They are only distinguishable by their unique ID. When using data sources to fetch a specific RDE, ensure you are targeting the correct ID to avoid conflicts.

    resource "vcd_rde" "my_rde" {
      org          = "my-org"
      rde_type_id  = data.vcd_rde_type.my-type.id
      name         = "My custom RDE"
      resolve      = true
      input_entity = file("${path.module}/entities/custom-rde.json")
    }
  10. Manage VMware Cloud Director Org VDC isolated networks with vcd_network_isolated

    main

    The vcd_network_isolated resource provides a VMware Cloud Director Org VDC isolated Network. These networks are used to create internal networks for vApps to connect and are not attached to external networks or routers.

    Important Compatibility Note: This resource only supports NSX-V backed Org VDC networks. If you are using NSX-T, you must use the vcd_network_isolated_v2 resource instead.

    resource "vcd_network_isolated" "net" {
      org = "my-org" # Optional
      vdc = "my-vdc" # Optional
    
      name    = "my-net"
      gateway = "192.168.2.1"
      dns1    = "192.168.2.1"
    
      dhcp_pool {
        start_address = "192.168.2.2"
        end_address   = "192.168.2.50"
      }
    
      static_ip_pool {
        start_address = "192.168.2.51"
        end_address   = "192.168.2.100"
      }
    }
  11. Manage ALB General Settings with vcd_nsxt_alb_settings

    main

    The vcd_nsxt_alb_settings resource allows you to activate or deactivate Application Load Balancer (ALB) settings for a specific NSX-T Edge Gateway.

    Requirements:

    • Provider version: v3.5+
    • VCD version: 10.2+ with NSX-T and ALB enabled.
    • Permissions: Only a System Administrator can create this resource.

    Key Behaviors:

    • Activation/Deactivation: Use the is_active argument to enable or disable ALB.
    • Deletion: Deleting this resource will automatically set the ALB status to false (disabled) on the Edge Gateway.
    • Network Stacks:
      • If both service_network_specification and ipv6_service_network_specification are unset, a default IPv4 network (192.168.255.125/25) is used.
      • If both are set, the service engine group uses a dual IPv4 and IPv6 stack.
      • If only ipv6_service_network_specification is set, only IPv6 is used.
    resource "vcd_nsxt_alb_settings" "example" {
      org             = "my-org"
      edge_gateway_id = data.vcd_nsxt_edgegateway.existing.id
      is_active       = true
    }
  12. Manage NSX-T Application Port Profiles with vcd_nsxt_app_port_profile

    main

    The vcd_nsxt_app_port_profile resource allows you to manage NSX-T Application Port Profiles. These profiles consist of a combination of a protocol and a port (or a group of ports) used for Firewall and NAT services on the Edge Gateway. You can create custom profiles in addition to the default ones preconfigured for NSX-T Data Center.

    Requirements:

    • Provider version: v3.3+
    • VMware Cloud Director (VCD) version: 10.1+ with NSX-T backed VDCs.
    resource "vcd_nsxt_app_port_profile" "example" {
      org         = "my-org"
      name        = "example-profile"
      scope       = "TENANT"
      context_id  = "vdc-id-here"
    
      app_port {
        protocol = "TCP"
        port     = ["80", "443"]
      }
    }