From a590e9aa51ff443ff16174e8d6e5193dc3cbd648 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Thu, 11 Jun 2020 14:48:21 +0800 Subject: [PATCH] update --- .../services/web/resource_arm_function_app.go | 12 +++- .../tests/resource_arm_function_app_test.go | 61 +++++++++++++++++-- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index 6042c3c9176f..b84c63c06ea4 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -661,9 +661,15 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error dashboard, ok := appSettings["AzureWebJobsDashboard"] d.Set("enable_builtin_logging", ok && dashboard != "") - delete(appSettings, "AzureWebJobsDashboard") - delete(appSettings, "AzureWebJobsStorage") - delete(appSettings, "FUNCTIONS_EXTENSION_VERSION") + if _, ok = d.GetOk("app_settings.AzureWebJobsDashboard"); !ok { + delete(appSettings, "AzureWebJobsDashboard") + } + if _, ok = d.GetOk("app_settings.AzureWebJobsStorage"); !ok { + delete(appSettings, "AzureWebJobsStorage") + } + if _, ok = d.GetOk("app_settings.FUNCTIONS_EXTENSION_VERSION"); !ok { + delete(appSettings, "FUNCTIONS_EXTENSION_VERSION") + } // Let the user have a final say whether he wants to keep these 2 or not on // Linux consumption plans. They shouldn't be there according to a bug diff --git a/azurerm/internal/services/web/tests/resource_arm_function_app_test.go b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go index f05ba6f727d4..4b1c29d1c973 100644 --- a/azurerm/internal/services/web/tests/resource_arm_function_app_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go @@ -174,23 +174,27 @@ func TestAccAzureRMFunctionApp_appSettings(t *testing.T) { Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFunctionAppExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "0"), - resource.TestCheckResourceAttr(data.ResourceName, "site_credential.#", "1"), ), }, + data.ImportStep(), { Config: testAccAzureRMFunctionApp_appSettings(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFunctionAppExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), ), }, + data.ImportStep(), + { + Config: testAccAzureRMFunctionApp_appSettingsUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFunctionAppExists(data.ResourceName), + ), + }, + data.ImportStep("app_settings.%", "app_settings.AzureWebJobsDashboard", "app_settings.AzureWebJobsStorage"), { Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFunctionAppExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "0"), ), }, data.ImportStep(), @@ -1224,6 +1228,53 @@ resource "azurerm_function_app" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } +func testAccAzureRMFunctionApp_appSettingsUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%[3]s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_app_service_plan" "test" { + name = "acctestASP-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku { + tier = "Standard" + size = "S1" + } +} + +resource "azurerm_function_app" "test" { + name = "acctest-%[1]d-func" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + app_service_plan_id = azurerm_app_service_plan.test.id + storage_account_name = azurerm_storage_account.test.name + storage_account_access_key = azurerm_storage_account.test.primary_access_key + + app_settings = { + "APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_storage_account.test.primary_connection_string + "AzureWebJobsDashboard" = azurerm_storage_account.test.primary_connection_string + "AzureWebJobsStorage" = azurerm_storage_account.test.primary_connection_string + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + func testAccAzureRMFunctionApp_alwaysOn(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" {