vmware / terraform-provider-nsxt

Terraform VMware NSX-T provider
https://www.terraform.io/docs/providers/nsxt/
Other
123 stars 80 forks source link

Error: PolicyUplinkHostSwitchProfile with name 'uplink-profile-edge' was not found #1236

Open shznkym opened 1 month ago

shznkym commented 1 month ago

Describe the bug

image

The following error is output even though there is an Uplink-Profile on the actual machine, named "uplink-profile-edge".

│ Error: PolicyUplinkHostSwitchProfile with name 'uplink-profile-edge' was not found │ │ with data.nsxt_policy_uplink_host_switch_profile.uplink_host_switch_profile, │ on 04_main_data_nsx.tf line 13, in data "nsxt_policy_uplink_host_switch_profile" "uplink_host_switch_profile": │ 13: data "nsxt_policy_uplink_host_switch_profile" "uplink_host_switch_profile" { │ ╵

================= data.tf ================= data "nsxt_policy_uplink_host_switch_profile" "uplink_host_switch_profile" { display_name = "uplink-profile-edge" }

================= resource.tf ================= resource "nsxt_edge_transport_node" "edge2" { description = "Terraform-deployed edge node" display_name = "edge2" standard_host_switch { ip_assignment { assigned_by_dhcp = true } transport_zone_endpoint { transport_zone = data.nsxt_policy_transport_zone.vlantz.id } transport_zone_endpoint { transport_zone = data.nsxt_policy_transport_zone.overlaytz.id }

host_switch_profile = [data.nsxt_policy_uplink_host_switch_profile.uplink_host_switch_profile.id]
pnic {
  device_name = "fp-eth0"
  uplink_name = "uplink-1"
}

} ...... (continued below)

Reproduction steps

  1. Execute terraform plan command
  2. ...

Expected behavior

Reads an existing Uplink Profile, and the Edge node is

Additional context

No response

shznkym commented 1 month ago

curl -k -u 'admin:password' -X GET "https://192.168.68.120/api/v1/host-switch-profiles"

{ "results" : [ { "teaming" : { "policy" : "FAILOVER_ORDER", "active_list" : [ { "uplink_name" : "uplink-1", "uplink_type" : "PNIC" } ] }, "named_teamings" : [ ], "transport_vlan" : 0, "overlay_encap" : "GENEVE", "resource_type" : "UplinkHostSwitchProfile", "id" : "325b48e7-3f9b-4aea-b8e2-de8f44aa003a", "display_name" : "uplink-profile-edge", "description" : "", "tags" : [ ], "_create_user" : "admin", "_create_time" : 1714630750441, "_last_modified_user" : "admin", "_last_modified_time" : 1718008778264, "_system_owned" : false, "_protection" : "NOT_PROTECTED", "_revision" : 4 }, { "teaming" : { "policy" : "FAILOVER_ORDER", "active_list" : [ { "uplink_name" : "uplink-1", "uplink_type" : "PNIC" } ], "standby_list" : [ { "uplink_name" : "uplink-2", "uplink_type" : "PNIC" } ] }, "named_teamings" : [ ], "transport_vlan" : 0, "overlay_encap" : "GENEVE", "resource_type" : "UplinkHostSwitchProfile", "id" : "18717311-f4f5-4c3a-8958-158643182ab4", "display_name" : "uplink-profile-esxi", "description" : "", "tags" : [ ], "_create_user" : "admin", "_create_time" : 1714627581116, "_last_modified_user" : "admin", "_last_modified_time" : 1718008815292, "_system_owned" : false, "_protection" : "NOT_PROTECTED", "_revision" : 8 } ], "result_count" : 2, "sort_by" : "display_name", "sort_ascending" : true }%

annakhm commented 1 month ago

Hi @shznkym, looks like you are trying to pull non-policy object api/v1/host-switch-profiles with policy API. Corresponding policy object would reside under API policy/api/v1/host-switch-profiles. Sorry for the duplication of APIs, this is indeed confusing, however this is what we have today. Eventually all APIs are expected to move to policy and non-policy ones will be deprecated and then removed. Hope this helps

shznkym commented 1 month ago
XXXXX terraform % terraform state list
data.nsxt_compute_manager.vc1
data.nsxt_policy_ip_pool.ip-pool
data.nsxt_policy_transport_zone.overlaytz
data.nsxt_policy_transport_zone.vlantz
**data.nsxt_policy_uplink_host_switch_profile.uplink-profile**
data.vsphere_compute_cluster.compute_cluster1
data.vsphere_datacenter.dc
data.vsphere_datastore.datastore1
data.vsphere_host.host1
data.vsphere_network.network1
nsxt_edge_transport_node.edge3
snakayama@J7W7NLWFQD terraform % 
XXXXX terraform % terraform state show **data.nsxt_policy_uplink_host_switch_profile.uplink-profile**
# data.nsxt_policy_uplink_host_switch_profile.uplink-profile:
data "nsxt_policy_uplink_host_switch_profile" "uplink-profile" {
    description  = null
    display_name = "uplink-profile"
    id           = "da09c60c-69f4-4729-a63b-6e506866aabe"
    **path         = "/infra/host-switch-profiles/da09c60c-69f4-4729-a63b-6e506866aabe"**
}
XXXXX terraform % 
data **"nsxt_policy_uplink_host_switch_profile" "uplink-profile"** {
  display_name = "uplink-profile"
}

resource "nsxt_edge_transport_node" "edge3" {
  description  = "Terraform-deployed edge node"
  display_name = "edge3"
  standard_host_switch {
    ip_assignment {
      static_ip_pool = data.nsxt_policy_ip_pool.ip-pool.realized_id
    }
    transport_zone_endpoint {
      transport_zone          = data.nsxt_policy_transport_zone.vlantz.id
    }
    transport_zone_endpoint {
      transport_zone          = data.nsxt_policy_transport_zone.overlaytz.id
    }

    **host_switch_profile = [data.nsxt_policy_uplink_host_switch_profile.uplink-profile.path]**
    pnic {
      device_name = "fp-eth0"
      uplink_name = "uplink-1"
    }
  }

Document [It didn't work.]

> https://registry.terraform.io/providers/vmware/nsxt/latest/docs/resources/edge_transport_node
> 
> [host_switch_profile]
>  (Optional) Identifiers of host switch profiles to be associated with this host switch.

    **host_switch_profile = [nsxt_policy_uplink_host_switch_profile.hsw_profile1.id]**
    pnic {
      device_name = "fp-eth0"
      uplink_name = "uplink1"
    }

[It worked.]

    **host_switch_profile = [data.nsxt_policy_uplink_host_switch_profile.uplink-profile.path]**
    pnic {
      device_name = "fp-eth0"
      uplink_name = "uplink-1"
    }

=================

The host_switch_profile should be rewritten in the document, as it is correct to specify the [path], not the [id].

id = "da09c60c-69f4-4729-a63b-6e506866aabe" path = "/infra/host-switch-profiles/da09c60c-69f4-4729-a63b-6e506866aabe

annakhm commented 1 month ago

Thank you, indeed documentation should be fixed