Terraform v0.11.7
azurerm v1.12.0
# create the resource group
resource "azurerm_resource_group" "rg" {
  name     = "${var.resourceGroupName}"
  location = "${var.resourceGroupLocation}"
}
# create the app insights plan
resource "azurerm_application_insights" "ai" {
  name                = "${var.appInsightsName}"
  location            = "${azurerm_resource_group.rg.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  application_type    = "Web"
}
# create the storage account
resource "azurerm_storage_account" "strg" {
  name                     = "${var.storageAccountName}"
  location                 = "${azurerm_resource_group.rg.location}"
  resource_group_name      = "${azurerm_resource_group.rg.name}"
  account_kind             = "StorageV2"
  account_tier             = "Standard"
  account_replication_type = "LRS"
  access_tier              = "Cool"
}
# create the app service plan
resource "azurerm_app_service_plan" "asp" {
  name                = "${var.appServicePlanName}"
  location            = "${azurerm_resource_group.rg.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  kind                = "FunctionApp"
  sku {
    tier = "Dynamic"
    size = "Y1"
  }
}
# create the function app
resource "azurerm_function_app" "function" {
  name                      = "${var.functionAppName}"
  location                  = "${azurerm_resource_group.rg.location}"
  resource_group_name       = "${azurerm_resource_group.rg.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.asp.id}"
  storage_connection_string = "${azurerm_storage_account.strg.primary_connection_string}"
  app_settings {
    "AppInsights_InstrumentationKey" = "${azurerm_application_insights.ai.instrumentation_key}"
        "StatusPageContainer" = "${azurerm_storage_account.strg.primary_connection_string}"
  }
}
terraform apply should generate a create plan for the function app
When running terraform apply the following error is thrown during the refresh state step.
Error refreshing state.
azurerm_function_app.function: Error making Read request on AzureRM function App AppSettings "xxxxx": web.AppsClient#ListApplicationSettings: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error.  Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.Web/sites/xxxxx" under resource group 'xxxxxxxx' was not found."
terraform applyterraform applyIf deleting a storage account manually and running terraform apply, the create plan is generated successfully.
Seems we need to check for 404 reply here:
Similar to how it's done just a few lines above, with utils.ResponseWasNotFound(resp.Response). 
@catsby Can I take this issue up and work on it? If not assigned to someone else.
@DexterPOSH I'm not active on this project, but it's likely OK to pick up, thanks!
hi @Mark-Wilkins @DexterPOSH
Just to let you know that this has been released as a part of v1.18 of the AzureRM Provider (the full changelog is available here). You can upgrade to this by specifying the version in the provider block (as shown below) and then running terraform init -upgrade
provider "azurerm" {
  version = "=1.18.0"
}
Thanks!
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 👉 [email protected]. Thanks!