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

azurerm refresh fails when a storage account is missing #6725

Closed
cchildress opened this issue May 17, 2016 · 3 comments · Fixed by #6855
Closed

azurerm refresh fails when a storage account is missing #6725

cchildress opened this issue May 17, 2016 · 3 comments · Fixed by #6855

Comments

@cchildress
Copy link
Contributor

cchildress commented May 17, 2016

Description

If a storage account is removed from the Azure web portal terraform fails to handle the missing resource gracefully. This affects refresh, plan, and apply. It looks like terraform is trying to query information about storage containers inside the account before querying the account itself, so it doesn't realize that they will be gone as well.
Not being able to refresh the state files is a bit annoying though. Here are the workarounds I've found so far:

  • Go to the Azure portal and recreate enough resources manually to help Terraform find what it expects.
  • Just delete all your resource groups and re-deploy everything.
  • Edit the state file and remove the resources you think are gone from there.

Terraform Version

0.6.15

Affected Resource(s)

  • azurerm_storage_container
  • azurerm_storage_account

Terraform Configuration Files

resource "azurerm_storage_account" "an_storage_std" {
  name = "anstoragestandard"
  resource_group_name = "${azurerm_resource_group.an_prod.name}"
  location = "westeurope"
  account_type = "Standard_LRS"
}
resource "azurerm_storage_container" "an_os_images" {
  name = "an-os-images"
  resource_group_name = "${azurerm_resource_group.an_prod.name}"
  storage_account_name = "${azurerm_storage_account.an_storage_std.name}"
  container_access_type = "private"
}

Debug Output

Error refreshing state: 1 error(s) occurred:
* azurerm_storage_container.an_os_images: Error retrieving keys for storage account "anstoragestandard": autorest:DoErrorUnlessStatusCode 404 POST https://management.azure.com/subscriptions/3581893b-e014-4aab-820e-d84c7d38a77c/resourceGroups/AN_Prod/providers/Microsoft.Storage/storageAccounts/anstoragestandard/listKeys?api-version=2015-06-15 failed with 404 Not Found

Expected Behavior

If a storage account has been removed, why try to get state info for the files that were in the account?
I think it would be safe to mark them removed as well and update the state file.

Actual Behavior

Terraform fails here and does not update the state file.

Steps to Reproduce

  1. Provision a storage account and a storage container inside the account.
  2. Delete the storage account from the Azure portal
  3. Run 'terraform refresh'

References

This may be appropriate to track along with issue #6526.

@stack72
Copy link
Contributor

stack72 commented May 18, 2016

Hi @cchildress

Thanks for reporting this issue - sorry it is happening. The error message that you are seeing is talking about a resource that isn't in the configuration sample you have provided. Can you check that you have the correct configuration in place (or should I assume that the config you have provided is a small sample of what you are using)?

Thanks

Paul

@cchildress
Copy link
Contributor Author

Hey @stack72
Sorry about that, I copy and pasted the wrong storage config; I've updated the initial post with the right config.

What I suspect is happening is the refresh goes and tries to query state on azurerm_storage_container.an_os_images, but gets a 404 error because it relies on anstoragestandard from azurerm_storage_account.an_storage_std which was deleted in the Azure portal manually.
If it evaluated the storage account before the container it could realize that the resource is gone.

@ghost
Copy link

ghost commented Apr 25, 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 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants