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

Virtual Machines Data Source does not like custom field of type multiple selection #627

Closed
jaket91-1 opened this issue Aug 12, 2024 · 1 comment

Comments

@jaket91-1
Copy link

I've run into an issue where the data type returned for a custom field in the netbox_virtual_machines data source does not match the expected type when the custom field is configured as Multiple selection, per below. All works when there is a custom field defined of type Text or no custom field defined, so it's definitely because of the Multiple selection type.

Terraform Version

❯ tofu --version
OpenTofu v1.6.0-dev
on darwin_amd64
+ provider registry.opentofu.org/e-breuninger/netbox v3.9.0

Netbox Version

v4.0.8

Affected Resource(s)

  • data.netbox_virtual_machines

Terraform Configuration Files

❯ cat main.tf

variable "pve_host" {
  type    = string
  default = "https://pve.xxx.com:8006"
}

locals {
  cluster_name = replace(var.pve_host, "/https://|:.*/", "")
}

data "netbox_cluster" "query" {
  name = local.cluster_name
}

data "netbox_virtual_machines" "list" {
  filter {
    name  = "cluster_id"
    value = data.netbox_cluster.query.id
  }

Debug Output

❯ tofu plan
data.netbox_cluster.query: Reading...
data.netbox_cluster.query: Read complete after 1s [id=2]
data.netbox_virtual_machines.list: Reading...

Planning failed. OpenTofu encountered an error while generating this plan.

╷
│ Error: vms.0.custom_fields.ansible_roles: '' expected type 'string', got unconvertible type '[]interface {}', value: '[base]'
│
│   with data.netbox_virtual_machines.list,
│   on main.tf line 24, in data "netbox_virtual_machines" "list":
│   24: data "netbox_virtual_machines" "list" {
│
╵

Expected Behavior

Map of VM's returned.

Actual Behavior

Type failure because of the custom field definition in Netbox.

Steps to Reproduce

  1. In Netbox, configure a VM custom field with the type Multiple selection
  2. Add the netbox_virtual_machines data source to your TF config
  3. terraform/tofu plan
@jaket91-1
Copy link
Author

Just found #443. Will close this.

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

1 participant