diff --git a/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go b/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go index b2f87acc5..ed94566c1 100644 --- a/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go +++ b/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points/transport_node_collections" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" ) @@ -21,7 +20,12 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealization() *schema.Resour Read: dataSourceNsxtPolicyHostTransportNodeCollectionRealizationRead, Schema: map[string]*schema.Schema{ - "id": getDataSourceIDSchema(), + "path": { + Type: schema.TypeString, + Description: "Path of this Transport Node Collection", + Optional: true, + ValidateFunc: validatePolicyPath(), + }, "timeout": { Type: schema.TypeInt, Description: "Realization timeout in seconds", @@ -36,12 +40,6 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealization() *schema.Resour Default: 1, ValidateFunc: validation.IntAtLeast(0), }, - "site_path": { - Type: schema.TypeString, - Description: "Path of the site this Transport Node Collection belongs to", - Optional: true, - ValidateFunc: validatePolicyPath(), - }, "state": { Type: schema.TypeString, Description: "Application state of transport node profile on compute collection", @@ -58,11 +56,9 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealizationRead(d *schema.Re connector := getPolicyConnector(m) client := transport_node_collections.NewStateClient(connector) - objID := d.Get("id").(string) + path := d.Get("path").(string) delay := d.Get("delay").(int) timeout := d.Get("timeout").(int) - objSitePath := d.Get("site_path").(string) - objPolicyEnforcementPoint := getPolicyEnforcementPoint(m) pendingStates := []string{model.TransportNodeCollectionState_STATE_IN_PROGRESS} targetStates := []string{ @@ -72,31 +68,25 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealizationRead(d *schema.Re model.TransportNodeCollectionState_STATE_SUCCESS, } - // For local manager, if site path is not provided, use default site - if objSitePath == "" { - objSitePath = defaultSite + site, err := getParameterFromPolicyPath("/sites/", "/enforcement-points/", path) + if err != nil { + return fmt.Errorf("Invalid transport node collection path %s", path) } - if objID == "" { - // Find the host transport node collection if exists - tncClient := enforcement_points.NewTransportNodeCollectionsClient(connector) - objList, err := tncClient.List(objSitePath, objPolicyEnforcementPoint, nil, nil, nil) - if err != nil { - return handleListError("HostTransportNodeCollection", err) - } - - if len(objList.Results) != 1 { - return fmt.Errorf("Single HostTransportNodeCollection was not identified on %s/%s", objSitePath, objPolicyEnforcementPoint) - } - objID = *objList.Results[0].Id + + ep, err1 := getParameterFromPolicyPath("/enforcement-points/", "/transport-node-collections/", path) + if err1 != nil { + return fmt.Errorf("Invalid transport node collection path %s", path) } + objID := getPolicyIDFromPath(path) + stateConf := &resource.StateChangeConf{ Pending: pendingStates, Target: targetStates, Refresh: func() (interface{}, string, error) { - state, err := client.Get(objSitePath, getPolicyEnforcementPoint(m), objID) + state, err := client.Get(site, ep, objID) if err != nil { - return state, model.TransportNodeCollectionState_STATE_IN_PROGRESS, logAPIError("Error while waiting for realization of Transport Node Collection", err) + return state, model.TransportNodeCollectionState_STATE_IN_PROGRESS, logAPIError("Error getting collection state", err) } log.Printf("[DEBUG] Current realization state for Transport Node Collection %s is %s", objID, *state.State) @@ -113,7 +103,7 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealizationRead(d *schema.Re MinTimeout: 1 * time.Second, Delay: time.Duration(delay) * time.Second, } - _, err := stateConf.WaitForState() + _, err = stateConf.WaitForState() if err != nil { return err } @@ -121,7 +111,7 @@ func dataSourceNsxtPolicyHostTransportNodeCollectionRealizationRead(d *schema.Re } func getErrorFromState(state *model.TransportNodeCollectionState) error { - var result string + result := fmt.Sprintf("state: %s\n", *state.State) if state.ClusterLevelError != nil { result += fmt.Sprintf("cluster level error: %v\n", *state.ClusterLevelError) } diff --git a/website/docs/d/policy_host_transport_node_collection_realization.html.markdown b/website/docs/d/policy_host_transport_node_collection_realization.html.markdown index c2c11689c..13e478350 100644 --- a/website/docs/d/policy_host_transport_node_collection_realization.html.markdown +++ b/website/docs/d/policy_host_transport_node_collection_realization.html.markdown @@ -8,25 +8,24 @@ description: Host transport node collection realization information. # nsxt_policy_host_transport_node_collection_realization This data source provides information about the realization of host transport -node collection configured on NSX. This data source will wait until realization is -determined as either success or error. It is recommended to use this data source -if further configuration depends on host transport node collection realization. +node collection configured on NSX. This data source will fail if transport node collection +fails to realize. It is recommended to use this data source if further configuration +depends on host transport node collection realization. This data source is applicable to NSX Policy Manager. ## Example Usage ```hcl data "nsxt_policy_host_transport_node_collection_realization" "test" { - id = data.nsxt_policy_host_transport_node_collection.id + path = data.nsxt_policy_host_transport_node_collection.path } ``` ## Argument Reference -* `id` - (Optional) The ID of host transport node collection to retrieve information. +* `path` - (Optional) Policy path of Transport Node Collection. * `delay` - (Optional) Delay (in seconds) before realization polling is started. Default is set to 1. * `timeout` - (Optional) Timeout (in seconds) for realization polling. Default is set to 1200. -* `site_path` - (Optional) The path of the site which the Transport Node Collection belongs to. `path` field of the existing `nsxt_policy_site` can be used here. ## Attributes Reference