Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8209ca
Adding nsxt_policy_segment_port_binding resource and corresponding te…
aruntony005 Dec 18, 2025
6cadb61
Fixing doc lint
aruntony005 Dec 18, 2025
8e2e368
Fixing doc lint
aruntony005 Dec 18, 2025
6b709d9
Fixing doc lint
aruntony005 Dec 18, 2025
ab2e238
Fixing segment port binding multitenancy test
aruntony005 Dec 19, 2025
93ffb58
Fix policy_segment_port_binding test
ksamoray Dec 28, 2025
4fb14a3
Replace segment_path and segment_port_id with segment_port_path
ksamoray Dec 28, 2025
a798de2
Fixing segment_port_binding tests
aruntony005 Dec 29, 2025
1e9f08b
Renaming nsxt_policy_segment_port_binding to nsxt_policy_segment_port…
aruntony005 Dec 29, 2025
7845d64
Adding destroy logic for nsxt_policy_segment_port_profile_bindings
aruntony005 Dec 29, 2025
f07517f
Fixing lint
aruntony005 Dec 29, 2025
660d368
Fixing typo
aruntony005 Dec 30, 2025
9e7c4bf
Adding nsxt_policy_segment_ports data source to get a list of segment…
aruntony005 Dec 31, 2025
508601d
Updating the segment_port_profile_bindings documentation
aruntony005 Dec 31, 2025
f7daaf1
Updating the segment_port_profile_bindings documentation
aruntony005 Dec 31, 2025
369fc4b
Updating the segment_port_profile_bindings documentation
aruntony005 Jan 4, 2026
1b846d7
Updating the segment_port_profile_bindings documentation
aruntony005 Jan 4, 2026
ad34730
Adding resource import for segment_port_profile_bindings
aruntony005 Jan 5, 2026
8657362
Fixed doc lint
aruntony005 Jan 5, 2026
1a7dd63
Updating the destroy strategy and making the binding ID unique
aruntony005 Jan 6, 2026
6cce470
Making the profile binding import tests separate and updating the exa…
aruntony005 Jan 6, 2026
1d93823
Fixing lint
aruntony005 Jan 6, 2026
59e7404
Fixing lint
aruntony005 Jan 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions docs/data-sources/policy_segment_ports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
subcategory: "Segments"
page_title: "NSXT: nsxt_policy_segment_ports"
description: A data source to retrieve multiple Segment Ports based on filter criteria.
---

# nsxt_policy_segment_ports

This data source provides a method for retrieving multiple Segment Ports based on filter criteria. Unlike the singular `nsxt_policy_segment_port` data source, this returns a list of segment ports matching the specified filters.

## Example Usage

### Get all segment ports for a specific segment

```hcl
data "nsxt_policy_segment" "segment1" {
display_name = "segment1"
}

data "nsxt_policy_segment_ports" "all_ports" {
segment_path = data.nsxt_policy_segment.segment1.path
}

output "port_count" {
value = length(data.nsxt_policy_segment_ports.all_ports.items)
}

output "first_port_id" {
value = data.nsxt_policy_segment_ports.all_ports.items[0].id
}
```

### Get segment ports by segment path and display name

```hcl
data "nsxt_policy_segment" "segment1" {
display_name = "segment1"
}

data "nsxt_policy_segment_ports" "filtered_ports" {
segment_path = data.nsxt_policy_segment.segment1.path
display_name = "web-server-port"
}
```

### Get segment ports by VIF ID

```hcl
data "nsxt_policy_segment_ports" "by_vif" {
vif_id = "50234567-abcd-1234-5678-123456789abc"
}
```

### Get segment ports by VIF ID and display name

```hcl
# This will first filter by VIF ID, then filter the results by display name
data "nsxt_policy_segment_ports" "by_vif_and_name" {
vif_id = "50234567-abcd-1234-5678-123456789abc"
display_name = "web-server-port"
}
```

### Get segment ports by VIF ID and segment path

