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

Azure provider unable to delete multiple resources #2416

Closed
robodenitro opened this issue Jun 22, 2015 · 4 comments
Closed

Azure provider unable to delete multiple resources #2416

robodenitro opened this issue Jun 22, 2015 · 4 comments

Comments

@robodenitro
Copy link

I successfully create Azure virtual machine using such configuration file:

provider "azure" {
  settings_file = "azure.publishsettings"
}

resource "azure_storage_service" "mi-storage" {
  name = "test2321torage1"
  location = "West US"
  account_type = "Standard_LRS"
}

resource "azure_virtual_network" "mi-vnet" {
  name = "mynet"
  address_space = [ "10.0.0.0/8" ]
  subnet {
    name = "mysubnet"
    address_prefix = "10.0.0.0/24"
  }
  location = "West US"
}

resource "azure_instance" "mi-control" {
  name = "mi-node01"
  image = "RightImage-CentOS-7.0-x64-v14.2.1"
  size = "Small"
  subnet = "mysubnet"
  virtual_network = "mynet"
  storage_service_name = "test2321torage1"

  location = "West US"
  username = "centos"
  password = "P@ssw0rd"

}

When I'm trying to delete those resources with terraform destroy I get:

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

azure_instance.mi-control: Refreshing state... (ID: mi-node01)
azure_virtual_network.mi-vnet: Refreshing state... (ID: mynet)
azure_storage_service.mi-storage: Refreshing state... (ID: test2321torage1)
azure_instance.mi-control: Destroying...
azure_storage_service.mi-storage: Destroying...
azure_virtual_network.mi-vnet: Destroying...
azure_storage_service.mi-storage: Error: 1 error(s) occurred:

* Error whilst issuing deletion of storage service off Azure: Error response from Azure. Code: BadRequest, Message: Storage account test2321torage1 has some active image(s) and/or disk(s), e.g. mi-node01-mi-node01-0-201506220756050483. Ensure these image(s) and/or disk(s) are removed before deleting this storage account.
azure_instance.mi-control: Destruction complete
azure_virtual_network.mi-vnet: Error: 1 error(s) occurred:

* Error waiting for Virtual Network mynet to be deleted: Error response from Azure. Code: BadRequest, Message: Cannot delete or modify virtual network while in use 'mynet'.
Error applying plan:

2 error(s) occurred:

* Error whilst issuing deletion of storage service off Azure: Error response from Azure. Code: BadRequest, Message: Storage account test2321torage1 has some active image(s) and/or disk(s), e.g. mi-node01-mi-node01-0-201506220756050483. Ensure these image(s) and/or disk(s) are removed before deleting this storage account.
* Error waiting for Virtual Network mynet to be deleted: Error response from Azure. Code: BadRequest, Message: Cannot delete or modify virtual network while in use 'mynet'.

It seems that terraform is trying to destroy storage and virtual network resources before virtual machines which use them.

@keymon
Copy link
Contributor

keymon commented Aug 24, 2015

+1

I wonder if the issue might also be that the delete operations are executed asynchronously, so it did not really delete the VM and its disks before trying to delete the storage and network.

@aznashwan
Copy link
Contributor

@keymon @AndreySabitov: thanks a bunch for the report!

@keymon: you are indeed correct; Terraform keeps an internal record of all resources and the dependency relationships between them and operates on the resources as concurrently as possible.
This is not a bug; but one of Terraform's main features.
Terraform only sequentially deploys/updates/deletes resources which depend on each-other, which is something the user must indicate; either by adding the *depends_on* field and listing the dependencies, or by referencing depended resources with ${type.name.field} syntax in the definition of the depending one.

@AndreySabitov: the most straightforward approach here would be to set virtual_network = "${azure_virtual_network.mi-vnet.name}" and storage_service_name = "${azure_storage_service.mi-storage.name}" in the definition of the instance.

@xied75
Copy link

xied75 commented Nov 27, 2015

Looks like not really a bug, but the intended feature, suggest close the issue.

@catsby catsby closed this as completed Nov 8, 2016
@ghost
Copy link

ghost commented Apr 20, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants