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

new resource_type vcd_vdc_group in data source vcd_resource_list #1012

Closed
carmine73 opened this issue Mar 6, 2023 · 20 comments
Closed

new resource_type vcd_vdc_group in data source vcd_resource_list #1012

carmine73 opened this issue Mar 6, 2023 · 20 comments
Assignees

Comments

@carmine73
Copy link

carmine73 commented Mar 6, 2023

Description

it would be nice to have vcd_vdc_group in data source vcd_resource_list as resource_type
https://registry.terraform.io/providers/vmware/vcd/latest/docs/data-sources/resource_list#resource_type

New or Affected Resource(s)

  • data source vcd_resource_list
@carmine73
Copy link
Author

carmine73 commented Oct 6, 2023

I have a question:
how can I get the list of edge gateway owned by a vdc group using vcd_resource_list?

## edge gateway list
data "vcd_resource_list" "edge_gws_list" {
  vdc           = var.my-vdc
  name          = "edge_gws_list"
  resource_type = "vcd_nsxt_edgegateway"
  list_mode     = "name"
}

the vdc is a mandatory field, but the edges do not belong to a vdc, so this list is empy

@dataclouder
Copy link
Contributor

The listing for edge gateways was made before we developed VDC groups, and this case was left incomplete.
We need to adapt the code to cover this case. At the moment vcd_resource_list is unable to get the list of edge gateways that depend on a VDC group.
I've opened Issue #1127 to track the problem

@dataclouder
Copy link
Contributor

Both vcd_vdc_group and vcd_nsxt_edgegateway are now available for listing with vcd_resource_list

@carmine73
Copy link
Author

carmine73 commented Oct 18, 2023

$ terraform version 
Terraform v1.6.1
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.11.0

ok with edge gateways

data "vcd_resource_list" "edge_gws_list" {
  parent        = local.my-vdc_group_name
  name          = "edge_gws_list"
  resource_type = "vcd_nsxt_edgegateway"
  list_mode     = "name"
}

but I can't get vdc groups list, do I miss something?

data "vcd_resource_list" "vdc_groups_list" {
  parent        = var.org.name
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

│ Error: [ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list,
│   on sdc-datasrc-myorg.tf line 341, in data "vcd_resource_list" "vdc_groups_list":
│  341: data "vcd_resource_list" "vdc_groups_list" {

@dataclouder
Copy link
Contributor

dataclouder commented Oct 18, 2023

You get that error when the organization is not found. Otherwise, even when the organization doesn't have any VDC groups, you should get a clean run.

@carmine73
Copy link
Author

carmine73 commented Oct 18, 2023

The org exists, in the same code I have:

## source org
data "vcd_org" "my-org" {
  name = var.org.name
}

output "my-org" {
  value       = data.vcd_org.my-org
  description = "Organization"
}

this is from plan output

  + my-org                        = {
      + can_publish_catalogs            = false
      + can_publish_external_catalogs   = false
      + can_subscribe_external_catalogs = false
      + delay_after_power_on_seconds    = 0
      + deployed_vm_quota               = 0
      + description                     = "Org di test IAAS"
      + full_name                       = "IAAS-TEST"
      + id                              = "urn:vcloud:org:55667e95-cb23-5cf7-9dab-07a0a1d90e66"
      + is_enabled                      = true
      + metadata                        = {}
      + metadata_entry                  = []

@dataclouder
Copy link
Contributor

dataclouder commented Oct 18, 2023

Please try this experiment:
in file vcd/datasource_vcd_resource_list.go

replace line 153 with

        return list, fmt.Errorf("error retrieving Org :%s", err)

then compile again (make fmt && make install) and run again your example.

@carmine73
Copy link
Author

carmine73 commented Oct 18, 2023

not sure I'm making the right thing

func getVdcGroups(d *schema.ResourceData, meta interface{}) (list []string, err error) {
	client := meta.(*VCDClient)

	org, err := client.GetAdminOrgByName(d.Get("org").(string))
	// return list, fmt.Errorf("error retrieving Org :%s", err) -> must replace 152-154 lines?
152:	if err != nil {
		return list, err
	}

@dataclouder
Copy link
Contributor

148 func getVdcGroups(d *schema.ResourceData, meta interface{}) (list []string, err error) {
 149     client := meta.(*VCDClient)
 150
 151     org, err := client.GetAdminOrgByName(d.Get("org").(string))
 152     if err != nil {
 153         return list, fmt.Errorf("error retrieving Org :%s", err)
 154     }
 155     vdcGroups, err := org.GetAllVdcGroups(nil)
 156     if err != nil {
 157         return list, err
 158     }

@carmine73
Copy link
Author

carmine73 commented Oct 18, 2023

the org is present, but

│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list,
│   on sdc-datasrc-myorg.tf line 341, in data "vcd_resource_list" "vdc_groups_list":
│  341: data "vcd_resource_list" "vdc_groups_list" {
│ 

One detail added: I'm an org admin

@carmine73
Copy link
Author

The result is the same as system admin

@dataclouder
Copy link
Contributor

The error message confirms that the organization was not found.

Either the Org has such a name that it defeats the data source, or the variable does not contain what it should.
Could you try entering the name of the organization literally, without the variable?
If it fails with a literal value and you are sure that the organization exists, I'd like to see the name, to figure out why it fails.

Would you be able to contact me on https://vmwarecode.slack.com, channel #vcd-terraform-dev?

@carmine73
Copy link
Author

Test done,
this is the pattern of the org name: "org-aa-bb-ccc-01-XXX-IAAS-TEST".

I'm org admin and var.org.name is used also in provider, so it exists:

provider "vcd" {
  user                 = var.admin_user
  password             = var.admin_pass
  org                  = var.org.name # default for resources
  url                  = local.region.vcd_url
  allow_unverified_ssl = local.region.vcd_allow_unverified_ssl
  logging              = true
  logging_file         = var.log_file
}

## source org
data "vcd_org" "my-org" {
  name = var.org.name
}

output "my-org" {
  value       = data.vcd_org.my-org
  description = "Organization"
}

## vdcs list
data "vcd_resource_list" "vdcs_list" {
  name          = "vdcs_list"
  resource_type = "vcd_org_vdc"
  list_mode     = "name"
}

output "vdcs_list" {
  value = data.vcd_resource_list.vdcs_list.list
}

# vcd_vdc_group list
data "vcd_resource_list" "vdc_groups_list_1" {
  parent        = var.org.name
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

# vcd_vdc_group list
data "vcd_resource_list" "vdc_groups_list_2" {
  parent        = data.vcd_org.my-org.name
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

# vcd_vdc_group list
data "vcd_resource_list" "vdc_groups_list_3" {
  parent        = "org-aa-bb-ccc-01-XXX-IAAS-TEST"
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

the output is:

$ terraform plan 
data.vcd_resource_list.vdc_groups_list_1: Reading...
data.vcd_org.my-org: Reading...
data.vcd_resource_list.vdc_groups_list_3: Reading...
data.vcd_resource_list.vdcs_list: Reading...
data.vcd_resource_list.vdcs_list: Read complete after 1s [id=vdcs_list]
data.vcd_org.my-org: Read complete after 1s [id=urn:vcloud:org:XXXXXXXXXXXXXXXXXX]
data.vcd_resource_list.vdc_groups_list_2: Reading...

Changes to Outputs:
  + my-org    = {
      + can_publish_catalogs            = false
      + can_publish_external_catalogs   = false
      + can_subscribe_external_catalogs = false
      + delay_after_power_on_seconds    = 0
      + deployed_vm_quota               = 0
      + description                     = "Org di test ...."
      + full_name                       = "XXX-IAAS-TEST"
      + id                              = "urn:vcloud:org:XXXXXXXXXXXXXXXXXX"
      + is_enabled                      = true
      + metadata                        = {}
      + metadata_entry                  = []
      + name                            = "org-aa-bb-ccc-01-XXX-IAAS-TEST"
      + stored_vm_quota                 = 0
      + vapp_lease                      = [
          + {
              + delete_on_storage_lease_expiration    = false
              + maximum_runtime_lease_in_sec          = 0
              + maximum_storage_lease_in_sec          = 0
              + power_off_on_runtime_lease_expiration = false
            },
        ]
      + vapp_template_lease             = [
          + {
              + delete_on_storage_lease_expiration = false
              + maximum_storage_lease_in_sec       = 0
            },
        ]
    }
  + vdcs_list = [
      + "ovdc-aa-bb-ccc-01-XXX-IAAS-TEST",
    ]

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
╷
│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list_1,
│   on sdc-datasrc-myorg.tf line 23, in data "vcd_resource_list" "vdc_groups_list_1":
│   23: data "vcd_resource_list" "vdc_groups_list_1" {
│ 
╵
╷
│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list_2,
│   on sdc-datasrc-myorg.tf line 31, in data "vcd_resource_list" "vdc_groups_list_2":
│   31: data "vcd_resource_list" "vdc_groups_list_2" {
│ 
╵
╷
│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list_3,
│   on sdc-datasrc-myorg.tf line 39, in data "vcd_resource_list" "vdc_groups_list_3":
│   39: data "vcd_resource_list" "vdc_groups_list_3" {
│ 
╵

@carmine73
Copy link
Author

I've done more tests, the error is not related to the org name pattern.
I've tried a different vcd environment with system admin login and I get the same error with this kind of org name:
aaa-name_1
name

This is my output when var.org.name is missing:

$ terraform plan 
data.vcd_resource_list.vdc_groups_list_3: Reading...
data.vcd_resource_list.vdcs_list: Reading...
data.vcd_org.my-org: Reading...
data.vcd_resource_list.vdc_groups_list_1: Reading...

Changes to Outputs:
  + my-orgname = "missingorg"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
╷
│ Error: org missingorg not found: [ENF] entity not found
│ 
│   with data.vcd_org.my-org,
│   on sdc-datasrc-myorg.tf line 7, in data "vcd_org" "my-org":
│    7: data "vcd_org" "my-org" {
│ 
╵
╷
│ Error: error retrieving Org missingorg: [ENF] entity not found
│ 
│   with data.vcd_resource_list.vdcs_list,
│   on sdc-datasrc-myorg.tf line 17, in data "vcd_resource_list" "vdcs_list":
│   17: data "vcd_resource_list" "vdcs_list" {
│ 
╵
╷
│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list_1,
│   on sdc-datasrc-myorg.tf line 28, in data "vcd_resource_list" "vdc_groups_list_1":
│   28: data "vcd_resource_list" "vdc_groups_list_1" {
│ 
╵
╷
│ Error: error retrieving Org :[ENF] entity not found
│ 
│   with data.vcd_resource_list.vdc_groups_list_3,
│   on sdc-datasrc-myorg.tf line 54, in data "vcd_resource_list" "vdc_groups_list_3":
│   54: data "vcd_resource_list" "vdc_groups_list_3" {
│ 
╵

@dataclouder
Copy link
Contributor

dataclouder commented Oct 19, 2023

Here's a possible explanation

The field "org" is mandatory for this list, but is missing, and replaced by "parent", which is not being considered at all.
Try replacing your script with this:

data "vcd_resource_list" "vdc_groups_list" {
  org           = var.org.name
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

@carmine73
Copy link
Author

great, it works.
org must be specified even if is defined at provider level (I thought I tried, sorry)

provider "vcd" {
  user                 = var.admin_user
  password             = var.admin_pass
  org                  = var.org.name # default for resources
  url                  = local.region.vcd_url
  allow_unverified_ssl = local.region.vcd_allow_unverified_ssl
  logging              = true
  logging_file         = var.log_file
}

# vcd_vdc_group list
data "vcd_resource_list" "vdc_groups_list_1" {
  org           = var.org.name
  name          = "vdc_groups_list"
  resource_type = "vcd_vdc_group"
  list_mode     = "name"
}

@carmine73
Copy link
Author

is there a release date for 3.11.0?

@dataclouder
Copy link
Contributor

org must be specified even if is defined at provider level

Yes.
I will make a change to treat the "org" parameter more sensibly.

is there a release date for 3.11.0?

Sorry, it's against company policy to announce release times.

@dataclouder
Copy link
Contributor

Issue addressed in PR #1140

@lvirbalas
Copy link
Collaborator

Sorry, it's against company policy to announce release times.

@carmine73 , we can't give dates, but at this point can give a preliminary update, which hopefully will be helpful. We are striving for our traditional holiday release at the end or beginning of the new year.

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

No branches or pull requests

4 participants