ionos-cloud/terraform-provider-ionoscloud

data servers resource with optional filtering

Closed this issue · 2 comments

Current Provider Version

 tf -version
Terraform v1.7.4
on linux_amd64
+ provider registry.terraform.io/ionos-cloud/ionoscloud v6.4.13

Use-cases

I would like to use the data resource for servers (plural) to get a list of all servers in the datacenter. Currently I need to define a filter which seems ambigous as the datacenter is already an required argument.

Example 1 - only using the datacenter_id:

data ionoscloud_servers example {
  datacenter_id = data.ionoscloud_datacenter.dc.id
}

i get an error message:

│ Error: Insufficient filter blocks
│
│   on main.tf line 24, in data "ionoscloud_servers" "example":
│   24: data ionoscloud_servers example {
│
│ At least 1 "filter" blocks are required.

Example 2 - Using an empty filter Block:

data ionoscloud_servers example {
  datacenter_id = data.ionoscloud_datacenter.dc.id
  filter {}
}

I get the error message:

│ Error: Missing required argument
│
│   on main.tf line 26, in data "ionoscloud_servers" "example":
│   26:   filter {}
│
│ The argument "value" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│
│   on main.tf line 26, in data "ionoscloud_servers" "example":
│   26:   filter {}
│
│ The argument "name" is required, but no definition was found.

Attempted Solutions

Implement the filter property optional or alternatively allow an empty filter map.

Meanwhile, as a workaround this might work and return all servers in the dc:

data "ionoscloud_servers" "datasource" {
  datacenter_id = "your id here"
  filter {
    name = "name"
    value = ""
  }
}

@cristiGuranIonos Thanks, the workaround works for me.