```hcl
data "nsxt_policy_segment" "segment1" {
display_name = "segment1"
}

# This will filter by both VIF ID and segment path
data "nsxt_policy_segment_ports" "by_vif_and_segment" {
vif_id = "50234567-abcd-1234-5678-123456789abc"
segment_path = data.nsxt_policy_segment.segment1.path
}
```

### Get segment ports by display name only

```hcl
# When only display_name is provided, behaves like the singular data source
data "nsxt_policy_segment_ports" "by_name" {
display_name = "web-server-port"
}
```

## Example Usage - Multi-Tenancy

```hcl
data "nsxt_policy_project" "demoproj" {
display_name = "demoproj"
}

data "nsxt_policy_segment" "segment1" {
context {
project_id = data.nsxt_policy_project.demoproj.id
}
display_name = "segment1"
}

data "nsxt_policy_segment_ports" "ports" {
context {
project_id = data.nsxt_policy_project.demoproj.id
}
segment_path = data.nsxt_policy_segment.segment1.path
}
```

## Argument Reference

The following arguments are supported:

* `context` - (Optional) The context which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to
* `vif_id` - (Optional) Segment Port attachment ID to filter segment ports. This takes priority over other filters.
* `segment_path` - (Optional) Segment path to filter segment ports. Can be combined with `vif_id` or `display_name`.
* `display_name` - (Optional) Display name to filter segment ports. When used with `vif_id`, filters the VIF results by display name. When used with `segment_path`, filters the segment's ports by display name. When used alone, searches all segment ports by display name.

~> **NOTE:** At least one of `vif_id`, `segment_path`, or `display_name` must be specified.

## Filter Priority

The data source applies filters in the following priority order:

1. **VIF ID** - If `vif_id` is set, it's used as the primary filter. Results can be further filtered by `segment_path` and/or `display_name`.
2. **Segment Path** - If `segment_path` is set (without `vif_id`), it filters ports by parent segment. Can be combined with `display_name`.
3. **Display Name** - If only `display_name` is set, it searches all segment ports by display name.

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `items` - List of segment ports matching the filter criteria. Each item contains:
* `id` - Unique identifier of the segment port.
* `display_name` - Display name of the segment port.
* `description` - Description of the segment port.
* `path` - Policy path of the segment port.
* `vif_id` - VIF attachment ID of the segment port (if attached).
* `segment_path` - Parent segment path of the segment port.
156 changes: 156 additions & 0 deletions docs/resources/policy_segment_port_profile_bindings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
subcategory: "Segments"
page_title: "NSXT: nsxt_policy_segment_port_profile_bindings"
description: A resource to configure profile bindings for an existing Segment Port.
---

# nsxt_policy_segment_port_profile_bindings

This resource provides a method for managing profile bindings (discovery, QoS, and security profiles) for an existing Segment Port. This resource is useful when you need to modify the profiles of a segment port that was created outside of Terraform or by another resource.

~> **NOTE:** This resource modifies an existing segment port's profile bindings. It does not create a new segment port. The segment port must already exist. Also try not to use this resource to modify the segment ports created using nsxt_policy_segment_port in the same terraform config. It will lead to conflicts.

## Example Usage

```hcl
data "nsxt_policy_segment" "segment1" {
display_name = "existing-segment"
}

data "nsxt_policy_segment_port" "existing_port" {
display_name = "existing-port"
segment_path = data.nsxt_policy_segment.segment1.path
}

data "nsxt_policy_ip_discovery_profile" "ip_profile" {
display_name = "default-ip-discovery-profile"
}

data "nsxt_policy_mac_discovery_profile" "mac_profile" {
display_name = "default-mac-discovery-profile"
}

resource "nsxt_policy_segment_port_profile_bindings" "existing_port_binding" {
segment_port_path = data.nsxt_policy_segment_port.existing_port.path
segment_path = data.nsxt_policy_segment.segment1.path

discovery_profile {
ip_discovery_profile_path = data.nsxt_policy_ip_discovery_profile.ip_profile.path
mac_discovery_profile_path = data.nsxt_policy_mac_discovery_profile.mac_profile.path
}
}
```

