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.54k stars 4.61k forks source link

Using data source azurerm_function_app_host_keys in fresh workspace causes Terraform crash #8491

Closed robinkb closed 4 years ago

robinkb commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.13.2

Affected Resource(s)

Terraform Configuration Files

Below are what I think are the relevant resources. It may also be important to note that the output of the data source is consumed in another resource. But, seeing as the panic log directly mentions the azurerm_function_app_host_keys data source, I don't think the other config is relevant.

resource "azurerm_function_app" "saleshub_backend" {
  name                = "func-${var.customer}-${var.env}-saleshub-backend"
  location            = azurerm_resource_group.saleshub.location
  resource_group_name = azurerm_resource_group.saleshub.name

  app_service_plan_id = azurerm_app_service_plan.saleshub_backend.id

  storage_account_name       = azurerm_storage_account.saleshub_backend.name
  storage_account_access_key = azurerm_storage_account.saleshub_backend.primary_access_key

  version = "~3"

  https_only = true

  app_settings = {
    # Required settings for Function Apps to work.
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.saleshub_backend.instrumentation_key
    FUNCTIONS_WORKER_RUNTIME       = "node"
    WEBSITE_NODE_DEFAULT_VERSION   = "~12"
    # TODO: Check if there are alternatives for this.
    # If this setting is on but the function app is empty, we cannot get keys from the runtime.
    # See: https://github.com/Azure/azure-functions-host/issues/5722#issuecomment-619596843
    WEBSITE_RUN_FROM_PACKAGE        = "1"
    WEBSITE_ENABLE_SYNC_UPDATE_SITE = "true"
    # Something else is setting this, and not setting it here triggers changes to remove it.
    SCM_DO_BUILD_DURING_DEPLOYMENT = "false"

    # # Custom app warm-up settings.
    # WEBSITE_SWAP_WARMUP_PING_PATH     = "/api/health-check"
    # WEBSITE_SWAP_WARMUP_PING_STATUSES = "200"
    # # Azure recommends always setting this except for WCF apps.
    # WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG = "1"

    # App Settings
    COSMOSDB_DATABASE           = lookup(azurerm_template_deployment.cosmos_db_account.outputs, "database")
    COSMOSDB_ENDPOINT           = lookup(azurerm_template_deployment.cosmos_db_account.outputs, "endpoint")
    COSMOSDB_KEY                = lookup(azurerm_template_deployment.cosmos_db_account.outputs, "primaryKey")
    FASTLY_SERVICE_ID           = fastly_service_v1.saleshub.id
    FASTLY_API_KEY              = data.azurerm_key_vault_secret.fastly_saleshub_api_key.value
    SERVERLESS_EXPRESS_PLATFORM = "azure"
  }

  site_config {
    ftps_state = "FtpsOnly"
  }
}

data "azurerm_function_app_host_keys" "saleshub_backend" {
  name                = azurerm_function_app.saleshub_backend.name
  resource_group_name = azurerm_function_app.saleshub_backend.resource_group_name
}

Debug Output

I haven't run Terraform again to get the complete debug output because I got a crash log, but I can run it again if needed.

Panic Output

Panic output to the console:

