-
Notifications
You must be signed in to change notification settings - Fork 86
Adding nsxt_policy_segment_port_binding resource #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 6cadb61
Fixing doc lint
aruntony005 8e2e368
Fixing doc lint
aruntony005 6b709d9
Fixing doc lint
aruntony005 ab2e238
Fixing segment port binding multitenancy test
aruntony005 93ffb58
Fix policy_segment_port_binding test
ksamoray 4fb14a3
Replace segment_path and segment_port_id with segment_port_path
ksamoray a798de2
Fixing segment_port_binding tests
aruntony005 1e9f08b
Renaming nsxt_policy_segment_port_binding to nsxt_policy_segment_port…
aruntony005 7845d64
Adding destroy logic for nsxt_policy_segment_port_profile_bindings
aruntony005 f07517f
Fixing lint
aruntony005 660d368
Fixing typo
aruntony005 9e7c4bf
Adding nsxt_policy_segment_ports data source to get a list of segment…
aruntony005 508601d
Updating the segment_port_profile_bindings documentation
aruntony005 f7daaf1
Updating the segment_port_profile_bindings documentation
aruntony005 369fc4b
Updating the segment_port_profile_bindings documentation
aruntony005 1b846d7
Updating the segment_port_profile_bindings documentation
aruntony005 ad34730
Adding resource import for segment_port_profile_bindings
aruntony005 8657362
Fixed doc lint
aruntony005 1a7dd63
Updating the destroy strategy and making the binding ID unique
aruntony005 6cce470
Making the profile binding import tests separate and updating the exa…
aruntony005 1d93823
Fixing lint
aruntony005 59e7404
Fixing lint
aruntony005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.