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

data azurerm_linux_function_app - Plugin did not respond #18302

Open Zaduvalo opened 2 years ago

Zaduvalo commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.8

AzureRM Provider Version

3.21.1

Affected Resource(s)/Data Source(s)

Data Source: azurerm_linux_function_app

Terraform Configuration Files

data "azurerm_linux_function_app" "test" {
  name                = var.function_app_name
  resource_group_name = var.function_app_rg_name
}

Debug Output/Panic Output

│ Error: Plugin did not respond
│
│   with module.test.data.azurerm_linux_function_app.test,
│   on ..\..\modules\test\main.tf line 25, in data "azurerm_linux_function_app" "test":
│   25: data "azurerm_linux_function_app" "test" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.

Expected Behaviour

Should return azurerm_linux_function_app data object. https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/linux_function_app

Actual Behaviour

Crash.

Steps to Reproduce

  1. Create azurerm_linux_function_app in environment "A"
  2. Try to read azurerm_linux_function_app from environment "B"

PS. The current workaround is to use old - data "azurerm_function_app".

Important Factoids

No response

References

No response

Zaduvalo commented 2 years ago

BUG Update. same error using: terraform 1.2.9 azurerm provider 3.22.0

Debug Output/Panic Output

│ Error: Plugin did not respond │ │ with module.test.data.azurerm_linux_function_app.test, │ on ....\modules\test\main.tf line 25, in data "azurerm_linux_function_app" "test": │ 25: data "azurerm_linux_function_app" "test" { │ │ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.

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

panic: runtime error: index out of range [0] with length 0

goroutine 145 [running]: github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice.(LinuxFunctionAppDataSourceModel).unpackLinuxFunctionAppSettings(0xc0013d9200, {{0xc002eba090}, 0xc00320dfb0, 0xc003213360, 0xc003213370, 0x0, 0xc003213380}, {0xc0013d0000, {0x7426d70, 0xc0004e6000}, ...}) github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/linux_function_app_data_source.go:400 +0xcdd github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice.LinuxFunctionAppDataSource.Read.func1({0x7425790, 0xc001a78d80}, {0xc0013d0000, {0x7426d70, 0xc0004e6000}, 0xc001a09c80, 0x0, {0x7428778, 0xb552ea0}}) github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/linux_function_app_data_source.go:339 +0x1dbb github.com/hashicorp/terraform-provider-azurerm/internal/sdk.(DataSourceWrapper).DataSource.func2({0x7425790, 0xc001a78d80}, 0x1176592e000?, {0x62d1740?, 0xc0013d0000?}) github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_data_source.go:48 +0x158 github.com/hashicorp/terraform-provider-azurerm/internal/sdk.diagnosticsWrapper.func1({0x7425790, 0xc001a78d80}, 0x24856360eb8?, {0x62d1740, 0xc0013d0000}) github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:185 +0xbe github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).read(0xc0004f09a0, {0x74257c8, 0xc000acc7e0}, 0xd?, {0x62d1740, 0xc0013d0000}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/schema/resource.go:724 +0x12e github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).ReadDataApply(0xc0004f09a0, {0x74257c8, 0xc000acc7e0}, 0xc001a09b80, {0x62d1740, 0xc0013d0000}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/schema/resource.go:943 +0x145 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ReadDataSource(0xc0015ba3c0, {0x74257c8?, 0xc000acc720?}, 0xc00117aa60) github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/schema/grpc_provider.go:1179 +0x38f github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ReadDataSource(0xc0009c9f40, {0x74257c8?, 0xc001759d10?}, 0xc0000b1ea0) github.com/hashicorp/terraform-plugin-go@v0.10.0/tfprotov5/tf5server/server.go:658 +0x3ef github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0x68c0680?, 0xc0009c9f40}, {0x74257c8, 0xc001759d10}, 0xc001a789c0, 0x0) github.com/hashicorp/terraform-plugin-go@v0.10.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:421 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0xc00032aa80, {0x74370d8, 0xc000dfc000}, 0xc001a4d680, 0xc000d6ab40, 0xb4ecff0, 0x0) google.golang.org/grpc@v1.47.0/server.go:1283 +0xcfd google.golang.org/grpc.(Server).handleStream(0xc00032aa80, {0x74370d8, 0xc000dfc000}, 0xc001a4d680, 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.22.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.

Zaduvalo commented 2 years ago

Same problem using azurerm 3.23.0

Zaduvalo commented 2 years ago

I found a solution to make data azurerm_linux_function_app work in terraform plan. But it still crashes on apply. Test module dependant on another module output variable. Adding "depends_on" to the Test module resolves this issue.

xiaxyi commented 1 year ago

Thanks @Zaduvalo for raising this issue, can you let me know how did you created the linux function app? if the app was created by using Terraform, can you share the config with me?

Zaduvalo commented 1 year ago

Hi @xiaxyi Originally function app was created by terraform using provider version 2.58:

resource "azurerm_function_app" "docker" {
  name                = "fn-test-docker"
  resource_group_name = var.resource_group_name
  location            = var.location
  os_type             = "linux"
  version             = "~4"

  storage_account_name = azurerm_storage_account.function.name
  storage_account_access_key = azurerm_storage_account.function.primary_access_key
  app_service_plan_id        = azurerm_service_plan.docker.id

  app_settings = {
    "APPLICATIONINSIGHTS_CONNECTION_STRING" = var.app_ins_connection
    "FUNCTIONS_WORKER_RUNTIME" = "dotnet"
    "DOCKER_REGISTRY_SERVER_URL"      = var.azurerm_container_registry.login_server
    "DOCKER_REGISTRY_SERVER_USERNAME" = var.azurerm_container_registry.admin_username
    "DOCKER_REGISTRY_SERVER_PASSWORD" = var.azurerm_container_registry.admin_password
    "DOCKER_ENABLE_CI" = true
    "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = azurerm_storage_account.function.primary_connection_string
    "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = false 
    "WEBSITE_VNET_ROUTE_ALL" = 1
  }

  identity {
    type = "SystemAssigned"
  }

  site_config {
    dotnet_framework_version = "v6.0"
    linux_fx_version = "DOCKER|${var.azurerm_container_registry.login_server}/${var.container_image}"

    dynamic "ip_restriction" {
      for_each = toset(local.network_rules)
      content {
     ...
      }
    }
    pre_warmed_instance_count  = 1 
  }
  tags = merge(local.common_tags)
  lifecycle { ignore_changes = [tags,] }
}

Later "azurerm_function_app" was converted to "azurerm_linux_function_app" using 3.23.0 provider:

resource "azurerm_linux_function_app" "docker" {
  name                = "fn-test-docker"
  resource_group_name = var.resource_group_name
  location            = var.location

  storage_account_name = azurerm_storage_account.function.name
  storage_account_access_key = azurerm_storage_account.function.primary_access_key
  service_plan_id        = azurerm_service_plan.docker.id
  virtual_network_subnet_id = var.function_subnet_id

  app_settings = {
    "FUNCTIONS_WORKER_RUNTIME" = "dotnet"
    "DOCKER_ENABLE_CI" = true
    "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = azurerm_storage_account.function.primary_connection_string
    "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = false
    "WEBSITE_VNET_ROUTE_ALL" = 1
  }

  identity {
    type = "SystemAssigned"
  }

  site_config {
    application_insights_key = var.log_wks_key
    application_insights_connection_string  = var.app_ins_connection
    application_stack {
      docker {
        registry_url = var.azurerm_container_registry.login_server
        image_name = ""
        image_tag = ""
        registry_username = var.azurerm_container_registry.admin_username
        registry_password = var.azurerm_container_registry.admin_password
      }
    }

    dynamic "ip_restriction" {
      for_each = toset(local.network_rules)
      content {
        ...
      }
    }
    pre_warmed_instance_count  = 1
  }
  tags = merge(local.common_tags)
  lifecycle { ignore_changes = [tags,] }
}