panic: runtime error: invalid memory address or nil pointer dereference
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x3cf66cf]
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: 
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: goroutine 185 [running]:
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web.dataSourceArmFunctionAppHostKeysRead(0xc0012e0af0, 0x406e680, 0xc0002bd340, 0x0, 0x0)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/data_source_function_app_host_keys.go:61 +0x4af
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc000e07440, 0xc0011972e0, 0x406e680, 0xc0002bd340, 0xc000902990, 0x1, 0x0)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:403 +0x88
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc00088ca80, 0xc001509ad0, 0xc0011972e0, 0xc0011972e0, 0x0, 0x0)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:451 +0x8f
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc00068cc60, 0x4f2a900, 0xc0013c30e0, 0xc001089d80, 0xc00068cc60, 0xc0013c30e0, 0xc00084bb78)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:1036 +0x45d
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0x4475800, 0xc00068cc60, 0x4f2a900, 0xc0013c30e0, 0xc00079f7a0, 0x0, 0x4f2a900, 0xc0013c30e0, 0xc0005d0210, 0xab)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3341 +0x217
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: google.golang.org/grpc.(*Server).processUnaryRPC(0xc000802900, 0x4f68580, 0xc000642600, 0xc0008f2400, 0xc000115170, 0x7de8e50, 0x0, 0x0, 0x0)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1024 +0x501
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: google.golang.org/grpc.(*Server).handleStream(0xc000802900, 0x4f68580, 0xc000642600, 0xc0008f2400, 0x0)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1313 +0xd3d
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000aba290, 0xc000802900, 0x4f68580, 0xc000642600, 0xc0008f2400)
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:722 +0xa1
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-09-16T17:28:13.173+0200 [DEBUG] plugin.terraform-provider-azurerm_v2.27.0_x5:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:720 +0xa1
2020/09/16 17:28:13 [ERROR] eval: *terraform.evalReadDataPlan, err: rpc error: code = Unavailable desc = transport is closing
2020-09-16T17:28:13.177+0200 [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.27.0/linux_amd64/terraform-provider-azurerm_v2.27.0_x5 pid=47846 error="exit status 2"
2020/09/16 17:28:13 [ERROR] eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2020/09/16 17:28:13 [TRACE] [walkPlan] Exiting eval tree: data.azurerm_function_app_host_keys.saleshub_backend
2020/09/16 17:28:13 [TRACE] vertex "data.azurerm_function_app_host_keys.saleshub_backend": visit complete
2020/09/16 17:28:13 [TRACE] vertex "data.azurerm_function_app_host_keys.saleshub_backend": dynamic subgraph encountered errors
2020/09/16 17:28:13 [TRACE] vertex "data.azurerm_function_app_host_keys.saleshub_backend": visit complete
2020/09/16 17:28:13 [TRACE] vertex "data.azurerm_function_app_host_keys.saleshub_backend (expand)": dynamic subgraph encountered errors
2020/09/16 17:28:13 [TRACE] vertex "data.azurerm_function_app_host_keys.saleshub_backend (expand)": visit complete
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "azurerm_api_management_named_value.saleshub_backend_key (expand)" errored, so skipping
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "azurerm_api_management_backend.saleshub (expand)" errored, so skipping
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "azurerm_api_management_api_operation_policy.saleshub (expand)" errored, so skipping
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/hashicorp/azurerm\"] (close)" errored, so skipping
2020/09/16 17:28:13 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/09/16 17:28:13 [INFO] backend/local: plan operation completed
2020-09-16T17:28:13.255+0200 [DEBUG] plugin: plugin exited

I would rather not link a full crash log, because that contains sensitive information. If the above output contains enough information, I can spend the time scrubbing the crash log, but I would much rather not do that.

Expected Behavior

Terraform produces a valid plan to setup a new environment.

Actual Behavior

Terraform crashes during the planning phase.

Steps to Reproduce

  1. terraform workspace new clean-workspace
  2. terraform plan

Important Factoids

The crash does not occur when using the data source in a workspace where the Azure Function App that it references already exists.

References

mbfrahry commented 4 years ago

Hey @robinkb, thanks for opening this issue. We had the same one open under #8428 and got it fixed in #8430. That fix should go out in the next release! Thanks for your patience here

robinkb commented 4 years ago

Whoops, I think I missed that issue because it was already marked as closed, even though the issue is still present in the current release. Thanks for the quick response and fixing the problem!

tombuildsstuff commented 4 years ago

Fixed via #8430

ghost commented 4 years ago

This has been released in version 2.28.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.28.0"
}
# ... other configuration ...
ghost commented 3 years 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!