Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nutanix_subnets_v2 multiple filters fail #749

Open
tomrijnland opened this issue Feb 17, 2025 · 7 comments
Open

nutanix_subnets_v2 multiple filters fail #749

tomrijnland opened this issue Feb 17, 2025 · 7 comments
Assignees

Comments

@tomrijnland
Copy link

Nutanix Cluster Information

AOS 6.10.0.5
Prism Central 2024.3

Terraform Version

Terraform version v1.10.5

Affected Resource(s)

  • nutanix_subnets_v2

Terraform Configuration Files

This filter works

data "nutanix_subnets_v2" "subnets" {
  filter = "name eq '${var.subnet}'"
  limit  = 1
}

This filter with multiple attributes fails.

data "nutanix_subnets_v2" "subnets" {
  filter = "name eq '${var.subnet}' and cluster_reference eq '${var.cluster_reference}'"
  limit  = 1
}

Debug Output

│ Error: error while fetching subnets : {"data":{"error":[{"$reserved":{"$fv":"v4.r0"},"$objectType":"networking.v4.error.AppMessage","message":"Failed to list subnets due to a bad request - Odata Error: Error while parsing URI","severity":"ERROR","code":"NETWORKING-10002","locale":"en_US"}],"$reserved":{"$fv":"v4.r0"},"$objectType":"networking.v4.error.ErrorResponse"},"$reserved":{"$fv":"v4.r0"},"$objectType":"networking.v4.config.GetSubnetApiResponse","metadata":{"flags":[{"$reserved":{"$fv":"v1.r0"},"$objectType":"common.v1.config.Flag","name":"hasError","value":true},{"$reserved":{"$fv":"v1.r0"},"$objectType":"common.v1.config.Flag","name":"isPaginated","value":false},{"$reserved":{"$fv":"v1.r0"},"$objectType":"common.v1.config.Flag","name":"isTruncated","value":false}],"$reserved":{"$fv":"v1.r0"},"$objectType":"common.v1.response.ApiResponseMetadata","links":[{"$reserved":{"$fv":"v1.r0"},"$objectType":"common.v1.response.ApiLink","href":"https://x.x.x.x:9440/api/networking/v4.0/config/subnets","rel":"self"}],"totalAvailableResults":0}}

Panic Output

Expected Behavior

Should find the subnet for the given cluster.

Actual Behavior

Above error

Steps to Reproduce

  1. terraform apply

@tomrijnland
Copy link
Author

Found a workaround so Terraform deals with the filter instead of the API or Provider.

data "nutanix_subnets_v2" "subnets" {
    filter = "name eq '${var.subnet}'"
  }

locals {
  filtered_data = [
    for subnet in data.nutanix_subnets_v2.subnets.subnets : subnet
    if subnet["cluster_reference"] == var.cluster
  ]

  ext_id = length(local.filtered_data) > 0 ? local.filtered_data[0]["ext_id"] : null
}` 

@bhati-pradeep
Copy link
Collaborator

bhati-pradeep commented Feb 26, 2025

Hi @tomrijnland ,

Correct filter is name eq '${var.subnet}' and clusterReference eq '${var.cluster_reference}'

Please refer https://developers.nutanix.com/api-reference?namespace=networking&version=v4.0#tag/Subnets/operation/listSubnets Query parameters sections for more attributes

@bhati-pradeep
Copy link
Collaborator

Attribute names are in camel case and supported filter attributes are below as per doc:

clusterReference
extId
isExternal
name
subnetType
vpcReference

@bhati-pradeep
Copy link
Collaborator

@GullapalliAkhil @Haroon-Dweikat-Ntx Can we add some guide in docs for filters ?

@xerxist
Copy link

xerxist commented Feb 28, 2025

Im not sure if Terrafrom is the right place to directly make api calls like that. Now every time you have to look up the api calls reference. It feels very out of Terraform standards to work this way.

@bhati-pradeep
Copy link
Collaborator

bhati-pradeep commented Feb 28, 2025

I will note that down. We should have filters allowed attributes noted in provider docs. Will get that added 👍

@Haroon-Dweikat-Ntx
Copy link
Collaborator

Hi @xerxist

We will incorporate the allowed filter attributes into the provider documentation to clarify their usage. Thank you for bringing this to our attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants