Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue 13568 - event_grid_extension_config_key is null #25108

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions internal/services/web/function_app_host_keys_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Binary file added internal/services/web/testdata/test_trigger.zip
Binary file not shown.
Loading