### Monitor Segment Realization in Multi-Tenancy Setup Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_segment_realization.md This example demonstrates how to monitor segment realization within a multi-tenant environment using the project context. It ensures the segment is realized before a VM is provisioned on it. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_segment" "s1" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "segment1" } data "nsxt_policy_segment_realization" "s1" { context { project_id = data.nsxt_policy_project.demoproj.id } path = nsxt_policy_segment.s1.path } # usage in vsphere provider data "vsphere_network" "net" { name = nsxt_policy_segment_realization.s1.network_name datacenter_id = data.vsphere_datacenter.datacenter.id } ``` -------------------------------- ### Install Development Binary with Go Install Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/build.md Use `go install` to install the development binary of the NSX Terraform provider. This makes the provider available for use in your Terraform projects. ```sh go install ``` -------------------------------- ### NSXT Gateway Policy Basic Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_gateway_policy.md This example shows how to create a basic Gateway Policy with a single rule. Ensure that dependent resources like nsxt_policy_group and nsxt_policy_tier1_gateway are defined. ```hcl resource "nsxt_policy_gateway_policy" "test" { display_name = "tf-gw-policy" description = "Terraform provisioned Gateway Policy" category = "LocalGatewayRules" locked = false sequence_number = 3 stateful = true tcp_strict = false tag { scope = "color" tag = "orange" } rule { display_name = "rule1" destination_groups = [nsxt_policy_group.group1.path, nsxt_policy_group.group2.path] disabled = true action = "DROP" logged = true scope = [nsxt_policy_tier1_gateway.policygateway.path] } lifecycle { create_before_destroy = true } } ``` -------------------------------- ### Import IPSec VPN Session with Example Path Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_ipsec_vpn_session.md An example of importing an IPSec VPN session, demonstrating the expected format for the policy path. ```shell terraform import nsxt_policy_ipsec_vpn_session.test /infra/tier-1s/gw1/ipsec-vpn-services/svc1/sessions/session1 ``` -------------------------------- ### Example Usage - Multi-Tenancy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_ipv6_dad_profile.md Example of how to use the nsxt_policy_ipv6_dad_profile data source within a multi-tenancy context, specifying the project ID. ```APIDOC ## Example Usage - Multi-Tenancy ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } data "nsxt_policy_ipv6_dad_profile" "demodad6" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "demodad6" } ``` ``` -------------------------------- ### nsxt_policy_lb_fast_udp_application_profile Resource Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_lb_fast_udp_application_profile.md Example usage for creating a Load Balancer Fast UDP Application Profile resource. ```hcl resource "nsxt_policy_lb_fast_udp_application_profile" "test" { display_name = "test" description = "Terraform provisioned profile" idle_timeout = 120 flow_mirroring_enabled = true } ``` -------------------------------- ### Example Usage Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_ipv6_dad_profile.md Example of how to use the nsxt_policy_ipv6_dad_profile data source to retrieve an IPv6 DAD profile by its display name. ```APIDOC ## Example Usage ```hcl data "nsxt_policy_ipv6_dad_profile" "test" { display_name = "ipv6-dad-profile1" } ``` ``` -------------------------------- ### Get Realization Info for a Tier-1 Gateway on Global Manager Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_realization_info.md This example demonstrates fetching realization information for a Tier-1 Gateway specifically within a Global Manager context, requiring a site path. ```hcl data "nsxt_policy_tier1_gateway" "tier1_gw" { display_name = "tier1_gw" } data "nsxt_policy_site" "site" { display_name = "Paris" } data "nsxt_policy_realization_info" "info" { path = data.nsxt_policy_tier1_gateway.tier1_gw.path entity_type = "RealizedLogicalRouter" site_path = data.nsxt_policy_site.site.path } ``` -------------------------------- ### Configure Predefined Security Policy with Multi-Tenancy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_predefined_security_policy.md This example shows how to configure a predefined security policy within a specific project in a multi-tenant environment. It includes setting the project ID using a data source and defining policy rules similar to the single-tenant example. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } data "nsxt_policy_security_policy" "default_l3" { is_default = true category = "Application" } resource "nsxt_policy_predefined_security_policy" "test" { context { project_id = data.nsxt_policy_project.demoproj.id } path = data.nsxt_policy_security_policy.default_l3.path tag { scope = "color" tag = "orange" } rule { display_name = "allow_icmp" destination_groups = [nsxt_policy_group.cats.path, nsxt_policy_group.dogs.path] action = "ALLOW" services = [nsxt_policy_service.icmp.path] logged = true } rule { display_name = "allow_udp" source_groups = [nsxt_policy_group.fish.path] sources_excluded = true scope = [nsxt_policy_group.aquarium.path] action = "ALLOW" services = [nsxt_policy_service.udp.path] logged = true disabled = true } default_rule { action = "DROP" } } ``` -------------------------------- ### Example Usage of Policy Virtual Network Appliance Cluster Realization Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_virtual_network_appliance_cluster_realization.md This example demonstrates how to use the nsxt_policy_virtual_network_appliance_cluster_realization data source to wait for a VNA cluster to be fully realized. It defines a VNA cluster resource and then uses the data source to poll its realization state. ```hcl resource "nsxt_policy_virtual_network_appliance_cluster" "example" { display_name = "example-vna-cluster" appliance_form_factor = "MEDIUM" service_type = "VPC_SERVICES" member { edge_transport_node_path = data.nsxt_policy_edge_transport_node.edge1.path } advanced_configuration { overlay_transport_zone_path = data.nsxt_policy_transport_zone.overlay_tz.path } } data "nsxt_policy_virtual_network_appliance_cluster_realization" "wait" { path = nsxt_policy_virtual_network_appliance_cluster.example.path timeout = 1800 } ``` -------------------------------- ### nsxt_vpc_service_profile Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/vpc_service_profile.md This is an example of how to configure a VPC Service Profile using the nsxt_vpc_service_profile resource. It includes configurations for DHCP, DHCPv6, IPv6 profiles, and DNS forwarder. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_vpc_service_profile" "vpc1_service_profile" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "vpc1" description = "Terraform provisioned Vpc Service Profile" mac_discovery_profile = nsxt_policy_mac_discovery_profile.for_vpc1.path spoof_guard_profile = nsxt_policy_spoof_guard_profile.for_vpc1.path ip_discovery_profile = nsxt_policy_ip_discovery_profile.for_vpc1.path qos_profile = nsxt_policy_qos_profile.for_vpc1.path dhcp_config { dhcp_server_config { ntp_servers = ["20.2.60.5"] lease_time = 50840 dns_client_config { dns_server_ips = ["10.204.2.20"] } advanced_config { is_distributed_dhcp = false } } } dhcpv6_config { dhcpv6_server_config { lease_time = 86400 preferred_time = 69120 ntp_servers = ["2001:db8::1"] sntp_servers = ["2001:db8::2"] dns_client_config { dns_server_ips = ["2001:db8::53"] } advanced_config { is_distributed_dhcp = false } } } # Up to two paths: one IPv6 DAD profile and one NDRA profile (see data sources nsxt_policy_ipv6_dad_profile / nsxt_policy_ipv6_ndra_profile). ipv6_profile_paths = ["/orgs/default/projects/myproj/infra/ipv6-dad-profiles/dad1", "/orgs/default/projects/myproj/infra/ipv6-ndra-profiles/ndra1"] service_subnet_cidrs = ["fd12:3456::/64"] dns_forwarder_config { log_level = "INFO" } } ``` -------------------------------- ### nsxt_policy_site Resource Configuration Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_site.md Example of how to define and configure an nsxt_policy_site resource with its arguments. ```APIDOC ## nsxt_policy_site Resource ### Description This resource provides a method for the management of Policy Site. This resource is applicable to NSX Global Manager. ### Method Resource definition (Terraform HCL) ### Endpoint N/A (Terraform Resource) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `display_name` (Required) - Display name of the resource. * `description` (Optional) - Description of the resource. * `tag` (Optional) - A list of scope + tag pairs to associate with this resource. * `nsx_id` (Optional) - The NSX ID of this resource. If set, this ID will be used to create the resource. * `fail_if_rtep_misconfigured` (Optional) - Fail onboarding if RTEPs misconfigured. Default is true. * `fail_if_rtt_exceeded` (Optional) - Fail onboarding if maximum RTT exceeded. Default is true. * `maximum_rtt` (Optional) - Maximum acceptable packet round trip time (RTT). Default is 250. * `site_connection_info` (Optional) - Connection information. * `fqdn` (Optional) - Fully Qualified Domain Name of the Management Node. * `password` (Optional) - Password. * `site_uuid` (Optional) - ID of Site. This attribute is supported with NSX 4.1.0 onwards. * `thumbprint` (Optional) - Thumbprint of Enforcement Point. * `username` (Optional) - Username. * `site_type` (Required) - Persistent Site Type. Allowed values are `ONPREM_LM`, `SDDC_LM`. This attribute is supported with NSX 4.1.0 onwards. ### Request Example ```hcl resource "nsxt_policy_site" "test" { display_name = "test" description = "Terraform provisioned Site" site_connection_info { fqdn = "192.168.230.230" username = "admin" password = "somepasswd" thumbprint = "207d65dcb6f17aa5a1ef2365ee6ae0b396867baa92464e5f8a46f6853708b9ef" } site_type = "ONPREM_LM" } ``` ### Response #### Success Response (200) * `id` - ID of the resource. * `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. * `path` - The NSX path of the policy resource. #### Response Example (Terraform apply output will show resource creation status) ### Importing An existing object can be imported into this resource. ```shell terraform import nsxt_policy_site.test POLICY_PATH ``` The above command imports Site named `test` with policy path `POLICY_PATH`. ``` -------------------------------- ### NSXT Policy Transit Gateway Prefix List Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_transit_gateway_prefix_list.md This example demonstrates how to configure a prefix list on a Transit Gateway using the `nsxt_policy_transit_gateway_prefix_list` resource. It includes defining permit and deny rules with specific network ranges and prefix lengths. ```hcl data "nsxt_policy_project" "test_proj" { display_name = "test_project" } data "nsxt_policy_transit_gateway" "test_tgw" { context { project_id = data.nsxt_policy_project.test_proj.id } id = "default" } resource "nsxt_policy_transit_gateway_prefix_list" "example" { display_name = "my-prefix-list" description = "Prefix list for BGP route filtering" parent_path = data.nsxt_policy_transit_gateway.test_tgw.path prefix { action = "PERMIT" network = "10.0.0.0/8" } prefix { action = "DENY" network = "192.168.0.0/16" ge = 24 le = 32 } prefix { action = "DENY" } } ``` -------------------------------- ### Configure Intrusion Service Policy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_intrusion_service_policy.md This example demonstrates how to configure an Intrusion Service Policy with multiple rules, specifying actions, services, source/destination groups, and IDS profiles. It includes examples of different rule configurations like DETECT, DETECT_PREVENT, and EXEMPT actions, as well as options for direction, IP version, and exclusion. ```hcl data "nsxt_policy_intrusion_service_profile" "default" { display_name = "DefaultIDSProfile" } resource "nsxt_policy_intrusion_service_policy" "policy1" { display_name = "policy1" description = "Terraform provisioned Policy" category = "ThreatRules" locked = false rule { display_name = "rule1" action = "DETECT" services = [nsxt_policy_service.http.path] logged = true ids_profiles = [data.nsxt_policy_intrusion_service_profile.default.path] } rule { display_name = "rule2" description = "" action = "DETECT_PREVENT" direction = "IN" ip_version = "IPV4" oversubscription = "BYPASSED" source_groups = [nsxt_policy_group.external_clients.path] destination_groups = [nsxt_policy_group.web_servers.path] services = [nsxt_policy_service.https.path] notes = "Disabled till Sunday" ids_profiles = [data.nsxt_policy_intrusion_service_profile.default.path] logged = true disabled = true sources_excluded = true destinations_excluded = true } rule { display_name = "rule3" source_groups = [nsxt_policy_group.trusted_admins.path] destination_groups = [nsxt_policy_group.external_clients.path, nsxt_policy_group.db_servers.path] action = "EXEMPT" oversubscription = "DROPPED" ids_profiles = [data.nsxt_policy_intrusion_service_profile.default.path] } } ``` -------------------------------- ### nsxt_policy_connectivity_policy Resource Configuration Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_connectivity_policy.md Example of how to configure the nsxt_policy_connectivity_policy resource with required and optional arguments. ```APIDOC ## nsxt_policy_connectivity_policy Resource ### Description This resource provides a method for the management of TGW Connectivity Policy. This resource is applicable to NSX Policy Manager and is supported with NSX 9.1.0 onwards. ### Method CREATE, READ, UPDATE, DELETE (Implicitly managed by Terraform) ### Endpoint Not directly applicable as this is a Terraform resource definition. ### Parameters #### Arguments Reference * `display_name` (Required) - Display name of the resource. * `description` (Optional) - Description of the resource. * `parent_path` (Required) - Path of parent transit gateway. * `group_path` (Required) - Path of group that the policy is applied to. * `connectivity_scope` (Optional) - Either `COMMUNITY`, `ISOLATED` or `PROMISCUOUS`. Default is `COMMUNITY`. * `tag` (Optional) - A list of scope + tag pairs to associate with this resource. * `nsx_id` (Optional) - The NSX ID of this resource. If set, this ID will be used to create the resource. #### Attributes Reference (Exported) * `id` - ID of the resource. * `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. * `path` - The NSX path of the policy resource. * `internal_id` - Internal ID of the resource. ### Request Example ```hcl resource "nsxt_policy_connectivity_policy" "test" { display_name = "test" description = "Terraform provisioned Connectivity Policy" parent_path = data.nsxt_policy_transit_gateway.default.path group_path = data.nsxt_policy_group.test.path connectivity_scope = "COMMUNITY" } ``` ### Response Example (Terraform resource attributes are exported, not direct API responses in this context) * `id` - The unique identifier of the connectivity policy. * `path` - The NSX API path for the connectivity policy. * `revision` - The revision number of the object. * `internal_id` - The internal NSX identifier for the policy. ``` -------------------------------- ### Get Terraform Provider Version (Local Install) Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Check the installed Terraform provider version by running 'terraform version'. This example shows the output when the provider is installed locally. ```console $ terraform version Terraform x.y.z on linux_amd64 + provider local/vmware/nsxt x.y.z ``` -------------------------------- ### Create and look up role binding Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_user_management_role_binding.md This example demonstrates creating a role binding using the `nsxt_policy_user_management_role_binding` resource and then looking it up using both ID and name/type. ```hcl resource "nsxt_policy_user_management_role_binding" "test" { display_name = "johndoe@example.com" name = "johndoe@example.com" type = "remote_user" identity_source_type = "LDAP" roles_for_path { path = "/" roles = ["auditor"] } roles_for_path { path = "/orgs/default" roles = ["vpc_admin"] } } # Look up by ID data "nsxt_policy_user_management_role_binding" "by_id" { id = nsxt_policy_user_management_role_binding.test.id } # Look up by name and type data "nsxt_policy_user_management_role_binding" "by_name_type" { name = nsxt_policy_user_management_role_binding.test.name type = nsxt_policy_user_management_role_binding.test.type identity_source_id = nsxt_policy_user_management_role_binding.test.identity_source_id } ``` -------------------------------- ### Get Terraform Provider Version (Registry) Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Check the installed Terraform provider version by running 'terraform version'. This example shows the output when the provider is installed from the Terraform Registry. ```console $ terraform version Terraform x.y.z on linux_amd64 + provider registry.terraform.io/vmware/nsxt x.y.z ``` -------------------------------- ### NSXT Upgrade Prepare Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/upgrade_prepare.md Use this resource to prepare for an NSXT cluster upgrade. Ensure the NSXT username and password are provided in the NSXT provider configuration. The upgrade bundle and precheck bundle URLs are required. ```hcl resource "nsxt_upgrade_prepare" "test" { upgrade_bundle_url = "http://url-to-upgrade-bundle.mub" precheck_bundle_url = "http://url-to-precheck-bundle.pub" accept_user_agreement = true bundle_upload_timeout = 1600 uc_upgrade_timeout = 600 precheck_timeout = 1600 version = "4.1.2" } ``` -------------------------------- ### Example Usage of nsxt_upgrade_prepare_ready Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/upgrade_prepare_ready.md Use this data source to check upgrade readiness. It requires the ID of the corresponding nsxt_upgrade_prepare resource and can depend on nsxt_upgrade_precheck_acknowledge resources. ```hcl data "nsxt_upgrade_prepare_ready" "test" { depends_on = ["nsxt_upgrade_precheck_acknowledge.test"] upgrade_prepare_id = nsxt_upgrade_prepare.test.id } ``` -------------------------------- ### Get NSX Manager Information Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/manager_info.md Use this data source to retrieve information about the NSX manager. No setup or imports are required. ```hcl data "nsxt_manager_info" "cluster" {} ``` -------------------------------- ### Get NSXT Management Cluster Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/management_cluster.md Use this data source to retrieve information about the NSX-T management cluster. No setup or imports are required for this data source. ```hcl data "nsxt_management_cluster" "cluster" {} ``` -------------------------------- ### Configure BGP for T0 Gateway in Global Manager Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_bgp_config.md Example of configuring BGP settings for a Tier-0 Gateway within a Global Manager setup. This includes specifying the site path. ```hcl resource "nsxt_policy_bgp_config" "gw1-paris" { site_path = data.nsxt_policy_site.paris.path gateway_path = nsxt_policy_tier0_gateway.gw1.path enabled = true inter_sr_ibgp = true local_as_num = 60001 graceful_restart_mode = "HELPER_ONLY" graceful_restart_timer = 2400 route_aggregation { prefix = "20.1.0.0/24" summary_only = false } } ``` -------------------------------- ### Configure Gateway Policy with Project Context (Multi-Tenancy) Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_predefined_gateway_policy.md This example demonstrates configuring a predefined Gateway Policy within a specific project context for multi-tenancy environments. It uses data sources to retrieve project and gateway policy information. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } data "nsxt_policy_gateway_policy" "default" { category = "Default" } resource "nsxt_policy_predefined_gateway_policy" "test" { context { project_id = data.nsxt_policy_project.demoproj.id } path = data.nsxt_policy_gateway_policy.default.path tag { scope = "color" tag = "orange" } default_rule { scope = nsxt_policy_tier0_gateway.main.path logged = true log_label = "orange default" action = "ALLOW" } } ``` -------------------------------- ### Get VMs by Display Name Regex Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_vms.md This example shows how to filter VMs using a regular expression on their display name. It retrieves running VMs with display names matching the pattern '.*CLS*'. ```hcl data "nsxt_policy_vms" "all" { state = "running" value_type = "bios_id" display_name = ".*CLS*" } ``` -------------------------------- ### Create IP Address Allocation with Multi-Tenancy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_ip_address_allocation.md This example demonstrates creating an IP address allocation within a multi-tenancy environment. It requires specifying the project ID in the context. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_ip_pool" "pool1" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "ip_pool" description = "Created by Terraform" } resource "nsxt_policy_ip_pool_static_subnet" "static_subnet1" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "static-subnet1" pool_path = nsxt_policy_ip_pool.pool1.path cidr = "12.12.12.0/24" gateway = "12.12.12.1" allocation_range { start = "12.12.12.10" end = "12.12.12.20" } } resource "nsxt_policy_ip_address_allocation" "test" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "test" description = "Terraform provisioned IpAddressAllocation" pool_path = nsxt_policy_ip_pool.pool1.path allocation_ip = "12.12.12.12" } ``` -------------------------------- ### Get NSXT Policy IPv6 DAD Profile within a Project Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_ipv6_dad_profile.md This example shows how to retrieve an IPv6 DAD profile within a specific project. First, retrieve the project ID, then use it to query the DAD profile. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } data "nsxt_policy_ipv6_dad_profile" "demodad6" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "demodad6" } ``` -------------------------------- ### Get NSXT policy tags by scope Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_tags.md Use this data source to retrieve a list of tags associated with a specific scope. The scope argument supports various filtering options like starts with, ends with, equals, and contains. ```hcl data "nsxt_policy_tags" "tags" { scope = "dev" } ``` -------------------------------- ### Example nsxt_policy_project Resource Configuration Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_project.md This snippet shows a basic configuration for an nsxt_policy_project resource, including display name, description, short ID, and Tier-0 gateway paths. ```hcl resource "nsxt_policy_project" "test" { display_name = "test" description = "Terraform provisioned Project" short_id = "test" tier0_gateway_paths = ["/infra/tier-0s/test"] } ``` -------------------------------- ### Get parent policy metadata in a multi-tenancy context Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_parent_intrusion_service_policy.md This example shows how to retrieve parent intrusion service policy metadata within a specific project in a multi-tenant environment. It first fetches the project ID and then uses it within the context of the parent policy data source. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } data "nsxt_policy_parent_intrusion_service_policy" "parent_policy" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "production-ids-policy" } ``` -------------------------------- ### Configure IP Discovery Profile with Multi-Tenancy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_ip_discovery_profile.md This example demonstrates configuring an IP discovery profile within a specific project for multi-tenancy. It requires a data source to fetch the project ID. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_ip_discovery_profile" "ip_discovery_profile" { context { project_id = data.nsxt_policy_project.demoproj.id } description = "ip discovery profile provisioned by Terraform" display_name = "ip_discovery_profile1" arp_nd_binding_timeout = 20 duplicate_ip_detection_enabled = false arp_binding_limit = 140 arp_snooping_enabled = false dhcp_snooping_enabled = false vmtools_enabled = false dhcp_snooping_v6_enabled = false nd_snooping_enabled = false nd_snooping_limit = 12 vmtools_v6_enabled = false tofu_enabled = false tag { scope = "color" tag = "red" } } ``` -------------------------------- ### Get BMS Interface Tags Using BMS Interface Discovery Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_baremetal_server_interface_tags.md This example first discovers BMS interfaces and then retrieves tags for a specific interface using its discovered external ID. It then uses these tags to determine the network type and conditionally create an NSXT policy group. ```hcl # First discover BMS interfaces data "nsxt_policy_baremetal_server_interfaces" "data_interfaces" { bms_external_id = "71be0142-2ed1-1d53-9c60-5564cf4b7e2e" } # Then get tags for a specific interface data "nsxt_policy_baremetal_server_interface_tags" "interface_tags" { external_id = data.nsxt_policy_baremetal_server_interfaces.data_interfaces.results[0].external_id } # Use tags to determine network type locals { network_type = [ for tag in data.nsxt_policy_baremetal_server_interface_tags.interface_tags.tag : tag.tag if tag.scope == "network-type" ][0] } # Conditional resource creation based on network type resource "nsxt_policy_group" "data_plane_interfaces" { count = local.network_type == "data-plane" ? 1 : 0 display_name = "Data-Plane-Interfaces" criteria { condition { key = "Tag" member_type = "BareMetalServerInterface" operator = "EQUALS" value = "network-type|data-plane" } } } ``` -------------------------------- ### Configure DNS Forwarder with Multi-Tenancy Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_gateway_dns_forwarder.md This example demonstrates configuring a DNS Forwarder within a specific project context for multi-tenancy. It requires a data source to fetch the project ID. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_gateway_dns_forwarder" "test" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "test" description = "Terraform provisioned Zone" gateway_path = nsxt_policy_tier1_gateway.test.path listener_ip = "122.30.0.13" enabled = true log_level = "DEBUG" cache_size = 2048 default_forwarder_zone_path = nsxt_policy_dns_forwarder_zone.default.path conditional_forwarder_zone_paths = [nsxt_policy_dns_forwarder_zone.oranges.path, nsxt_policy_dns_forwarder_zone.apples.path] } ``` -------------------------------- ### nsxt_policy_virtual_network_appliance_cluster Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_virtual_network_appliance_cluster.md Example usage of the nsxt_policy_virtual_network_appliance_cluster resource to create a VNA cluster for VPC services. ```hcl data "nsxt_policy_transport_zone" "overlay_tz" { display_name = "overlay-tz" } resource "nsxt_policy_virtual_network_appliance_cluster" "example" { display_name = "vna-cluster-1" description = "VNA cluster for VPC services" appliance_form_factor = "MEDIUM" service_type = "VPC_SERVICES" advanced_configuration { core_allocation_profile = "L4LBSERVICE" overlay_transport_zone_path = data.nsxt_policy_transport_zone.overlay_tz.path } tag { scope = "environment" tag = "production" } } ``` -------------------------------- ### Basic VM Tagging Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_vm_tags.md Use this snippet to apply basic scope and tag pairs to a virtual machine. Ensure the 'vsphere_virtual_machine' resource and 'nsxt_policy_segment' are defined. ```hcl resource "nsxt_policy_vm_tags" "vm1_tags" { instance_id = vsphere_virtual_machine.vm1.id tag { scope = "color" tag = "blue" } tag { scope = "env" tag = "test" } port { segment_path = nsxt_policy_segment.seg1.path tag { tag { scope = "color" tag = "green" } } } } ``` -------------------------------- ### nsxt_policy_transport_zone Example Usage Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_transport_zone.md Terraform configuration examples for creating overlay and VLAN-backed transport zones. ```APIDOC ## Resource: nsxt_policy_transport_zone ### Description A resource to configure Policy Transport Zone. ### Argument Reference * `display_name` - (Optional) The Display Name of the Transport Zone. * `description` - (Optional) Description of the Transport Zone. * `tag` - (Optional) A list of scope + tag pairs to associate with this resource. * `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the policy resource. * `transport_type` - (Required) Transport type of requested Transport Zone, one of `OVERLAY_STANDARD`, `OVERLAY_ENS`, `OVERLAY_BACKED`, `VLAN_BACKED` and `UNKNOWN`. * `is_default` - (Optional) Set this Transport Zone as the default zone of given `transport_type`. Default value is `false`. When setting a Transport Zone with `is_default`: `true`, no existing Transport Zone of same `transport_type` should be set as default. * `uplink_teaming_policy_names` - (Optional) The names of switching uplink teaming policies that all transport nodes in this transport zone support. Uplink teaming policies are only valid for `VLAN_BACKED` transport zones. * `site_path` - (Optional) The path of the site which the Transport Zone belongs to. `path` field of the existing `nsxt_policy_site` can be used here. * `enforcement_point` - (Optional) The ID of enforcement point under given `site_path` to manage the Transport Zone. * `authorized_vlans` - (Optional) This field lists vlan ids allowed on logical network entities, eg. Segments, bridges, etc. created under this transport zone. Can be empty, VLAN id or a range of VLAN ids specified with '-' in between. An empty list allows all vlan ids. ### Attributes Reference In addition to arguments listed above, the following attributes are exported: * `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. * `path` - The NSX path of the policy resource. * `realized_id` - Realized ID for the transport zone. For reference in fabric resources (such as `transport_node`), `realized_id` should be used rather than `id`. ### Importing An existing Transport Zone can be imported into this resource, via the following command: ```shell terraform import nsxt_policy_transport_zone.overlay-tz POLICY_PATH ``` ### Example Usage ```hcl resource "nsxt_policy_transport_zone" "overlay_transport_zone" { display_name = "1-transportzone-87" transport_type = "OVERLAY_BACKED" } resource "nsxt_policy_transport_zone" "vlan_transport_zone" { display_name = "1-transportzone-87" description = "VLAN transport zone" transport_type = "VLAN_BACKED" is_default = true uplink_teaming_policy_names = ["teaming-1"] authorized_vlans = ["100", "110-120"] site_path = "/infra/sites/default" enforcement_point = "default" tag { scope = "app" tag = "web" } } ``` ``` -------------------------------- ### Install wget on macOS Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Use Homebrew to install wget on macOS if it is not already present. This is a prerequisite for downloading the provider. ```console brew install wget ``` -------------------------------- ### Create a Policy Group with VM Criteria Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_group.md This example demonstrates how to create a policy group that includes virtual machines based on their name and operating system. It requires a pre-defined project. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_group" "group1" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "tf-group1" description = "Terraform provisioned Group" criteria { condition { key = "Name" member_type = "VirtualMachine" operator = "STARTSWITH" value = "public" } condition { key = "OSName" member_type = "VirtualMachine" operator = "CONTAINS" value = "Ubuntu" } } } ``` -------------------------------- ### Tier1 Gateway Interface Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_gateway_interface.md Example of retrieving a Tier-1 gateway interface using its display name and gateway path. ```APIDOC ## Tier1 Gateway Interface Example ### Description Retrieves a Tier-1 gateway interface configuration. ### Method GET ### Endpoint `/policy/api/v1/infra/tier-1s/{tier1_id}/gateway-interfaces/{gateway_interface_id}` (Conceptual - actual API endpoint not provided in source) ### Parameters #### Query Parameters - **display_name** (string) - Required - The Display Name prefix of the gateway interface to retrieve. - **gateway_path** (string) - Required - The path of the Tier-1 gateway where the interface should be linked to. ### Request Example ```hcl data "nsxt_policy_tier1_gateway" "t1_gw" { display_name = "t1Gateway" } data "nsxt_policy_gateway_interface" "tier1_gw_interface" { display_name = "gw-interface2" gateway_path = data.nsxt_policy_tier1_gateway.t1_gw.path } ``` ### Response #### Success Response (200) - **id** (string) - ID of the interface. - **description** (string) - The description of the resource. - **path** (string) - The NSX path of the policy resource. #### Response Example ```json { "id": "interface-id-789", "description": "Example Tier-1 Gateway Interface", "path": "/infra/tier-1s/t1Gateway/gateway-interfaces/gw-interface2" } ``` ``` -------------------------------- ### Configure IP Pool with Multi-Tenancy Context Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_ip_pool.md This example demonstrates configuring an IP Pool within a specific project for multi-tenancy. It requires a data source to fetch the project ID. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_ip_pool" "pool1" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "ip-pool1" tag { scope = "color" tag = "blue" } tag { scope = "env" tag = "test" } } ``` -------------------------------- ### Configure DNS Forwarder Zone with Project Context Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_dns_forwarder_zone.md This example demonstrates configuring a DNS Forwarder Zone within a specific project using its ID. The `context` block with `project_id` is required for multi-tenancy. ```hcl data "nsxt_policy_project" "demoproj" { display_name = "demoproj" } resource "nsxt_policy_dns_forwarder_zone" "test" { context { project_id = data.nsxt_policy_project.demoproj.id } display_name = "test" description = "Terraform provisioned Zone" dns_domain_names = ["test.domain.org"] upstream_servers = ["33.14.0.2"] } ``` -------------------------------- ### Tier0 Gateway Interface Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_gateway_interface.md Example of how to retrieve a Tier-0 gateway interface using its display name and gateway path. ```APIDOC ## Tier0 Gateway Interface Example ### Description Retrieves a Tier-0 gateway interface configuration. ### Method GET ### Endpoint `/policy/api/v1/infra/tier-0s/{tier0_id}/gateway-interfaces/{gateway_interface_id}` (Conceptual - actual API endpoint not provided in source) ### Parameters #### Query Parameters - **display_name** (string) - Required - The Display Name prefix of the gateway interface to retrieve. - **gateway_path** (string) - Required - The path of the Tier-0 gateway where the interface should be linked to. ### Request Example ```hcl data "nsxt_policy_tier0_gateway" "t0_gw" { display_name = "t0Gateway" } data "nsxt_policy_gateway_interface" "tier0_gw_interface" { display_name = "gw-interface1" gateway_path = data.nsxt_policy_tier0_gateway.t0_gw.path } ``` ### Response #### Success Response (200) - **id** (string) - ID of the interface. - **description** (string) - The description of the resource. - **edge_cluster_path** (string) - The path of the Edge cluster where this gateway is placed. This attribute is not set for NSX Global Manager, where gateway can span across multiple sites. This attribute is set only for Tier0 gateways. - **path** (string) - The NSX path of the policy resource. - **segment_path** (string) - Policy path for segment which is connected to this Tier0 Gateway #### Response Example ```json { "id": "interface-id-123", "description": "Example Tier-0 Gateway Interface", "edge_cluster_path": "/infra/sites/default/edge-clusters/edge-cluster-1", "path": "/infra/tier-0s/t0Gateway/gateway-interfaces/gw-interface1", "segment_path": "/infra/segments/segment1" } ``` ``` -------------------------------- ### Enable Security Features on a Tier-0 Gateway Using Data Source Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_gateway_security_config.md This example shows how to enable IDPS and IDFW on a Tier-0 gateway by referencing the gateway's ID using a data source. This approach is useful for dynamically retrieving gateway information. ```hcl data "nsxt_policy_tier0_gateway" "tier0" { display_name = "DefaultT0Gateway" } resource "nsxt_policy_gateway_security_config" "tier0_security" { tier0_id = data.nsxt_policy_tier0_gateway.tier0.id idps_enabled = true idfw_enabled = true } ``` -------------------------------- ### Create a basic Context Profile Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/resources/policy_context_profile.md Use this snippet to create a basic context profile with domain name and application ID attributes. Ensure NSX version is 3.0.0 or later. ```hcl resource "nsxt_policy_context_profile" "test" { display_name = "test" description = "Terraform provisioned ContextProfile" domain_name { description = "test-domain-name-attribute" value = ["*-myfiles.sharepoint.com"] } app_id { description = "test-app-id-attribute" value = ["SSL"] sub_attribute { tls_version = ["SSL_V3"] } } } ``` -------------------------------- ### Tier0 Gateway Interface with Service Path Example Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/data-sources/policy_gateway_interface.md Example of retrieving a Tier-0 gateway interface using its display name and service path. ```APIDOC ## Tier0 Gateway Interface with Service Path Example ### Description Retrieves a Tier-0 gateway interface configuration using the service path. ### Method GET ### Endpoint `/policy/api/v1/infra/tier-0s/{tier0_id}/locale-services/{locale_service_id}/gateway-interfaces/{gateway_interface_id}` (Conceptual - actual API endpoint not provided in source) ### Parameters #### Query Parameters - **display_name** (string) - Required - The Display Name prefix of the gateway interface to retrieve. - **service_path** (string) - Required - The name of the locale service of the gateway to which interface is linked. Either service_path or gateway_path should be provided. ### Request Example ```hcl data "nsxt_policy_tier0_gateway" "t0_gw" { display_name = "t0Gateway" } data "nsxt_policy_gateway_locale_service" "test" { gateway_path = data.nsxt_policy_tier0_gateway.t0_gw.path } data "nsxt_policy_gateway_interface" "tier0_gw_interface" { display_name = "gw-interface1" service_path = data.nsxt_policy_gateway_locale_service.test.path } ``` ### Response #### Success Response (200) - **id** (string) - ID of the interface. - **description** (string) - The description of the resource. - **edge_cluster_path** (string) - The path of the Edge cluster where this gateway is placed. This attribute is not set for NSX Global Manager, where gateway can span across multiple sites. This attribute is set only for Tier0 gateways. - **path** (string) - The NSX path of the policy resource. - **segment_path** (string) - Policy path for segment which is connected to this Tier0 Gateway #### Response Example ```json { "id": "interface-id-456", "description": "Example Tier-0 Gateway Interface with Service Path", "edge_cluster_path": "/infra/sites/default/edge-clusters/edge-cluster-1", "path": "/infra/tier-0s/t0Gateway/locale-services/test/gateway-interfaces/gw-interface1", "segment_path": "/infra/segments/segment2" } ``` ``` -------------------------------- ### Verify NSX Provider Installation on macOS Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Navigate to the provider's directory and list its contents to verify that the NSX provider binary has been successfully installed. ```console cd ~/.terraform.d/plugins/local/vmware/nsxt/${RELEASE}/darwin_amd64 ls ``` -------------------------------- ### Initialize Terraform with Local Provider Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Run 'terraform init' in your working directory to initialize Terraform and download provider plugins. This command will detect and use the locally installed NSX provider. ```console $ terraform init Initializing the backend... Initializing provider plugins... - Finding local/vmware/nsxt versions matching ">= x.y.x" ... - Installing local/vmware/nsxt x.y.x ... - Installed local/vmware/nsxt x.y.x (unauthenticated) ... Terraform has been successfully initialized! ``` -------------------------------- ### Verify NSX Provider Installation on Windows Source: https://github.com/vmware/terraform-provider-nsxt/blob/master/docs/install.md Navigate to the provider's directory and list its contents using 'dir' to verify that the NSX provider executable has been successfully installed. ```powershell cd $ENV:APPDATA\terraform.d\plugins\local\vmware\nsxt\${RELEASE}\windows_amd64 dir ```