## Example Usage - Multi-Tenancy

```hcl
data "nsxt_policy_project" "demoproj" {
display_name = "demoproj"
}

resource "nsxt_policy_segment_port_profile_bindings" "port1_binding" {
context {
project_id = data.nsxt_policy_project.demoproj.id
}

segment_port_path = data.nsxt_policy_segment_port.existing_port.path
segment_path = data.nsxt_policy_segment.segment1.path

discovery_profile {
ip_discovery_profile_path = data.nsxt_policy_ip_discovery_profile.profile1.path
mac_discovery_profile_path = data.nsxt_policy_mac_discovery_profile.profile1.path
}

security_profile {
spoofguard_profile_path = data.nsxt_policy_spoofguard_profile.profile1.path
security_profile_path = data.nsxt_policy_segment_security_profile.profile1.path
}
}
```

## Example Usage - Using nsxt_policy_segment_ports data source

```hcl
data "nsxt_policy_segment_ports" "test" {
display_name = "segment-port1"
}

resource "nsxt_policy_segment_port_profile_bindings" "test" {
count = length(data.nsxt_policy_segment_ports.test.items)

segment_port_path = data.nsxt_policy_segment_ports.test.items[count.index].path

discovery_profile {
ip_discovery_profile_path = data.nsxt_policy_ip_discovery_profile.profile.path
mac_discovery_profile_path = data.nsxt_policy_mac_discovery_profile.profile.path
}

security_profile {
spoofguard_profile_path = data.nsxt_policy_spoofguard_profile.profile.path
security_profile_path = data.nsxt_policy_segment_security_profile.profile.path
}

qos_profile {
qos_profile_path = data.nsxt_policy_qos_profile.profile.path
}
}
```

## Argument Reference

The following arguments are supported:

* `segment_port_path` - (Required) The path of the existing segment port to bind profiles to.
* `context` - (Optional) The context which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to
* `discovery_profile` - (Optional) IP and MAC discovery profiles for this segment port.
* `ip_discovery_profile_path` - (Optional) Policy path of the IP Discovery Profile to bind.
* `mac_discovery_profile_path` - (Optional) Policy path of the MAC Discovery Profile to bind.
* `qos_profile` - (Optional) QoS profile for this segment port.
* `qos_profile_path` - (Required) Policy path of the QoS Profile to bind.
* `security_profile` - (Optional) Security profiles for this segment port.
* `spoofguard_profile_path` - (Optional) Policy path of the Spoofguard Profile to bind.
* `security_profile_path` - (Optional) Policy path of the Segment Security Profile to bind.

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `id` - ID of the Segment Port.
* `discovery_profile`:
* `binding_map_path` - Policy path of the discovery profile binding map.
* `revision` - Revision number of the binding map.
* `qos_profile`:
* `binding_map_path` - Policy path of the QoS profile binding map.
* `revision` - Revision number of the binding map.
* `security_profile`:
* `binding_map_path` - Policy path of the security profile binding map.
* `revision` - Revision number of the binding map.

## Resource Lifecycle

~> **NOTE:** This resource manages profile bindings for an existing segment port. When the resource is destroyed (via `terraform destroy` or resource removal), the profile bindings are set to the segment defaults.

## Importing

An existing segment port's profile bindings can be [imported][docs-import] into this resource, via the following command:

[docs-import]: https://www.terraform.io/cli/import

```shell
terraform import nsxt_policy_segment_port_profile_bindings.port1_bindings SEGMENT_PORT_PATH
```

The above command imports the profile bindings for the segment port named `port1_bindings` using its policy path.

For example:

```shell
terraform import nsxt_policy_segment_port_profile_bindings.port1_bindings /infra/segments/segment1/ports/port1
```

For multitenancy environments:

```shell
terraform import nsxt_policy_segment_port_profile_bindings.port1_bindings /orgs/default/projects/project1/infra/segments/segment1/ports/port1
```
Loading
Loading