Open kingsleyck opened 1 year ago
Hi, it seems you have more than one cluster with same name. You can fetch the cluster details with cluster_uuid as well .
data "nutanix_cluster" "cluster" {
cluster_id = "{{ id }} "
}
In this case Prism Central does not have two clusters with the same name. The issue is not limited to one cluster's name, either. Any cluster name tested produces the same result. The behavior of this resource is different between pc.2022.1.0.2 and pc.2022.6.0.1. It works as expected on pc.2022.1.0.2 (name argument returns a single cluster).
To collect another data point, I used the nutanix_clusters data source with a for loop:
variable "cluster_name" {
default = CLUSTERNAME
}
data "nutanix_clusters" "clusters" {}
output "clusters" {
value = [
for entity in data.nutanix_clusters.clusters.entities : entity.name if entity.name == var.cluster_name
]
}
Which returns the following:
Changes to Outputs:
+ clusters = [
+ "CLUSTERNAME",
+ "CLUSTERNAME",
]
There are two cluster entities returned whose properties are all identical (uuid, name, etc). This result is unexpected given neither the GUI nor REST API v3/clusters/list display or return 2 cluster entities with the same name.
Can you please collect the Trace log and share it ? Have to check the response from /clusters/list API.
export TF_LOG=TRACE
Also, you can confirm whether the API returns with 2 cluster entities. Trace log will help how API is returning the response vs how we are handling it.
POST /api/nutanix/v3/clusters/list HTTP/1.1
Host: prism.fqdn:9440
User-Agent: nutanix/v3
Content-Length: 44
Accept: application/json
Authorization: Basic <removed>
Content-Type: application/json
Accept-Encoding: gzip
{
"filter": "",
"kind": "cluster",
"length": 100
}
-----------------------------------------------------: timestamp=2023-02-03T11:47:19.615-0700
2023-02-03T11:47:21.539-0700 [DEBUG] provider.terraform-provider-nutanix_v1.7.1.exe: {"@level":"info","@message":"2023/02/03 11:47:21 [DEBUG] Nutanix API
Response Details:\n---[ RESPONSE ]--------------------------------------\nHTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nContent-Security-Policy:
default-src 'self' https://*.nutanix.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; connect-src 'self' wss:
https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src 'self' blob: data:; frame-src 'self' https://*.nutanix.com blob:
data:\r\nContent-Type: application/json\r\nDate: Fri, 03 Feb 2023 18:47:20 GMT\r\nServer: envoy\r\nSet-Cookie: <ommitted>; Expires=Fri, 03-Feb-2023 19:02:21 GMT; Secure; HttpOnly;
Path=/; SameSite=Lax\r\nStrict-Transport-Security: max-age=8640000:includeSubdomains\r\nVary: Accept-Encoding\r\nX-Content-Type-Options:
nosniff\r\nX-Dns-Prefetch-Control: off\r\nX-Envoy-Upstream-Service-Time: 1414\r\nX-Frame-Options: SAMEORIGIN\r\nX-Ntnx-Env: pc\r\nX-Ntnx-Product:
pc.2022.6.0.1\r\nX-Permitted-Cross-Domain-Policies: master-only\r\nX-Xss-Protection: 1; mode=block\r\n\r\n8b2d6\r\n{\n \"api_version\": \"3.1\",\n
\"metadata\": {\n \"total_matches\": 122,\n \"kind\": \"cluster\"\n },\n \"entities\": [\n {\n \"status\": {\n \"state\": \"COMPLETE\",\n
\"name\": \"CLUSTERNAME\",\n \"resources\": {\n \"nodes\": {\n \"hypervisor_server_list\": [\n {\n \"ip\": \"<removed>\",\n (removed remainder)
...
<repeats same API call and output three times>
...
2023-02-03T11:47:24.427-0700 [INFO] provider.terraform-provider-nutanix_v1.7.1.exe: 2023/02/03 11:47:24 [Debug] total=122, remaining=-78, offset=200
len(entities)=244: timestamp=2023-02-03T11:47:24.427-0700
[0m[1mdata.nutanix_clusters.clusters: Still reading... [10s elapsed][0m[0m
[0m[1mdata.nutanix_clusters.clusters: Read complete after 11s [id=terraform-20230203184726004500000001][0m
2023-02-03T11:47:30.612-0700 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from
server: EOF"
2023-02-03T11:47:30.623-0700 [DEBUG] provider: plugin process exited:
path=.terraform/providers/registry.terraform.io/nutanix/nutanix/1.7.1/windows_amd64/terraform-provider-nutanix_v1.7.1.exe pid=7268
2023-02-03T11:47:30.623-0700 [DEBUG] provider: plugin exited
2023-02-03T11:47:30.684-0700 [DEBUG] building apply graph to check for errors
2023-02-03T11:47:30.684-0700 [DEBUG] ProviderTransformer: "data.nutanix_clusters.clusters (expand)" (*terraform.nodeExpandApplyableResource) needs
provider["registry.terraform.io/nutanix/nutanix"]
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "data.nutanix_clusters.clusters (expand)" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "var.nutanix_username" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "var.nutanix_password" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "var.nutanix_endpoint" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "var.nutanix_port" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "var.cluster_name" references: []
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "output.clusters (expand)" references: [data.nutanix_clusters.clusters (expand)
var.cluster_name]
2023-02-03T11:47:30.684-0700 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/nutanix/nutanix\"]" references: [var.nutanix_port
var.nutanix_username var.nutanix_endpoint var.nutanix_password]
2023-02-03T11:47:30.684-0700 [DEBUG] pruneUnusedNodes: data.nutanix_clusters.clusters (expand) is no longer needed, removing
2023-02-03T11:47:30.684-0700 [DEBUG] pruneUnusedNodes: provider["registry.terraform.io/nutanix/nutanix"] is no longer needed, removing
2023-02-03T11:47:30.684-0700 [INFO] backend/local: plan operation completed
[0m
[1mChanges to Outputs:[0m[0m
[32m+[0m [0m[1m[0mclusters[0m[0m = [
[32m+[0m [0m"CLUSTERNAME",
[32m+[0m [0m"CLUSTERNAME",
]
This Prism Central has 122 clusters attached. I sanitized and removed most of the API return for legibility. Based on the API call above to clusters/list I would expect to see an offset added to a subsequent call, with only two API calls required to retrieve all 122 entities. Instead it is sending 3 separate calls with length 100 and no offset specified. It's not clear to me why it is making 3 API calls when only 2 would be required.
Nutanix Cluster Information
Terraform Version
Terraform v1.3.7 on windows_amd64
Affected Resource(s)
data "nutanix_cluster"
Terraform Configuration Files
Actual Behavior
Steps to Reproduce
terraform apply
Important Factors
0000 <!---Github Issue number --->