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

Improve error handling on incorrect API calls #112

Closed
yannickstruyf3 opened this issue Apr 6, 2020 · 2 comments · Fixed by #134
Closed

Improve error handling on incorrect API calls #112

yannickstruyf3 opened this issue Apr 6, 2020 · 2 comments · Fixed by #134

Comments

@yannickstruyf3
Copy link
Collaborator

yannickstruyf3 commented Apr 6, 2020

When performing 'incorrect' API calls via the terraform provider, the "status" field on the API is being set to "error". Trying to shrink disks will cause this state.

This state makes it impossible to use Terraform afterwards.

The only way of getting the VM out of error state is the following:

  • Retrieve the UUID of the virtual machine (should be in your statefile)
  • Perform a GET request on https://<< Prism IP >>:9440/api/nutanix/v3/vms/<< VM UUID >>
  • Take the output, remove the “status” key from the JSON
  • Perform a PUT request using the retrieved payload on https://<< Prism IP >>:9440/api/nutanix/v3/vms/<< VM UUID >>

Improving error handling should resolve this issue.

@PacoDw
Copy link
Contributor

PacoDw commented May 11, 2020

Could you share the configuration or the steps to recreate the issue?

@yannickstruyf3
Copy link
Collaborator Author

yannickstruyf3 commented May 12, 2020

To force this error you can perform following steps:
First create a vm:

resource "nutanix_virtual_machine" "vm" {
  name                  = "mytest"
  cluster_uuid          = "my-cluster-uuid"
  num_vcpus_per_socket  = "1"
  num_sockets           = "2"
  memory_size_mib       = 2048
  power_state_mechanism = "ACPI"

  disk_list {
    disk_size_bytes = 40 * 1024 * 1024 * 1024
  }
}

After creation, shrink the disk (not supported):

resource "nutanix_virtual_machine" "vm" {
resource "nutanix_virtual_machine" "vm" {
  name                  = "mytest"
  cluster_uuid          = "my-cluster-uuid"
  num_vcpus_per_socket  = "1"
  num_sockets           = "2"
  memory_size_mib       = 2048
  power_state_mechanism = "ACPI"

  disk_list {
    disk_size_bytes = 20 * 1024 * 1024 * 1024
  }
}

Will result in failures of the next plan, apply, destroy:
Error: error waiting for vm (vmid) to update: error_detail: INVALID_ARGUMENT: NotSupported: Can't shrink disk at scsi.0 of VM vmid., progress_message: update_vm

The only way to resolve this situation is by performing the manual steps listed in the issue or deleting the VM via the UI.

PacoDw added a commit that referenced this issue Jun 19, 2020
fix #112: Improve error handling on incorrect API calls
yannickstruyf3 pushed a commit to yannickstruyf3/terraform-provider-nutanix that referenced this issue Nov 9, 2021
fix nutanix#112: Improve error handling on incorrect API calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants