From d1b838ccfb872b70abce45cfd4e4f095bec9338c Mon Sep 17 00:00:00 2001 From: Mark Rzasa Date: Thu, 29 Feb 2024 20:49:04 -0500 Subject: [PATCH] fix for issue 13568 - event_grid_extension_config_key is null --- .../web/function_app_host_keys_data_source.go | 16 +++- ...function_app_host_keys_data_source_test.go | 84 ++++++++++++++++++ .../services/web/testdata/test_trigger.zip | Bin 0 -> 1059 bytes 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 internal/services/web/testdata/test_trigger.zip diff --git a/internal/services/web/function_app_host_keys_data_source.go b/internal/services/web/function_app_host_keys_data_source.go index b54949fb3e2c..3498387b65d9 100644 --- a/internal/services/web/function_app_host_keys_data_source.go +++ b/internal/services/web/function_app_host_keys_data_source.go @@ -49,6 +49,12 @@ func dataSourceFunctionAppHostKeys() *pluginsdk.Resource { Sensitive: true, }, + "event_grid_extension_key": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + "signalr_extension_key": { Type: pluginsdk.TypeString, Computed: true, @@ -112,9 +118,15 @@ func dataSourceFunctionAppHostKeysRead(d *pluginsdk.ResourceData, meta interface } d.Set("default_function_key", defaultFunctionKey) + // The name of the EventGrid System Key has changed from version 1.x to version 2.x: + // https://learn.microsoft.com/en-us/azure/azure-functions/event-grid-how-tos?tabs=v2%2Cportal#system-key + // This block accommodates both keys. eventGridExtensionConfigKey := "" - if v, ok := res.SystemKeys["eventgridextensionconfig_extension"]; ok { - eventGridExtensionConfigKey = *v + for _, key := range []string{"eventgridextensionconfig_extension", "eventgrid_extension"} { + if v, ok := res.SystemKeys[key]; ok { + eventGridExtensionConfigKey = *v + break + } } d.Set("event_grid_extension_config_key", eventGridExtensionConfigKey) diff --git a/internal/services/web/function_app_host_keys_data_source_test.go b/internal/services/web/function_app_host_keys_data_source_test.go index e795cbb879f4..12aef93434cd 100644 --- a/internal/services/web/function_app_host_keys_data_source_test.go +++ b/internal/services/web/function_app_host_keys_data_source_test.go @@ -39,3 +39,87 @@ data "azurerm_function_app_host_keys" "test" { } `, template) } + +func TestAccFunctionAppHostKeysDataSource_linuxEventGridTrigger(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_function_app_host_keys", "test") + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: FunctionAppHostKeysDataSource{}.linuxEventGridTrigger(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("primary_key").Exists(), + check.That(data.ResourceName).Key("default_function_key").Exists(), + check.That(data.ResourceName).Key("event_grid_extension_config_key").Exists(), + ), + }, + }) +} + +func (d FunctionAppHostKeysDataSource) linuxEventGridTrigger(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_service_plan" "test" { + name = "acctestASP-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + os_type = "Linux" + sku_name = "EP1" +} + +resource "azurerm_linux_function_app" "test" { + name = "acctest-%[1]d-func" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + service_plan_id = azurerm_service_plan.test.id + storage_account_name = azurerm_storage_account.test.name + storage_account_access_key = azurerm_storage_account.test.primary_access_key + + zip_deploy_file = abspath("testdata/test_trigger.zip") + + app_settings = { + WEBSITE_RUN_FROM_PACKAGE = 1 + } + + identity { + type = "SystemAssigned" + } + + site_config { + application_stack { + python_version = "3.11" + } + } +} + +// The key is not always present when azurerm_linux_function_app.test creation completes. +resource "time_sleep" "wait_for_event_grid_key" { + depends_on = [azurerm_linux_function_app.test] + + create_duration = "30s" +} + +data "azurerm_function_app_host_keys" "test" { + depends_on = [time_sleep.wait_for_event_grid_key] + + name = azurerm_linux_function_app.test.name + resource_group_name = azurerm_linux_function_app.test.resource_group_name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/internal/services/web/testdata/test_trigger.zip b/internal/services/web/testdata/test_trigger.zip new file mode 100644 index 0000000000000000000000000000000000000000..5e41ab25b0451510c414f4b2490124574a6a05b5 GIT binary patch literal 1059 zcmWIWW@Zs#U|`^2c(c+q;<<`Q{B|HufsuiMlR<_dBfq#rFRM5|FEoUcf!Su-!PNEk zM^Z~GxEUB(z5>;NwZ`__@*h$VX#4(;>(H`HkK~fV%S+Vw^jetuixs;<@O#o zPI4E9SbvyzYJ%WZJ@-nJfS@<888Z79X!>X@ymMc>Be;h9I>Wio{@&AT&c9P->t*lR zb-H0`V_d-T<3HWRx0Zf;a`cg4mcZ%;*OD@&|I#(qJk#xcj#{J|PwdPQ+5djhJI(;O z&)L?wMzEv=FZ>Sl`2(P@_<=r8E6qzT$;{7-Pb?_VE2sqf|MlF1srFtN{`Z}DH|vOk zKT;FYmUP zg$ZANqHFbA{`7m1hWwN3GUoJ#xJ9ujUaGEIX;}aIUHA7KwHBN7{3#sTD+`BN7r;My&E?>uDDt14EMsHEFCZV zelnldiCKEr{af(dBDKZKmXf`D5DNptFDE}aF-NaBwWK67FTI#x8p`c)*}x{usFY^5&okeZgPj{`sm6EVbXPf&w&!x1O4!?=$C;*b;tWmS=7i z`{(@Jo;{iWl*7yicivt7#~R?x$Rx*%D@RBGeaFB6Od