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.52k stars 4.6k forks source link

The terraform-provider-azurerm_v3.91.0_x5.exe plugin crashed #24894

Open 7timus opened 7 months ago

7timus commented 7 months ago

Is there an existing issue for this?

Community Note

Terraform Version

Terraform v1.6.6 on windows_amd64

AzureRM Provider Version

3.91.0

Affected Resource(s)/Data Source(s)

azurerm_windows_web_app_slot

Terraform Configuration Files

resource "azurerm_windows_web_app_slot" "api" {
  name                    = "staging"
  app_service_id          = azurerm_windows_web_app.api.id
  https_only              = true
  client_affinity_enabled = true
  tags                    = local.az_common_tags

  site_config {
    websockets_enabled    = false

    application_stack {
      dotnet_version ="v6.0"
    }

    dynamic "ip_restriction" {
      for_each = var.ip_restriction_rules
      content {
              action = ip_restriction.value.action
              name = ip_restriction.value.name
              priority = ip_restriction.value.priority
              service_tag = ip_restriction.value.service_tag
              ip_address = ip_restriction.value.ip_address
              virtual_network_subnet_id=ip_restriction.value.virtual_network_subnet_id
              }
      }
  }

  app_settings = local.web_app_app_settings
}

resource "azurerm_application_insights_web_test" "api" {
  name                    = var.web_availability_test_name
  location                = azurerm_application_insights.api.location
  resource_group_name     = azurerm_resource_group.api.name
  application_insights_id = azurerm_application_insights.api.id
  kind                    = "ping"
  frequency               = 300
  timeout                 = 120
  enabled                 = true
  retry_enabled           = true
  geo_locations           = ["emea-fr-pra-edge", "emea-se-sto-edge","emea-nl-ams-azr","latam-br-gru-edge","apac-hk-hkn-azr"]
  tags = local.az_common_tags
  configuration = <<XML
<WebTest Name="WebTest1" Id="ABD48585-0831-40CB-9069-682EA6BB3583" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
  <Items>
    <Request Method="GET" Guid="a5f10126-e4cd-570d-961c-cea43999a200" Version="1.1" Url="https://${azurerm_windows_web_app.api.default_hostname}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="200" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
  </Items>
</WebTest>
XML
}
resource "azurerm_key_vault" "api" {
  name                            = var.kv_name
  location                        = azurerm_resource_group.api.location
  resource_group_name             = azurerm_resource_group.api.name
  enabled_for_disk_encryption     = true
  enabled_for_deployment          = true
  enabled_for_template_deployment = true
  purge_protection_enabled        = true
  tenant_id                       = data.azurerm_client_config.api.tenant_id
  soft_delete_retention_days      = var.kv_soft_delete_retention_days
  sku_name                        = "standard"
  tags = local.az_common_tags

  depends_on   = [
      azurerm_windows_web_app.api
    ]

  access_policy {
    object_id  =  var.access_rights_group
    tenant_id  =  data.azurerm_client_config.api.tenant_id

    secret_permissions = [
      "Get",
      "Set",
      "List",
      "Delete",
      "Recover",
    ]

    certificate_permissions = [
      "Get",
      "List",
    ]
  }

  access_policy {
    object_id  =  azurerm_windows_web_app.api.identity.0.principal_id
    tenant_id  =  data.azurerm_client_config.api.tenant_id

    secret_permissions = [
      "Get",
      "List",
    ]

    certificate_permissions = [
      "Get",
      "List",
    ]
  }

  access_policy {
    tenant_id = data.azurerm_client_config.api.tenant_id
    object_id = data.azurerm_client_config.api.object_id

    key_permissions = [
      "Get",
      "List",
      "Import",
    ]

    secret_permissions = [
      "Get",
      "List",
      "Set",
      "Delete",
      "Purge",
      "Recover",
      "Restore"
    ]
  }
}

resource "azurerm_monitor_metric_alert" "alert_dependency_spike_last_15_minutes" {
  name                = "XXX API ${var.web_app_environment} failed dependencies spike in last 15 minutes"
  resource_group_name = azurerm_resource_group.api.name
  scopes              = [azurerm_application_insights.api.id]
  description         = "There has been a spike of failed dependencies in short period."

  dynamic_criteria {
    metric_namespace = "microsoft.insights/components"
    metric_name      = "dependencies/failed"
    aggregation      = "Count"
    operator         = "GreaterOrLessThan"
    alert_sensitivity = "Medium"
    evaluation_total_count = 4
    evaluation_failure_count = 4
  }

  frequency=  "PT5M"
  window_size = "PT15M"
  severity=1

  action {
    action_group_id = data.azurerm_monitor_action_group.teamsAlertActionGroup.id
  }
   tags = local.az_common_tags
}

