Skip to content

Commit

Permalink
Address issue with nsxt_policy_uplink_host_switch_profile
Browse files Browse the repository at this point in the history
Uplink host switch profile data source does not retrieve the realized_id of the object.
It is also not retrievable with the nsxt_policy_realization_info data source, as the data returned by NSX doesn't contain this info, e.g

{
  "results" : [ {
    "entity_type" : "RZ_BASE_HOST_SWITCH_PROFILE",
    "intent_paths" : [ "/infra/host-switch-profiles/da7ea85b-e286-47bd-950e-bd7a8519c120" ],
    "resource_type" : "GenericPolicyRealizedResource",
    "id" : "da7ea85b-e286-47bd-950e-bd7a8519c120",
    "display_name" : "da7ea85b-e286-47bd-950e-bd7a8519c120",
    "path" : "/infra/realized-state/enforcement-points/default/host-switch-profiles/da7ea85b-e286-47bd-950e-bd7a8519c120",
    "relative_path" : "da7ea85b-e286-47bd-950e-bd7a8519c120",
    "parent_path" : "/infra/realized-state/enforcement-points/default",
    "remote_path" : "",
    "unique_id" : "5af90399-45ec-47f3-b884-e29cb79e06e0",
    "realization_id" : "5af90399-45ec-47f3-b884-e29cb79e06e0",
    "owner_id" : "4d4c5ded-c15f-49de-b7f6-cac9dbb48fbb",
    "intent_reference" : [ "/infra/host-switch-profiles/da7ea85b-e286-47bd-950e-bd7a8519c120" ],
    "state" : "REALIZED",
    "alarms" : [ ],
    "runtime_status" : "UNINITIALIZED",
    "publish_status" : "UNINITIALIZED",
    "_create_time" : 1722436827167,
    "_create_user" : "system",
    "_last_modified_time" : 1722436827167,
    "_last_modified_user" : "system",
    "_system_owned" : false,
    "_protection" : "NOT_PROTECTED",
    "_revision" : 0
  } ],
  "result_count" : 1
}

With no realization_specific_identifier attribute.

Signed-off-by: Kobi Samoray <kobi.samoray@broadcom.com>
  • Loading branch information
ksamoray committed Jul 31, 2024
1 parent 65aa2a7 commit f4afada
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions nsxt/data_source_nsxt_policy_uplink_host_switch_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package nsxt

import (
"fmt"
"github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"

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

func dataSourceNsxtUplinkHostSwitchProfile() *schema.Resource {
Expand All @@ -19,17 +21,29 @@ func dataSourceNsxtUplinkHostSwitchProfile() *schema.Resource {
"path": getPathSchema(),
"display_name": getDisplayNameSchema(),
"description": getDescriptionSchema(),
"realized_id": {
Type: schema.TypeString,
Description: "The ID of the realized resource",
Computed: true,
},
},
}
}

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

_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), infra.HostSwitchProfiles_LIST_HOSTSWITCH_PROFILE_TYPE_POLICYUPLINKHOSTSWITCHPROFILE, nil, false)
if err == nil {
return nil
obj, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), infra.HostSwitchProfiles_LIST_HOSTSWITCH_PROFILE_TYPE_POLICYUPLINKHOSTSWITCHPROFILE, nil, false)
if err != nil {
return fmt.Errorf("PolicyUplinkHostSwitchProfile with name '%s' was not found", d.Get("display_name").(string))
}
converter := bindings.NewTypeConverter()
dataValue, errors := converter.ConvertToGolang(obj, model.PolicyUplinkHostSwitchProfileBindingType())
if len(errors) > 0 {
return errors[0]
}
pool := dataValue.(model.PolicyUplinkHostSwitchProfile)
d.Set("realized_id", pool.RealizationId)

return fmt.Errorf("PolicyUplinkHostSwitchProfile with name '%s' was not found", d.Get("display_name").(string))
return nil
}
2 changes: 1 addition & 1 deletion website/docs/d/policy_ip_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ 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.
* `realized_id` - The id of realized pool object. This id should be used in `nsxt_transport_node` resource.
* `realized_id` - The id of realized pool object. This id should be used in `nsxt_edge_transport_node` resource.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ 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.
* `realized_id` - The id of realized pool object. This id should be used in `nsxt_edge_transport_node` resource.

0 comments on commit f4afada

Please sign in to comment.