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.20.0_x5.exe plugin crashed! #18147

Closed auwi987 closed 1 year ago

auwi987 commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.8

AzureRM Provider Version

3.20

Affected Resource(s)/Data Source(s)

azurerm

Terraform Configuration Files

terraform {
  required_version = ">= 0.12" 
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.0, <= 3.20.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}

resource "azurerm_service_plan" "ApplicationServicePlanWindows" {
  name                        = var.name
  location                    = var.location
  resource_group_name         = var.resourceGroupName
  per_site_scaling_enabled    = var.perSiteScaling

  sku_name                    = var.skuName
  os_type                     = var.osType   

  tags                        = var.tags
}

resource "azurerm_service_plan" "ApplicationServicePlanLinux" {
  name                        = var.name
  location                    = var.location
  resource_group_name         = var.resourceGroupName
  per_site_scaling_enabled    = var.perSiteScaling

  sku_name                    = var.skuName
  os_type                     = var.osType    

  tags                        = var.tags  
}

resource "azurerm_application_insights" "ApplicationInsights" {
  name                  = var.name
  location              = var.location
  resource_group_name   = var.resourceGroupName
  application_type      = var.type

  lifecycle {
    prevent_destroy = true
  }

  tags = var.tags
}

resource "azurerm_container_registry" "ContainerRegistry" {
  name                      = var.name
  resource_group_name       = var.resourceGroupName
  location                  = var.location
  sku                       = var.sku
  admin_enabled             = var.adminEnable

  network_rule_set {  
    default_action          = "Deny"
    ip_rule                 = var.ipRules
  }

  tags = var.tags
}

resource "azurerm_redis_cache" "redisCache" {
  name                = var.name
  location            = var.location
  resource_group_name = var.resourceGroupName
  capacity            = var.capacity
  family              = var.tier
  sku_name            = var.sku
  enable_non_ssl_port = var.sslPortBool
  minimum_tls_version = var.tlsVersion

  tags = var.tags

}

resource "azurerm_signalr_service" "SignalR" {
  name                = var.name
  resource_group_name = var.resourceGroupName
  location            = var.location

  sku {
    name     = var.sku.name
    capacity = var.sku.capacity
  }

  cors {
    allowed_origins = var.cors
  }

   tags = var.tags
}

resource "azurerm_mssql_elasticpool" "AzureSqlElasticPool" {
  server_name         = var.sqlServerName
  name                = var.name
  resource_group_name = var.resourceGroupName
  location            = var.location
  max_size_gb         = var.maxgb     # integer value
  zone_redundant      = var.zonebool  # true or false

  sku {
    name     = var.skuName
    tier     = var.skuTier        
    capacity = var.skuCapacity    
    family   = var.skuFamily
  }

  per_database_settings {
    min_capacity = var.perDBMinCapacity
    max_capacity = var.perDBMaxCapacity
  }

  tags = var.tags
}

resource "azurerm_mssql_server" "AzureMsSqlServer" {
  name                          = var.name
  resource_group_name           = var.resourceGroupName
  location                      = var.location
  version                       = var.sqlversion
  administrator_login           = var.username
  administrator_login_password  = var.password

  azuread_administrator{
    login_username = var.aadName
    object_id      = var.aadObjectid
  }

  lifecycle {
    prevent_destroy = true
  }

  tags = var.tags
}

resource "azurerm_storage_account" "StorageAccount" {
  name                      = var.name
  resource_group_name       = var.resourceGroupName
  location                  = var.location
  account_tier              = var.tier
  account_replication_type  = var.replicationType
  account_kind              = var.kind
  min_tls_version           = var.minimumTlsVersion
  enable_https_traffic_only = var.isHttpsTrafficOnly

  tags = var.tags
}

Debug Output/Panic Output

