From bfd13938bba0390a1434efc60e899bec91e42aa3 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 16 Nov 2023 10:08:20 +0200 Subject: [PATCH] Implement host transport node profile data source Signed-off-by: Kobi Samoray --- ...nsxt_policy_host_transport_node_profile.go | 30 ++++ ...policy_host_transport_node_profile_test.go | 41 ++++++ nsxt/provider.go | 135 +++++++++--------- nsxt/utils_test.go | 4 + ..._host_transport_node_profile.html.markdown | 31 ++++ 5 files changed, 174 insertions(+), 67 deletions(-) create mode 100644 nsxt/data_source_nsxt_policy_host_transport_node_profile.go create mode 100644 nsxt/data_source_nsxt_policy_host_transport_node_profile_test.go create mode 100644 website/docs/d/policy_host_transport_node_profile.html.markdown diff --git a/nsxt/data_source_nsxt_policy_host_transport_node_profile.go b/nsxt/data_source_nsxt_policy_host_transport_node_profile.go new file mode 100644 index 000000000..71ad15580 --- /dev/null +++ b/nsxt/data_source_nsxt_policy_host_transport_node_profile.go @@ -0,0 +1,30 @@ +/* Copyright © 2023 VMware, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceNsxtPolicyHostTransportNodeProfile() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNsxtPolicyHostTransportNodeProfileRead, + + Schema: map[string]*schema.Schema{ + "id": getDataSourceIDSchema(), + "display_name": getDataSourceDisplayNameSchema(), + "description": getDataSourceDescriptionSchema(), + "path": getPathSchema(), + }, + } +} + +func dataSourceNsxtPolicyHostTransportNodeProfileRead(d *schema.ResourceData, m interface{}) error { + _, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "PolicyHostTransportNodeProfile", nil) + if err != nil { + return err + } + + return nil +} diff --git a/nsxt/data_source_nsxt_policy_host_transport_node_profile_test.go b/nsxt/data_source_nsxt_policy_host_transport_node_profile_test.go new file mode 100644 index 000000000..0c543f0ca --- /dev/null +++ b/nsxt/data_source_nsxt_policy_host_transport_node_profile_test.go @@ -0,0 +1,41 @@ +/* Copyright © 2023 VMware, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceNsxtPolicyHostTransportNodeProfile_basic(t *testing.T) { + htnpName := getHostTransportNodeProfileName() + testResourceName := "data.nsxt_policy_host_transport_node_profile.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccOnlyLocalManager(t) + testAccPreCheck(t) + testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE_PROFILE") + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccNSXHostTransportNodeProfileReadTemplate(htnpName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(testResourceName, "display_name", htnpName), + resource.TestCheckResourceAttrSet(testResourceName, "id"), + ), + }, + }, + }) +} + +func testAccNSXHostTransportNodeProfileReadTemplate(name string) string { + return fmt.Sprintf(` +data "nsxt_policy_host_transport_node_profile" "test" { + display_name = "%s" +}`, name) +} diff --git a/nsxt/provider.go b/nsxt/provider.go index 299f607c7..6d479b5b9 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -225,73 +225,74 @@ func Provider() *schema.Provider { }, DataSourcesMap: map[string]*schema.Resource{ - "nsxt_provider_info": dataSourceNsxtProviderInfo(), - "nsxt_transport_zone": dataSourceNsxtTransportZone(), - "nsxt_switching_profile": dataSourceNsxtSwitchingProfile(), - "nsxt_logical_tier0_router": dataSourceNsxtLogicalTier0Router(), - "nsxt_logical_tier1_router": dataSourceNsxtLogicalTier1Router(), - "nsxt_mac_pool": dataSourceNsxtMacPool(), - "nsxt_ns_group": dataSourceNsxtNsGroup(), - "nsxt_ns_groups": dataSourceNsxtNsGroups(), - "nsxt_ns_service": dataSourceNsxtNsService(), - "nsxt_ns_services": dataSourceNsxtNsServices(), - "nsxt_edge_cluster": dataSourceNsxtEdgeCluster(), - "nsxt_certificate": dataSourceNsxtCertificate(), - "nsxt_ip_pool": dataSourceNsxtIPPool(), - "nsxt_firewall_section": dataSourceNsxtFirewallSection(), - "nsxt_management_cluster": dataSourceNsxtManagementCluster(), - "nsxt_policy_edge_cluster": dataSourceNsxtPolicyEdgeCluster(), - "nsxt_policy_edge_node": dataSourceNsxtPolicyEdgeNode(), - "nsxt_policy_tier0_gateway": dataSourceNsxtPolicyTier0Gateway(), - "nsxt_policy_tier1_gateway": dataSourceNsxtPolicyTier1Gateway(), - "nsxt_policy_service": dataSourceNsxtPolicyService(), - "nsxt_policy_realization_info": dataSourceNsxtPolicyRealizationInfo(), - "nsxt_policy_segment_realization": dataSourceNsxtPolicySegmentRealization(), - "nsxt_policy_transport_zone": dataSourceNsxtPolicyTransportZone(), - "nsxt_policy_ip_discovery_profile": dataSourceNsxtPolicyIPDiscoveryProfile(), - "nsxt_policy_spoofguard_profile": dataSourceNsxtPolicySpoofGuardProfile(), - "nsxt_policy_qos_profile": dataSourceNsxtPolicyQosProfile(), - "nsxt_policy_ipv6_ndra_profile": dataSourceNsxtPolicyIpv6NdraProfile(), - "nsxt_policy_ipv6_dad_profile": dataSourceNsxtPolicyIpv6DadProfile(), - "nsxt_policy_gateway_qos_profile": dataSourceNsxtPolicyGatewayQosProfile(), - "nsxt_policy_segment_security_profile": dataSourceNsxtPolicySegmentSecurityProfile(), - "nsxt_policy_mac_discovery_profile": dataSourceNsxtPolicyMacDiscoveryProfile(), - "nsxt_policy_vm": dataSourceNsxtPolicyVM(), - "nsxt_policy_vms": dataSourceNsxtPolicyVMs(), - "nsxt_policy_lb_app_profile": dataSourceNsxtPolicyLBAppProfile(), - "nsxt_policy_lb_client_ssl_profile": dataSourceNsxtPolicyLBClientSslProfile(), - "nsxt_policy_lb_server_ssl_profile": dataSourceNsxtPolicyLBServerSslProfile(), - "nsxt_policy_lb_monitor": dataSourceNsxtPolicyLBMonitor(), - "nsxt_policy_certificate": dataSourceNsxtPolicyCertificate(), - "nsxt_policy_lb_persistence_profile": dataSourceNsxtPolicyLbPersistenceProfile(), - "nsxt_policy_vni_pool": dataSourceNsxtPolicyVniPool(), - "nsxt_policy_ip_block": dataSourceNsxtPolicyIPBlock(), - "nsxt_policy_ip_pool": dataSourceNsxtPolicyIPPool(), - "nsxt_policy_site": dataSourceNsxtPolicySite(), - "nsxt_policy_gateway_policy": dataSourceNsxtPolicyGatewayPolicy(), - "nsxt_policy_security_policy": dataSourceNsxtPolicySecurityPolicy(), - "nsxt_policy_group": dataSourceNsxtPolicyGroup(), - "nsxt_policy_context_profile": dataSourceNsxtPolicyContextProfile(), - "nsxt_policy_dhcp_server": dataSourceNsxtPolicyDhcpServer(), - "nsxt_policy_bfd_profile": dataSourceNsxtPolicyBfdProfile(), - "nsxt_policy_intrusion_service_profile": dataSourceNsxtPolicyIntrusionServiceProfile(), - "nsxt_policy_lb_service": dataSourceNsxtPolicyLbService(), - "nsxt_policy_gateway_locale_service": dataSourceNsxtPolicyGatewayLocaleService(), - "nsxt_policy_bridge_profile": dataSourceNsxtPolicyBridgeProfile(), - "nsxt_policy_ipsec_vpn_local_endpoint": dataSourceNsxtPolicyIPSecVpnLocalEndpoint(), - "nsxt_policy_ipsec_vpn_service": dataSourceNsxtPolicyIPSecVpnService(), - "nsxt_policy_l2_vpn_service": dataSourceNsxtPolicyL2VpnService(), - "nsxt_policy_segment": dataSourceNsxtPolicySegment(), - "nsxt_policy_project": dataSourceNsxtPolicyProject(), - "nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(), - "nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(), - "nsxt_policy_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(), - "nsxt_compute_manager": dataSourceNsxtComputeManager(), - "nsxt_transport_node_realization": dataSourceNsxtTransportNodeRealization(), - "nsxt_failure_domain": dataSourceNsxtFailureDomain(), - "nsxt_compute_collection": dataSourceNsxtComputeCollection(), - "nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(), - "nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(), + "nsxt_provider_info": dataSourceNsxtProviderInfo(), + "nsxt_transport_zone": dataSourceNsxtTransportZone(), + "nsxt_switching_profile": dataSourceNsxtSwitchingProfile(), + "nsxt_logical_tier0_router": dataSourceNsxtLogicalTier0Router(), + "nsxt_logical_tier1_router": dataSourceNsxtLogicalTier1Router(), + "nsxt_mac_pool": dataSourceNsxtMacPool(), + "nsxt_ns_group": dataSourceNsxtNsGroup(), + "nsxt_ns_groups": dataSourceNsxtNsGroups(), + "nsxt_ns_service": dataSourceNsxtNsService(), + "nsxt_ns_services": dataSourceNsxtNsServices(), + "nsxt_edge_cluster": dataSourceNsxtEdgeCluster(), + "nsxt_certificate": dataSourceNsxtCertificate(), + "nsxt_ip_pool": dataSourceNsxtIPPool(), + "nsxt_firewall_section": dataSourceNsxtFirewallSection(), + "nsxt_management_cluster": dataSourceNsxtManagementCluster(), + "nsxt_policy_edge_cluster": dataSourceNsxtPolicyEdgeCluster(), + "nsxt_policy_edge_node": dataSourceNsxtPolicyEdgeNode(), + "nsxt_policy_tier0_gateway": dataSourceNsxtPolicyTier0Gateway(), + "nsxt_policy_tier1_gateway": dataSourceNsxtPolicyTier1Gateway(), + "nsxt_policy_service": dataSourceNsxtPolicyService(), + "nsxt_policy_realization_info": dataSourceNsxtPolicyRealizationInfo(), + "nsxt_policy_segment_realization": dataSourceNsxtPolicySegmentRealization(), + "nsxt_policy_transport_zone": dataSourceNsxtPolicyTransportZone(), + "nsxt_policy_ip_discovery_profile": dataSourceNsxtPolicyIPDiscoveryProfile(), + "nsxt_policy_spoofguard_profile": dataSourceNsxtPolicySpoofGuardProfile(), + "nsxt_policy_qos_profile": dataSourceNsxtPolicyQosProfile(), + "nsxt_policy_ipv6_ndra_profile": dataSourceNsxtPolicyIpv6NdraProfile(), + "nsxt_policy_ipv6_dad_profile": dataSourceNsxtPolicyIpv6DadProfile(), + "nsxt_policy_gateway_qos_profile": dataSourceNsxtPolicyGatewayQosProfile(), + "nsxt_policy_segment_security_profile": dataSourceNsxtPolicySegmentSecurityProfile(), + "nsxt_policy_mac_discovery_profile": dataSourceNsxtPolicyMacDiscoveryProfile(), + "nsxt_policy_vm": dataSourceNsxtPolicyVM(), + "nsxt_policy_vms": dataSourceNsxtPolicyVMs(), + "nsxt_policy_lb_app_profile": dataSourceNsxtPolicyLBAppProfile(), + "nsxt_policy_lb_client_ssl_profile": dataSourceNsxtPolicyLBClientSslProfile(), + "nsxt_policy_lb_server_ssl_profile": dataSourceNsxtPolicyLBServerSslProfile(), + "nsxt_policy_lb_monitor": dataSourceNsxtPolicyLBMonitor(), + "nsxt_policy_certificate": dataSourceNsxtPolicyCertificate(), + "nsxt_policy_lb_persistence_profile": dataSourceNsxtPolicyLbPersistenceProfile(), + "nsxt_policy_vni_pool": dataSourceNsxtPolicyVniPool(), + "nsxt_policy_ip_block": dataSourceNsxtPolicyIPBlock(), + "nsxt_policy_ip_pool": dataSourceNsxtPolicyIPPool(), + "nsxt_policy_site": dataSourceNsxtPolicySite(), + "nsxt_policy_gateway_policy": dataSourceNsxtPolicyGatewayPolicy(), + "nsxt_policy_security_policy": dataSourceNsxtPolicySecurityPolicy(), + "nsxt_policy_group": dataSourceNsxtPolicyGroup(), + "nsxt_policy_context_profile": dataSourceNsxtPolicyContextProfile(), + "nsxt_policy_dhcp_server": dataSourceNsxtPolicyDhcpServer(), + "nsxt_policy_bfd_profile": dataSourceNsxtPolicyBfdProfile(), + "nsxt_policy_intrusion_service_profile": dataSourceNsxtPolicyIntrusionServiceProfile(), + "nsxt_policy_lb_service": dataSourceNsxtPolicyLbService(), + "nsxt_policy_gateway_locale_service": dataSourceNsxtPolicyGatewayLocaleService(), + "nsxt_policy_bridge_profile": dataSourceNsxtPolicyBridgeProfile(), + "nsxt_policy_ipsec_vpn_local_endpoint": dataSourceNsxtPolicyIPSecVpnLocalEndpoint(), + "nsxt_policy_ipsec_vpn_service": dataSourceNsxtPolicyIPSecVpnService(), + "nsxt_policy_l2_vpn_service": dataSourceNsxtPolicyL2VpnService(), + "nsxt_policy_segment": dataSourceNsxtPolicySegment(), + "nsxt_policy_project": dataSourceNsxtPolicyProject(), + "nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(), + "nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(), + "nsxt_policy_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(), + "nsxt_compute_manager": dataSourceNsxtComputeManager(), + "nsxt_transport_node_realization": dataSourceNsxtTransportNodeRealization(), + "nsxt_failure_domain": dataSourceNsxtFailureDomain(), + "nsxt_compute_collection": dataSourceNsxtComputeCollection(), + "nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(), + "nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(), + "nsxt_policy_host_transport_node_profile": dataSourceNsxtPolicyHostTransportNodeProfile(), }, ResourcesMap: map[string]*schema.Resource{ diff --git a/nsxt/utils_test.go b/nsxt/utils_test.go index 0235fcd34..c50e1ee21 100644 --- a/nsxt/utils_test.go +++ b/nsxt/utils_test.go @@ -131,6 +131,10 @@ func getHostTransportNodeName() string { return os.Getenv("NSXT_TEST_HOST_TRANSPORT_NODE") } +func getHostTransportNodeProfileName() string { + return os.Getenv("NSXT_TEST_HOST_TRANSPORT_NODE_PROFILE") +} + func getVlanTransportZoneName() string { name := os.Getenv("NSXT_TEST_VLAN_TRANSPORT_ZONE") if name == "" { diff --git a/website/docs/d/policy_host_transport_node_profile.html.markdown b/website/docs/d/policy_host_transport_node_profile.html.markdown new file mode 100644 index 000000000..17dd8784b --- /dev/null +++ b/website/docs/d/policy_host_transport_node_profile.html.markdown @@ -0,0 +1,31 @@ +--- +subcategory: "Beta" +layout: "nsxt" +page_title: "NSXT: nsxt_policy_host_transport_node_profile" +description: A host transport node profile data source. +--- + +# nsxt_policy_host_transport_node_profile + +This data source provides information about host transport node profile configured on NSX. +This data source is applicable to NSX Policy Manager. + +## Example Usage + +```hcl +data "nsxt_policy_host_transport_node_profile" "host_transport_node_profile" { + display_name = "host_transport_node_profile1" +} +``` + +## Argument Reference + +* `id` - (Optional) The ID of host transport node profile to retrieve. +* `display_name` - (Optional) The Display Name prefix of the host transport node profile to retrieve. + +## Attributes Reference + +In addition to arguments listed above, the following attributes are exported: + +* `description` - The description of the resource. +* `path` - The NSX path of the policy resource.