vmware / terraform-provider-vra

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

Update of Cloud_Account_NSXT resource not possible #481

Closed BergCyrill closed 3 months ago

BergCyrill commented 1 year ago

vRA Version vRA 8.8.0

Terraform Version 1.0.0

vRA Terraform Provider Version 0.5.1

Affected Resource(s) vra_cloud_account_nsxt

When updating a vra_cloud_account_nsxt resource (e.g. changing the username & password), the apply step fail(s) with a 400 HTTP response.

Expected Behavior I would expect changes to the username or password for a already existant cloud_account_nsxt resource to update properly.

Actual Behavior After setting debug logging for the terraform apply step I could identify a "malformed" body for the API call.

PATCH /iaas/api/cloud-accounts-nsx-t/<my id>?apiVersion=2021-07-15 HTTP/1.1
Host: <my vRA host>
User-Agent: Go-http-client/1.1
Content-Length: 153
Accept: app/json
Accept: application/json
Authorization: Bearer <Token>
Content-Type: application/json
Accept-Encoding: gzip
{
 "associatedCloudAccountIds": null,
 "dcid": null,
 "description": "My Description for this cloud account",
 "hostName": null,
 "password": null,
 "tags": [],
 "username": null
}

The following response is provided by the vRA API:

---[ RESPONSE ]--------------------------------------
HTTP/1.1 400 Bad Request
[...]
{
 "message": "'username' is required.",
 "statusCode": 400,
 "errorCode": 0,
 "serverErrorId": "...",
 "documentKind": "com:vmware:xenon:common:ServiceErrorResponse"
}

I have identified in the resourceCloudAccountNSXTUpdate function, that only the description and tags values will be set in the body for the PATCH request: https://github.com/vmware/terraform-provider-vra/blob/964bfe38bf3dea9135dafa6d90f5cfd833755f09/vra/resource_cloud_account_nsxt.go#L186-L216.

tenthirtyam commented 11 months ago

Based on https://github.com/vmware/vra-sdk-go/blob/46d819a2bf81fd75b3d97342accc879939ae3050/pkg/models/update_cloud_account_nsx_t_specification.go this should be an easy fix; however, taking a quick look at the other cloud accounts appears to show that these also have the same issue.

BerryR-RBA commented 6 months ago

I'm having the same issue with a vra_cloud_account_vsphere resource:

Terraform will perform the following actions:

  # vra_cloud_account_vsphere.demo will be updated in-place
  ~ resource "vra_cloud_account_vsphere" "demo" {
        id                           = "3a7b26f3-f242-4fc0-b9fa-615767dad3af"
        name                         = "Demo Account"
      ~ regions                      = [
          + "Datacenter:datacenter-21226",
            # (1 unchanged element hidden)
        ]
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
vra_cloud_account_vsphere.demo: Modifying... [id=3a7b26f3-f242-4fc0-b9fa-615767dad3af]
╷
│ Error: response status code does not match any response statuses defined for this endpoint in the swagger spec (status 400): {}
│ 
│   with vra_cloud_account_vsphere.demo,
│   on main.tf line 11, in resource "vra_cloud_account_vsphere" "demo":
│   11: resource "vra_cloud_account_vsphere" "demo" {
│ 
╵

The error from the debug log is the same:

2024-02-23T14:21:29.676+1100 [INFO] provider.terraform-provider-vra_v0.8.6.exe: 2024/02/23 14:21:29 {"message":"'username' is required.","statusCode":400,"errorCode":0,"serverErrorId":"a7515183-f5ac-4d48-b195-7a42406cfcf5","documentKind":"com:vmware:xenon:common:ServiceErrorResponse"}: timestamp="2024-02-23T14:21:29.676+1100"