cloud-ca / terraform-provider-cloudca

Terraform provider for cloud.ca
https://cloud.ca
MIT License
8 stars 10 forks source link

destroy not working for instance with data-volume #35

Closed pdion891 closed 7 years ago

pdion891 commented 7 years ago

Using cloudca_volume attached to cloudca_instance, terraform destroy not working with following error when VM is running:

$ terraform destroy
Do you really want to destroy?
  Terraform will delete all your managed infrastructure.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

cloudca_instance.tools_instance: Refreshing state... (ID: 17333242-a092-4bbf-bf4c-183bfb59afad)
cloudca_volume.db_volume: Refreshing state... (ID: 15045939-7a1c-4005-af55-14ab9f149b28)
cloudca_volume.db_volume: Destroying...
Error applying plan:

1 error(s) occurred:

* cloudca_volume.db_volume: [ERROR] Received HTTP status code 400
[ERROR] Error Code: 2705, Message: Cannot delete volumes which are attached to instances. Detach this volume from its instance to delete., Context: {"instanceId":"17333242-a092-4bbf-bf4c-183bfb59afad"}

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

resource definition:

resource "cloudca_instance" "tools_instance" {
  count = "${var.vm_count}"
  service_code = "${var.service_code}"
  environment_name = "${var.environment_name}"
  name = "${format("fio-node-%03d", count.index + 1)}"
  network_id = "${var.network_id}"
  template = "${var.template_name}"
  compute_offering = "${var.compute_offering}"
  ssh_key_name = "hackathon"
  user_data = "${file("cloudinit.yml")}"
  purge = true
}

resource "cloudca_volume" "db_volume" {
  count = "${var.disk_count}"
  service_code = "${var.service_code}"
  environment_name = "${var.environment_name}"

  name = "${format("DATA_lbtest-%03d_%d", count.index % var.vm_count, count.index)}"

  disk_offering = "${var.db_volume_name}"
  instance_id = "${element(cloudca_instance.tools_instance.*.id, count.index % var.vm_count)}"
}

It work if VM is shutdown.

pdion891 commented 7 years ago

Was because the state of the VM was not the same as how terraform left it when the VM was created.