hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.65k forks source link

Error: creating App Service. Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil> #25961

Open glenthomas opened 6 months ago

glenthomas commented 6 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.8.3

AzureRM Provider Version

2.76.0

Affected Resource(s)/Data Source(s)

azurerm_app_service

Terraform Configuration Files

# module.node_app.azurerm_app_service.main will be created
  + resource "azurerm_app_service" "main" {
      + app_service_plan_id               = "***"
      + app_settings                      = (sensitive value)
      + client_affinity_enabled           = false
      + client_cert_enabled               = false
      + custom_domain_verification_id     = (known after apply)
      + default_site_hostname             = (known after apply)
      + enabled                           = true
      + https_only                        = true
      + id                                = (known after apply)
      + location                          = "northeurope"
      + name                              = "17660-sketba-test-msn"
      + outbound_ip_address_list          = (known after apply)
      + outbound_ip_addresses             = (known after apply)
      + possible_outbound_ip_address_list = (known after apply)
      + possible_outbound_ip_addresses    = (known after apply)
      + resource_group_name               = "17660-sketba-test-msn-v1-eun"
      + site_credential                   = (known after apply)

      + auth_settings {
          + allowed_external_redirect_urls = []
          + default_provider               = "AzureActiveDirectory"
          + enabled                        = false
          + issuer                         = (known after apply)
          + token_refresh_extension_hours  = 72
          + token_store_enabled            = false
          + unauthenticated_client_action  = "RedirectToLoginPage"
        }

      + identity {
          + principal_id = (known after apply)
          + tenant_id    = (known after apply)
          + type         = "SystemAssigned"
        }

      + site_config {
          + acr_use_managed_identity_credentials = false
          + always_on                            = true
          + dotnet_framework_version             = "v4.0"
          + ftps_state                           = "Disabled"
          + http2_enabled                        = true
          + ip_restriction                       = []
          + linux_fx_version                     = "NODE|18-lts"
          + local_mysql_enabled                  = (known after apply)
          + managed_pipeline_mode                = (known after apply)
          + min_tls_version                      = "1.2"
          + number_of_workers                    = (known after apply)
          + remote_debugging_enabled             = false
          + remote_debugging_version             = (known after apply)
          + scm_ip_restriction                   = (known after apply)
          + scm_type                             = (known after apply)
          + scm_use_main_ip_restriction          = false
          + vnet_route_all_enabled               = false
          + websockets_enabled                   = (known after apply)
          + windows_fx_version                   = (known after apply)

          + cors {
              + allowed_origins     = [
                  + "mywebsite.org",
                ]
              + support_credentials = false
            }
        }
    }

Debug Output/Panic Output

azurerm_resource_group.this: Creating...
azurerm_resource_group.this: Creation complete after 1s [id=/subscriptions/***/resourceGroups/17660-sketba-test-msn-eun]
module.node_app.data.azurerm_client_config.main: Reading...
module.node_app.data.azurerm_client_config.main: Read complete after 1s [id=2024-05-14 08:40:21.990201747 +0000 UTC]
module.node_app.azurerm_app_service.main: Creating...
module.node_app.azurerm_app_service.main: Still creating... [10s elapsed]

Error: creating App Service "17660-sketba-test-msn" (Resource Group "17660-sketba-test-msn-eun"): web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

  with module.node_app.azurerm_app_service.main,
  on /tmp/terraform-data-dir/modules/node_app/main.tf line 141, in resource "azurerm_app_service" "main":
 141: resource "azurerm_app_service" "main" {

Expected Behaviour

Deployment completes successfully. App service is created.

Actual Behaviour

I see an error in the Azure activity log for the subcription

Error code: Conflict
Message:
Cannot modify this site because another operation is in progress.
Details: Id: 2520e37a-5a12-4dcb-9b80-29e87f96da73,
OperationName: UpdateServerFarm,
CreatedTime: 5/14/2024 8:40:24 AM,
WebSystemName: WebSites,
SubscriptionName: ec666399-4bcb-8715-070d47a56fe6-49bb,
WebspaceName: D-ASP-f945f6cd-eun-NorthEuropewebspace-Linux,
SiteName: ,
SlotName: ,
ServerFarmName: D-ASP-f945f6cd,
GeoOperationId: 79492a59-cee5-4ede-9f2f-366d853f3c35

Steps to Reproduce

  1. terraform apply

Important Factoids

No response

References

No response

Chambras commented 6 months ago

Hi @glenthomas just curious, do you get the same error when trying with the latest azurerm provider 3.103.1?

glenthomas commented 6 months ago

Hi @glenthomas just curious, do you get the same error when trying with the latest azurerm provider 3.103.1?

Hello @Chambras, it will take me a while to test it as I have am using a large repository of shared code and updating to the latest provider will take some time. It is also not a consistent issue. It looks like the failure was likely due to the app service plan being in a locked state by another operation in progress and the azurerm provider not applying sufficient retries to handle the scenario.

rcskosir commented 6 months ago

In order to get a more useful error response set the environment variable TF_LOGto TRACE, that will hopefully help surface what is actually causing an error.

cloud-az commented 1 week ago

I am encountering the same issue with the creation of a new standard LogicApp (WS1).

resource "azurerm_service_plan" "logic_app_plan" {
  name                = "name"
  location            = var.location
  resource_group_name = var.resource_group_name
  os_type             = "Windows"
  zone_balancing_enabled = false
  sku_name               = var.logic_app_sku.size
}

resource "azurerm_logic_app_standard" "logic_app" {
  name                       = "xxx"
  location                   = var.location
  resource_group_name        = var.resource_group_name
  app_service_plan_id        = azurerm_service_plan.logic_app_plan.id
  storage_account_name       = var.storage_account_name
  storage_account_access_key = var.storage_account_access_key
  virtual_network_subnet_id  = var.vnet_integration_subnet_id
  https_only                 = true

  identity {
    type = "SystemAssigned"
  }
  site_config {
    public_network_access_enabled    = false
    app_scale_limit                  = 20
    vnet_route_all_enabled           = true
    runtime_scale_monitoring_enabled = true
  }

  app_settings = {
    "WEBSITE_VNET_ROUTE_ALL" = "1",
    "vnetContentShareEnabled" = "true",
    "WEBSITE_CONTENTSHARE"    = var.content_share_name
  }
}

resource "azurerm_app_service_virtual_network_swift_connection" "logic_app_vnet_integration" {
  app_service_id = azurerm_logic_app_standard.logic_app.id
  subnet_id      = var.vnet_integration_subnet_id
}

resource "azurerm_private_endpoint" "logic_app_private_endpoint" {
  name                = "xxxxx"
  location            = var.location
  resource_group_name = var.resource_group_name
  subnet_id           = var.pep_subnet_id

  private_service_connection {
    name                           = "xxxxxxxx"
    private_connection_resource_id = azurerm_logic_app_standard.logic_app.id
    subresource_names              = ["sites"]
    is_manual_connection           = false
  }
}

Terraform version: 1.9.8

terraform {
  required_version = ">= 1.0.0"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.8.0"
    }
  }
} 

Any update on this? @rcskosir