resource "azurerm_role_assignment" "shared_blob_table_reader_for_web_app" {
  scope                 = azurerm_storage_account.shared.id
  role_definition_name  = "Storage Table Data Reader"
  principal_id          = azurerm_windows_web_app.api.identity.0.principal_id
}

Debug Output/Panic Output

Plan: 0 to add, 20 to change, 0 to destroy.
╷
│ Error: Plugin did not respond
│
│   with azurerm_windows_web_app_slot.api,
│   on main.tf line 68, in resource "azurerm_windows_web_app_slot" "api":
│   68: resource "azurerm_windows_web_app_slot" "api" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).UpgradeResourceState call. The 
│ plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│   with azurerm_application_insights_web_test.api,
│   on main.tf line 130, in resource "azurerm_application_insights_web_test" "api":
│  130: resource "azurerm_application_insights_web_test" "api" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).UpgradeResourceState call. The 
│ plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│   with azurerm_key_vault.api,
│   on main.tf line 151, in resource "azurerm_key_vault" "api":
│  151: resource "azurerm_key_vault" "api" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin  
│ logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│   with azurerm_role_assignment.shared_blob_table_reader_for_web_app,
│   on main.tf line 690, in resource "azurerm_role_assignment" "shared_blob_table_reader_for_web_app":
│  690: resource "azurerm_role_assignment" "shared_blob_table_reader_for_web_app" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin  
│ logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│   with azurerm_monitor_metric_alert.alert_handle_count_buildup,
│   on main.tf line 762, in resource "azurerm_monitor_metric_alert" "alert_handle_count_buildup":
│  762: resource "azurerm_monitor_metric_alert" "alert_handle_count_buildup" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).UpgradeResourceState call. The 
│ plugin logs may contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.91.0_x5.exe plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 1067 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration.(*WindowsWebAppSlotV0toV1).UpgradeFunc.WindowsWebAppSlotV0toV1.UpgradeFunc.func1({0x0?, 0x0?}, 0x0?, {0x0?, 0x0?})
        github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration/windows_web_app_slot.go:1806 +0x13c
