vmware / terraform-provider-vra

Terraform Provider for VMware Aria Automation
https://registry.terraform.io/providers/vmware/vra/
Mozilla Public License 2.0
103 stars 90 forks source link

Issue with region name being the same as `externalRegionId` #472

Open an2ane opened 1 year ago

an2ane commented 1 year ago

Code of Conduct

This project has a Code of Conduct that all participants are expected to understand and follow:

vRA Version

vRA Cloud 8.10.0

Terraform Version

0.12+

vRA Terraform Provider Version

0.6.0

Affected Resource(s)

vra_region vra_zone vra_cloud_account_vsphere

When creating a vra_cloud_account_vsphere resource, the related regions name share the same value as externalRegionId.

Terraform Configuration Files

data "vra_region_enumeration_vsphere" "this" {
  accept_self_signed_cert = false
  dc_id        = var.dc_id
  hostname    = var.vcenter_hostname
  username    = var.vcenter_username
  password    = var.vcenter_password
}

resource "vra_cloud_account_vsphere" "this" {
  name        = "tf-vsphere-account"
  description = "foobar"
  hostname    = var.vcenter_hostname
  username    = var.vcenter_username
  password    = var.vcenter_password
  dc_id        = var.dc_id

  regions                      = data.vra_region_enumeration_vsphere.this.regions
  associated_cloud_account_ids = []
  accept_self_signed_cert      = true
}

data "vra_region" "this" {
  filter = name eq "my_dc_name"
}

Expected Behavior

The way it was working with the vra provider 0.4.x was great. We had the name and the id from the vCenter, not the id set twice in name and externalRegionId variables

Actual Behavior

{
    "content": [
        {
            "externalRegionId": "Datacenter:datacenter-3",
            "name": "Datacenter:datacenter-3",
            "cloudAccountId": "cloudaccount_id",
            "id": "region_id",
            "updatedAt": "2022-10-24",
            "organizationId": "org_id",
            "orgId": "org_id",
            "_links": {
                "self": {
                    "href": "/iaas/api/regions/region_id"
                },
                "cloud-account": {
                    "href": "/iaas/api/cloud-accounts/cloudaccount_id"
                }
            }
        }
    ],
    "totalElements": 1,
    "numberOfElements": 1
}

Steps to Reproduce

terraform {
  required_version = ">= 0.12"
  required_providers {
    vra = {
      source = "vmware/vra"
      version = "0.6.0"
    }
  }
}
  1. terraform apply
  2. Make a GET API call to https://de.api.mgmt.cloud.vmware.com/iaas/api/regions
  3. See the name and externalRegionId being the same

Screenshots

result

Community Note

frodenas commented 1 year ago

Newer versions of the vRA API require setting the region id and name when creating a vSphere cloud account (older versions only required the id). The region name specified can be any name, it does not need to match the real name of the region, it's just an internal reference for the cloud account. When using the vRA UI you will see that the region name shown in the cloud account is not the one used at the cloud account creation API, it is the real region name, but when you use the API to retrieve the cloud account, you will get the name specified at creation time (and not the real region name).

This is a limitation we discovered when we upgraded the SDK version (#421 ). At that time we decided that making an extra call inside the Terraform provider to get the real region name was too expensive and that the limitation should be addressed inside vRA and not the terraform provider. Additionally, as this is something internal (we only show the id as part of the terraform resource schema), it should not affect end users (if this is not accurate, I'd like to understand your use case).

We currently have a story (internal reference #VRAE-12847) to address this limitation in vRA, but unfortunately, I cannot provide you any estimate on when this will be addressed.

an2ane commented 1 year ago

Hello Ferran.

When using the old 0.4.1 vra provider (as it was using the old sdk), we were fetching the vra_region not by its id but by its name, which is currently the same as the datacenter we have on vSphere. Since the new sdk, as you mentionned, the vra_region name is also required but set with the same value as the datacenter id, Datacenter:datacenter-3.

Even though it does create the region on vRA successfully, this is less friendly-user as it was created before the sdk update. Knowing the dc name is easier than knowing the dc id, when getting the vra_region. Is there another way to get the region_id without using?

data "vra_region" "this" {
  filter = "name eq '${var.vra_region_name}'"
}

Maybe a foreach on vra_region_enumration_vsphere?

Glad to hear the issue is tracked by the vRA team :)

an2ane commented 1 year ago

Hello @frodenas.

Do you have any update about VRAE-12847?

frodenas commented 1 year ago

@an2ane Unfortunately, I don't have any updates yet.

powertim commented 1 year ago

As deploying a new production stack, this bug is very confusing. I'd like this to be fixed.

BerryR-RBA commented 5 months ago

This is the interface for Cloud Accounts:

Datacenters

And this is the interface for Cloud Zones:

Regions

How do I know which region is which, without checking URLs in the vCenter?

BerryR-RBA commented 5 months ago

Hi @frodenas,

I understand that vRA limitations have made this difficult. But we now have a situation where deployed configurations are using externalRegionId as the name.

When the provider is fixed, how will we migrate to actual names without rebuilding our infrastructure?

Thanks Rob B.