Found a strange issue when creating Azure Event Grid subscription.
If I don't provide all the values of 'subject_filter' block, I get a hard crash (Gist below), and it says it's a Terraform bug.
From looking at the code, it shows all values as optional for subject_filter, so I'm not clear why they're all required.
AzureRM: 2.12
Terraform 0.12.26
resource "azurerm_eventgrid_event_subscription" "event_grid_subscription" {
name = "${var.platform_name}-subscription-${var.function_name}"
scope = var.topic_id
event_delivery_schema = "EventGridSchema"
included_event_types = var.included_event_types
subject_filter {
subject_begins_with = var.subject_begins_with
subject_ends_with = var.subject_ends_with
# NOTE: commenting out this line causes this crash
case_sensitive = false
}
webhook_endpoint {
url = "${var.functions_uri}/runtime/webhooks/EventGrid?functionName=${var.function_name}&code=${var.functions_key}"
}
}
https://gist.github.com/kirk-marple/12c844ec9e436f4763c8eff788880bd1
Successfully create Azure Event Grid subscription to webhook.
Failed to create Azure Event Grid subscription.
This fails:
subject_filter {
subject_begins_with = var.subject_begins_with
subject_ends_with = var.subject_ends_with
}
This works:
subject_filter {
subject_begins_with = var.subject_begins_with
subject_ends_with = var.subject_ends_with
case_sensitive = false
}
This is a bug inside the expand function for the subject filter. Although the schema params are defined as Optional they are required as otherwise the type conversion fails due to a nil pointer dereference.
Thanks for opening this issue. After tested, seems I can create this resource successfully with below tfconfig which is similar with yours. Perhaps this issue only occurred in some cases. If you want, please have a try below tfconfig to check whether the problem still exists. If still exists, could you possibly share entire tf config that trigger this problem? Thanks.
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-eg-test"
location = "westus"
}
resource "azurerm_storage_account" "test" {
name = "acctestacctest"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_queue" "test" {
name = "mysamplequeue-test"
storage_account_name = azurerm_storage_account.test.name
}
resource "azurerm_eventgrid_event_subscription" "test" {
name = "acctest-eg-test"
scope = azurerm_resource_group.test.id
event_delivery_schema = "EventGridSchema"
storage_queue_endpoint {
storage_account_id = azurerm_storage_account.test.id
queue_name = azurerm_storage_queue.test.name
}
included_event_types = ["Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted"]
subject_filter {
subject_begins_with = "test/test"
subject_ends_with = ".jpg"
}
}
Here's the whole module I'm using. I can't easily provide the entire config, since it's one part of a big infrastructure.
It may also be due to using default values ("") for subject_begins_with, subject_ends_with.
function-event-grid-subscription.zip
Hope that helps.
@kirk-marple , sorry, seems I still cannot repro this issue with your tfconfig after tested. And then I also checked your debug log, seems you encountered this issue at modification stage not first creation, right? If yes, could you provide the repro steps?
@kirk-marple, I think I can repro it now. Seems the failure is caused by nil pointer reference error while subject_filter from nil to map[string]interface{}. I'll submit a fix for this. And if you want to remove all values in subject_filter block, suggests to directly remove this whole block from tfconfig. Thanks.
This has been released in version 2.14.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:
provider "azurerm" {
version = "~> 2.14.0"
}
# ... other configuration ...
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!