github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk.StateUpgrades.func1({0x9e230f0, 0xc001b80900}, 0x0?, {0x86186a0, 0xc0003e1b00})
        github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk/state_upgrades.go:55 +0x5e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).upgradeJSONState(0xc0005efcb0, {0x9e230f0, 0xc001b80900}, 0xd?, 0x95d4c0f?, 0x14?)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:485 +0x75
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).UpgradeResourceState(0xc0005efcb0, {0x9e230f0?, 0xc001b80810?}, 0xc005f76d40)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:361 +0x3fa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).UpgradeResourceState(0xc001ef46e0, {0x9e230f0?, 0xc001b800c0?}, 0xc0000c74a0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:757 +0x258
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_UpgradeResourceState_Handler({0x91cd820?, 0xc001ef46e0}, {0x9e230f0, 0xc001b800c0}, 0xc006668230, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:395 +0x169 
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0003f0000, {0x9e49e20, 0xc000b38000}, 0xc00236b9e0, 0xc000b2f1d0, 
0xf990ed8, 0x0)
        google.golang.org/grpc@v1.58.3/server.go:1374 +0xde7
google.golang.org/grpc.(*Server).handleStream(0xc0003f0000, {0x9e49e20, 0xc000b38000}, 0xc00236b9e0, 0x0)
        google.golang.org/grpc@v1.58.3/server.go:1751 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.58.3/server.go:986 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 68
        google.golang.org/grpc@v1.58.3/server.go:997 +0x145

Error: The terraform-provider-azurerm_v3.91.0_x5.exe plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected Behaviour

Terraform plan output in tfplan file

Actual Behaviour

Terraform azurerm plugin crashed

Steps to Reproduce

terraform plan

Important Factoids

No response

References

No response

andygreen-commify commented 7 months ago

I'm experiencing the same issue, though I'm using Terraform v1.7.3 on windows_amd64

7timus commented 7 months ago

Looks like a problem in latest azurerm version. I tried multiple versions and azurem version = "3.86.0" doesn't have this issue.

jocelynenglund commented 6 months ago

We have a similar issue with a function app. here is our stack trace. (Using v 3.92.0)

panic: interface conversion: interface {} is nil, not string

goroutine 659 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration.(*WindowsFunctionAppSlotV0toV1).UpgradeFunc.WindowsFunctionAppSlotV0toV1.UpgradeFunc.func1({0x0?, 0x0?}, 0x0?, {0x0?, 0x0?})
    github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration/windows_function_app_slot.go:1530 +0x13c
github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk.StateUpgrades.func1({0x9cd5dc0, 0xc005b26960}, 0x0?, {0x84d0460, 0xc001ce4900})
    github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk/state_upgrades.go:55 +0x5e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).upgradeJSONState(0xc000b21b00, {0x9cd5dc0, 0xc005b26960}, 0xd?, 0x949d654?, 0x14?)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:485 +0x75
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).UpgradeResourceState(0xc000b21b00, {0x9cd5dc0?, 0xc005b26870?}, 0xc0023eec80)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:361 +0x3fa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).UpgradeResourceState(0xc0008eb9a0, {0x9cd5dc0?, 0xc005a55ad0?}, 0xc0022ea5a0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:757 +0x258
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_UpgradeResourceState_Handler({0x909dea0?, 0xc0008eb9a0}, {0x9cd5dc0, 0xc005a55ad0}, 0xc00234abd0, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:395 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000460000, {0x9cfcba0, 0xc001af0340}, 0xc002400ea0, 0xc001b16ea0, 0xf6c3ed8, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1374 +0xde7
google.golang.org/grpc.(*Server).handleStream(0xc000460000, {0x9cfcba0, 0xc001af0340}, 0xc002400ea0, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1751 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.58.3/server.go:986 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 9
    google.golang.org/grpc@v1.58.3/server.go:997 +0x145

looked at the sources and they are essentially the same code that is failing.

oldId := rawState["service_plan_id"].(string)
// service_plan_id can be empty if it is not in a different Service Plan to the "parent" app

I also saw similar issue that was fixed with a null check so hopefully it will be a quick fix? :D Update: We have also tried adding the service_plan_id explicitly and still we get a failure in this line, so it might be a totally different issue?

kristiangleeson commented 6 months ago

Also experiencing this with AzureRM version 3.94.0 and terraform version 1.7.4

Stack trace from the terraform-provider-azurerm_v3.94.0_x5.exe plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 1989 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration.(*WindowsWebAppSlotV0toV1).UpgradeFunc.WindowsWebAppSlotV0toV1.UpgradeFunc.func1({0x0?, 0x0?}, 0x0?, {0x0?, 0x0?})
    github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/migration/windows_web_app_slot.go:1806 +0x13c
github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk.StateUpgrades.func1({0x94d1ee0, 0xc003feac90}, 0x0?, {0x7ca8ca0, 0xc001d2a900})
    github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk/state_upgrades.go:55 +0x5e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).upgradeJSONState(0xc000b3b110, {0x94d1ee0, 0xc003feac90}, 0xd?, 0x8c9c37f?, 0x14?)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:485 +0x75
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).UpgradeResourceState(0xc000b3b110, {0x94d1ee0?, 0xc003feab70?}, 0xc002e77540)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:361 +0x3fa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).UpgradeResourceState(0xc000f603c0, {0x94d1ee0?, 0xc003fea3c0?}, 0xc002ed2a50)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:757 +0x258
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_UpgradeResourceState_Handler({0x889aee0?, 0xc000f603c0}, {0x94d1ee0, 0xc003fea3c0}, 0xc00292d340, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:395 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002b01e0, {0x94f9060, 0xc001ad0000}, 0xc002f2c7e0, 0xc001a1dcb0, 0xeec8ed8, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1374 +0xde7
google.golang.org/grpc.(*Server).handleStream(0xc0002b01e0, {0x94f9060, 0xc001ad0000}, 0xc002f2c7e0, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1751 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.58.3/server.go:986 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 23
    google.golang.org/grpc@v1.58.3/server.go:997 +0x145

Error: The terraform-provider-azurerm_v3.94.0_x5.exe plugin crashed!

Downgrading to v3.86.0 as per @7timus recommendation allowed plan to complete without issue. Once terraform applied with v3.86.0 I then upgraded back to v3.94.0 and plan/apply worked. Assume issue is with some migration of property not being handled correctly in 3.87-3.94, but if you apply the interim 3.86.0 it has the missing piece.

DGAISmith commented 3 weeks ago

This looks to be the same slot migration problem that was fixed for the linux resource here - https://github.com/hashicorp/terraform-provider-azurerm/pull/25838

I guess the same fix is needed on the windows side of the provider?