Skip to content

Commit

Permalink
UplinkHostSwitchProfile support (#939)
Browse files Browse the repository at this point in the history
Signed-off-by: graysonwu <[email protected]>
  • Loading branch information
GraysonWu authored Aug 22, 2023
1 parent a4307e9 commit 60cc731
Show file tree
Hide file tree
Showing 8 changed files with 1,022 additions and 1 deletion.
42 changes: 42 additions & 0 deletions nsxt/data_source_nsxt_uplink_host_switch_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra"
)

func dataSourceNsxtUplinkHostSwitchProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtUplinkHostSwitchProfileRead,

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"gateway_path": getPolicyPathSchema(false, false, "Gateway path"),
"path": getPathSchema(),
"display_name": getDisplayNameSchema(),
"description": getDescriptionSchema(),
},
}
}

func dataSourceNsxtUplinkHostSwitchProfileRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

gwPath := d.Get("gateway_path").(string)
query := make(map[string]string)
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}

_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), infra.HostSwitchProfiles_LIST_HOSTSWITCH_PROFILE_TYPE_POLICYUPLINKHOSTSWITCHPROFILE, query, false)
if err == nil {
return nil
}

return fmt.Errorf("UplinkHostSwitchProfile with name '%s' was not found", d.Get("display_name").(string))
}
8 changes: 8 additions & 0 deletions nsxt/policy_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func getDataSourceStringSchema(description string) *schema.Schema {
}
}

func getRequiredStringSchema(description string) *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Description: description,
Required: true,
}
}

func getDomainNameSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 2 additions & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func Provider() *schema.Provider {
"nsxt_policy_project": dataSourceNsxtPolicyProject(),
"nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(),
"nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(),
"nsxt_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -403,6 +404,7 @@ func Provider() *schema.Provider {
"nsxt_edge_cluster": resourceNsxtEdgeCluster(),
"nsxt_compute_manager": resourceNsxtComputeManager(),
"nsxt_manager_cluster": resourceNsxtManagerCluster(),
"nsxt_uplink_host_switch_profile": resourceNsxtUplinkHostSwitchProfile(),
},

ConfigureFunc: providerConfigure,
Expand Down
Loading

0 comments on commit 60cc731

Please sign in to comment.