Terraform-provider-azurerm: Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter or get a TF crash

Created on 31 May 2020  ·  7Comments  ·  Source: terraform-providers/terraform-provider-azurerm

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.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

AzureRM: 2.12
Terraform 0.12.26

Affected Resource(s)

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}"
}
}

Debug Output

https://gist.github.com/kirk-marple/12c844ec9e436f4763c8eff788880bd1

Expected Behavior

Successfully create Azure Event Grid subscription to webhook.

Actual Behavior

Failed to create Azure Event Grid subscription.

Steps to Reproduce

This fails:

subject_filter {
subject_begins_with = var.subject_begins_with
subject_ends_with = var.subject_ends_with

case_sensitive = false

}

This works:

subject_filter {
subject_begins_with = var.subject_begins_with
subject_ends_with = var.subject_ends_with
case_sensitive = false
}

bug servicevent-grid

All 7 comments

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!

Was this page helpful?
0 / 5 - 0 ratings