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 000000000000..5e41ab25b045 Binary files /dev/null and b/internal/services/web/testdata/test_trigger.zip differ