terraform-provider-azurerm: Cannot delete a non empty file share storage
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and AzureRM Provider) Version
Terraform v0.12.28
provider.azurerm v2.18.0
provider.null v2.1.2
Affected Resource(s)
azurerm_storage_share_directory azurerm_storage_share
azurerm_XXXXX
Terraform Configuration Files
# #storage account and file share
resource "azurerm_storage_account" "test" {
name = local.storage_name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = var.account_tier
account_replication_type = var.account_replication_type
}
resource "azurerm_storage_share" "test" {
name = azurerm_storage_account.test.name
storage_account_name = azurerm_storage_account.test.name
quota = var.storage_fileshare_quota
}
Debug Output
Error: Error deleting Storage Share “test” (File Share “testfilestracc” / Account “testfilestracc” / Resource Group “testfilestraccqa”): directories.Client#Delete: Failure sending request: StatusCode=409 – Original Error: autorest/azure: Service returned an error. Status=<nil> Code=“DirectoryNotEmpty” Message=“The specified directory is not empty.\nRequestId:b6fa48eb-a01a-0055-4059-5f4f8e000000\nTime:2020-07-21T12:23:36.3720820Z”
Panic Output
Expected Behavior
should have deleted the file share
Actual Behavior
throws an error saying the directory is not empty, isn’t possible to delete a non-empty directory? Any workaround or solution would be appreciated! i used terraform to create storage account , fileshare and the directories as well.
Steps to Reproduce
terraform apply
Important Factoids
NO
References
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 12
- Comments: 16 (5 by maintainers)
Agreed, it would be great if there was a
allow_force_deleteboolean argument on theazurerm_storage_share_directoryresource.My use case: I need to spin up a Container Instance that mounts a file share containing some seed data. The container, once running, will add and modify files in that file share. Once it does that, I’m no longer able to tear down my environment with terraform because of this issue.
@razgrim is correct, running a destroy provisioner with a local_file sometimes succeeds and sometimes fails depending on the order of execution, if the file gets created before the destroy operation takes place it succeeds and fails otherwise (No such file or directory) and there is no way to ensure that the file gets created first using Terraform.
There is no way to configure the order of destroy/apply in Terraform because in this case [depends_on] simply does not work since the required action is to create a script before destroying a share directory, and [depends_on] controls the order of apply or destroy but not both.
To work around this, I utilized Terragrunt dependencies, since I use Terragrunt in my project. That is, modularization. One module will only create a script and another will manage the share directory (and other resources). The module that manages the share directory has a dependency on the first. This ensures that the script is always there for the local_exec during the destroy operation, and will be ignored during apply.
This solution works locally and also in GitLab/Github/etc pipelines since the script will get created each pipeline run, and discarded after the pipeline finishes. And only takes seconds to create.