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

Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter or get a TF crash #7144

Closed
kirk-marple opened this issue May 31, 2020 · 7 comments · Fixed by #7222
Milestone

Comments

@kirk-marple
Copy link

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
}

@kirk-marple kirk-marple changed the title Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter or get a crash May 31, 2020
@kirk-marple kirk-marple changed the title Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter or get a crash Must provide all optional values in azurerm_eventgrid_event_subscription.subject_filter or get a TF crash May 31, 2020
@jrauschenbusch
Copy link
Contributor

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.

@neil-yechenwei
Copy link
Contributor

neil-yechenwei commented Jun 2, 2020

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

@kirk-marple
Copy link
Author

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.

@neil-yechenwei
Copy link
Contributor

neil-yechenwei commented Jun 4, 2020

@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?

@neil-yechenwei
Copy link
Contributor

neil-yechenwei commented Jun 4, 2020

@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.

@ghost
Copy link

ghost commented Jun 11, 2020

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 ...

@ghost
Copy link

ghost commented Jul 5, 2020

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!

@ghost ghost locked and limited conversation to collaborators Jul 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants