vmware / terraform-provider-vcd

Terraform VMware Cloud Director provider
https://www.terraform.io/docs/providers/vcd/
Mozilla Public License 2.0
151 stars 112 forks source link

data source vcd_catalog_vapp_template does not handle duplicate names correctly, even if specified with unique catalog id #1331

Open jpbuecken opened 2 months ago

jpbuecken commented 2 months ago

Assume you have a shared catalog from org "other-org" and a local catalog in one org named "my-org"

Both catalogs have the same name.

In this example, lets name both catalogs "templates".

Assume you have a vapp template with the same name in it. Lets call it test_vapp_template.

Since the name is not unique, we specify the unique catalog_id in vcd_catalog_vapp_template.

Anyway the datasource vcd_catalog_vapp_template aborts with

data.vcd_catalog_vapp_template.vapp_template: Reading...
╷
│ Error: Unable to find vApp Template: unable to find vApp Template test_vapp_template: found 2 vApp Templates with name test_vapp_template in Catalog templates
│
│   with data.vcd_catalog_vapp_template.vapp_template,
│   on main.tf line 16, in data "vcd_catalog_vapp_template" "vapp_template":
│   16: data "vcd_catalog_vapp_template" "vapp_template" {
│
╵

But we specified a unique catalog_id, so it should not find the vapp template from the other catalog.

Terraform Version

Terraform v1.9.6
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.14.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

terraform {
  required_providers {
    vcd = {
      source  = "vmware/vcd"
      version = "3.14.0"
    }
  }
  required_version = ">= 1.9.6"
}

data "vcd_catalog" "catalog" {
   org = "other-org"
   name = "templates"
}

data "vcd_catalog_vapp_template" "vapp_template" {
  org = "other-org"
  catalog_id = data.vcd_catalog.catalog.id
  name       = "test_vapp_template"
}

Debug Output

We produced a debug log with:

export VCD_API_LOGGING_FILE=catalog.log                
export VCD_API_LOGGING=true

In this log, you can see the last api call does not respect the catalog_id, which is wrong. It only contains the name, and of course this is not unique:

2024/09/19 14:47:32 GET https://access.xxxxx/api/query?&type=vAppTemplate&filter=catalogName==templates;name==test_vapp_template

Expected Behavior

The data source should only find the uniq vapp template.

Actual Behavior

See initial description.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a catalog in "other-org" and share it to another org called "my-org"
  2. Create a catalog with the same name in "my-org"
  3. Use login credentials from "my-org"
  4. run terraform apply with above hcl
jpbuecken commented 2 months ago

Info, this also occurs if you use the "latest" parameter with the filter feature

filter { 
   latest = true
 } 

In that case it makes even less sence that it reports "found 2 vApp Templates" because this key word should make them unique