I’ve deployed a new file share on a storage account I have in Azure and ever since I did that I am no longer able to perform terraform plan and instead getting the following error:
azurerm_storage_account_customer_managed_key.this[0]: Refreshing state... [id=/subscriptions/**********/resourceGroups/myrg/providers/Microsoft.Storage/storageAccounts/myaccount]
╷
│ Error: shares.Client#GetProperties: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded
│
│ with azurerm_storage_share.this["share1"],
│ on main.tf line 155, in resource "azurerm_storage_share" "this":
│ 155: resource "azurerm_storage_share" "this" {
│
╵
Destroy False detailedExitCode: 1
Error detected by Terraform
##[error]Script failed with exit code: 1
I’ve tried setting the storage account networking to public (Enable from all networks) and still the same.
I’ve tried different Terraform versions (1.2.6, 1.0.4, 1.2.7, 1.2.0) – same outcome.
I’ve looked it up online and came up with these two tickets that seem similar but have yet to receive an answer (though they are not from Stack Overflow):
https://github.com/hashicorp/terraform-provider-azurerm/issues/17851
https://github.com/hashicorp/terraform-provider-azurerm/issues/2977
I have run out of leads to investigate at the moment , and I’d appreciate if someone might have new ideas as to what’s causing the issue.
Let me know if I can share more information.
2
Answers
In my case i got the similar kind of error when i have not cleared the state
file (TF) in which other resource is present which is not present in
azure portal.(As I have manually deleted it in the portal but still
present in the terraform state file.)
I erased the resources which are not present in the azure portal and then tried to execute the same.
Or If some sources are present in azure and not in terraform state file.In this case
make sure to import the resources using
terraform import <terraformid> <resourceId>
something like this azurerm_resource_group | Resources | registry.terraform.io or this SO ref by checking the mismatch in resources in azure portal and terraform.tfstate file.portal, then try and execute.
I tried in my environment and able to execute
terraform plan
andterraform apply
Result:
References:
Terraform Registry
So Terraform uses private urls for management of the file share. In our cases DNS resolving of these endpoints was not working correctly. You can get the URL for the private endpoint using the command
terraform console
and then investigate the resource>azurerm_storage_share.file_share
. It will show the private URL. Subsequently, use thenslookup or dig
command to determine if you can resolve the URL to an IP address. If you are not able to resolve the URL there are several options. For example you could add them to your/etc/hosts file
. This solved it our case. Another option is to add the private link to a private DNS zone and forward you local DNS to this private zone.