╷
│ Warning: Deprecated Resource
│
│   with module.TranslationServiceMainAPI.azurerm_app_service.ApplicationpServiceWindows,
│   on modules\AzAppServiceWindows\main.tf line 1, in resource "azurerm_app_service" "ApplicationpServiceWindows":
│    1: resource "azurerm_app_service" "ApplicationpServiceWindows" {
│
│ The `azurerm_app_service` resource has been superseded by the `azurerm_linux_web_app` and `azurerm_windows_web_app` resources. Whilst this resource will continue to be available in the 2.x and 3.x    
│ releases it is feature-frozen for compatibility purposes, will no longer receive any updates and will be removed in a future major release of the Azure Provider.
│
│ (and one more similar warning elsewhere)
╵
╷
│ Error: Plugin did not respond
│
│   with module.TranslationServiceAppSvcPlanLinux.azurerm_service_plan.ApplicationServicePlanLinux,
│   on modules\AzAppServicePlanLinux\main.tf line 1, in resource "azurerm_service_plan" "ApplicationServicePlanLinux":
│    1: resource "azurerm_service_plan" "ApplicationServicePlanLinux" {
│
│ 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 module.TranslationServiceAppSvcPlanWindows.azurerm_service_plan.ApplicationServicePlanWindows,
│   on modules\AzAppServicePlanWindows\main.tf line 1, in resource "azurerm_service_plan" "ApplicationServicePlanWindows":
│    1: resource "azurerm_service_plan" "ApplicationServicePlanWindows" {
│
│ 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 module.TranslationServiceAppInsights.azurerm_application_insights.ApplicationInsights,
│   on modules\AzApplicationInsights\main.tf line 1, in resource "azurerm_application_insights" "ApplicationInsights":
│    1: resource "azurerm_application_insights" "ApplicationInsights" {
│
│ 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 module.TranslationserviceContainerRegistry.azurerm_container_registry.ContainerRegistry,
│   on modules\AzContainerRegistry\main.tf line 1, in resource "azurerm_container_registry" "ContainerRegistry":
│    1: resource "azurerm_container_registry" "ContainerRegistry" {
│
│ 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 module.TranslationServiceRedis.azurerm_redis_cache.redisCache,
│   on modules\AzRedisCache\main.tf line 1, in resource "azurerm_redis_cache" "redisCache":
│    1: resource "azurerm_redis_cache" "redisCache" {
│
│ 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 module.TranslationServiceSignalR.azurerm_signalr_service.SignalR,
│   on modules\AzSignalR\main.tf line 1, in resource "azurerm_signalr_service" "SignalR":
│    1: resource "azurerm_signalr_service" "SignalR" {
│
│ 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 module.TranslationServiceSQLServerElasticPool.azurerm_mssql_elasticpool.AzureSqlElasticPool,
│   on modules\AzSqlElasticPool\main.tf line 1, in resource "azurerm_mssql_elasticpool" "AzureSqlElasticPool":
│    1: resource "azurerm_mssql_elasticpool" "AzureSqlElasticPool" {
│
│ 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 module.TranslationServiceSQLServer.azurerm_mssql_server.AzureMsSqlServer,
│   on modules\AzSqlServer\main.tf line 1, in resource "azurerm_mssql_server" "AzureMsSqlServer":
│    1: resource "azurerm_mssql_server" "AzureMsSqlServer" {
│
│ 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 module.TranslationServiceStorageAcct.azurerm_storage_account.StorageAccount,
│   on modules\AzStorageAccount\main.tf line 1, in resource "azurerm_storage_account" "StorageAccount":
│    1: resource "azurerm_storage_account" "StorageAccount" {
│
│ 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.20.0_x5.exe plugin:

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

goroutine 162 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/migration.AccountV0ToV1.UpgradeFunc.func1({0x90?, 0xc0019915c0?}, 0x68a96d0?, {0x557c900?, 0xc000580400?})
        github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/migration/account.go:21 +0x18c
github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk.StateUpgrades.func1({0x6886848, 0xc000759260}, 0xc001991620?, {0x577baa0, 0xc001cb5c00})
        github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk/state_upgrades.go:52 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).upgradeJSONState(0xc0000058c0, {0x6886848, 0xc000759260}, 0xd?, 0x6134a07?, 0x14?)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/schema/grpc_provider.go:449 +0x97
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).UpgradeResourceState(0xc0000058c0, {0x6886848?, 0xc0007591a0?}, 0xc001e96260)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/schema/grpc_provider.go:325 +0x437
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).UpgradeResourceState(0xc0005426e0, {0x6886848?, 0xc000523e30?}, 0xc001dfc0a0)
        github.com/hashicorp/terraform-plugin-go@v0.10.0/tfprotov5/tf5server/server.go:716 +0x267
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_UpgradeResourceState_Handler({0x5d43680?, 0xc0005426e0}, {0x6886848, 0xc000523e30}, 0xc001982060, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.10.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:313 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000244540, {0x6897970, 0xc001618000}, 0xc00076c5a0, 0xc0015e20c0, 0xa894d40, 0x0)
        google.golang.org/grpc@v1.47.0/server.go:1283 +0xcfd
google.golang.org/grpc.(*Server).handleStream(0xc000244540, {0x6897970, 0xc001618000}, 0xc00076c5a0, 0x0)
        google.golang.org/grpc@v1.47.0/server.go:1620 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.47.0/server.go:922 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.47.0/server.go:920 +0x28a

Error: The terraform-provider-azurerm_v3.20.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

No response

Actual Behaviour

Steps to Reproduce

terraform plan

Important Factoids

No response

References

No response

auwi987 commented 2 years ago

hi any updates on this one?

lonegunmanb commented 2 years ago

Hi @auwi987 , I've dug into this issue and I believe this is a very old tfstate right?

The panic stack was on migration.AccountV0ToV1.UpgradeFunc.func1 function, which means the Terraform was trying to upgrade your storage account resource's state in tfstate file from V0 to V1. azurerm_storage_account resource is in schema version 2 now, and v1 was introduced in 2017/09/28 at this commit.

github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/migration.AccountV0ToV1.UpgradeFunc.func1({0x90?, 0xc0019915c0?}, 0x68a96d0?, {0x557c900?, 0xc000580400?})
        github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/migration/account.go:21 +0x18c

The panic stack told us the panic was triggered by line 21:

func (AccountV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
    return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
        // this should have been applied from pre-0.12 migration system; backporting just in-case
LINE21:     accountType := rawState["account_type"].(string)
        split := strings.Split(accountType, "_")
        rawState["account_tier"] = split[0]
        rawState["account_replication_type"] = split[1]
        return rawState, nil
    }
}

The panic message panic: interface conversion: interface {} is nil, not string means rawState["account_type"] is nil and cannot be converted into string. Could you please check your tfstate file to see whether there's account_type field in your storage account resource state? Since this argument in V0 is required I have no idea why we can get a nil value. The argument schema in V0:

                       "account_type": {
                Type:             schema.TypeString,
                Required:         true,
                ValidateFunc:     validateArmStorageAccountType,
                DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
            },
auwi987 commented 2 years ago

hi @lonegunmanb no account_type field image

lonegunmanb commented 2 years ago

Sorry for the late reply @auwi987 , I've checked the azurerm_storage_account git log, the account_replication_type was introduced in commit 77d13c7608975a6c1a1ab4b8c9cedddd93557dda, and the schema version has been upgraded to V1 in the same commit.

In your state file we can see account_replication_type but no account_type, but the schema_version is 0, so my guess is this state file is corrupted by unknown reason, the schema_version should be greater than 0. Would you please tell us how do you get this state file? Thanks for your patience.

lonegunmanb commented 1 year ago

Hello @auwi987 , a kindly ping, how's things going?

rcskosir commented 1 year ago

Thanks for opening this issue. Since time has passed without a response regarding how your state file came to be, I am going to mark this issue as closed. If you are able to provide more information to help us reproduce this issue we may re-open this issue or open a new issue, thanks!

github-actions[bot] commented 4 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.