skip to Main Content

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


  1. 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.)


    enter image description here

    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.

    For example Resource Groups can be imported as:

    terraform import azurerm_resource_group.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example
    
    • After making sure the state file matches the resources present in
      portal, then try and execute.

    I tried in my environment and able to execute terraform plan and terraform apply

    provider "azurerm" {
    
      features {}
    
    }
    resource "azurerm_resource_group" "example" {
      name     = "xxxxxxx"  
      location = "westus2"
    }
    
    resource "azurerm_storage_account" "test" {
      name                     = "acctestacc1234"
      resource_group_name      = azurerm_resource_group.example.name
      location                 = "westus2"
      account_tier             = "Standard"
      account_replication_type = "LRS"
    }
    resource "azurerm_storage_share" "test" {
      name                 = "testkaaccount"
      storage_account_name = azurerm_storage_account.test.name
      quota                = 5
      access_tier          = "TransactionOptimized"
    }
    

    enter image description here

    Result:

    enter image description here

    Also please check with the location if it correctly given refering to
    resource group location and if it is created in VM ,make sure the vm
    and the resources created are in the same location .

    References:

    1. azurerm_storage_share_file | Resources | hashicorp/azurerm |
      Terraform Registry
    2. Terraform Azure Configure VM Backup Policy Fails – Stack Overflow
    Login or Signup to reply.
  2. 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 the nslookup 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search