Search code examples
azureterraformazure-storageazure-blob-storageterraform-provider-azure

Creating an Azure event-subscription filtering by Microsoft.Storage.BlobCreated event using Terraform


What is the equivalent of this Azure Cli example (from Azure doc) using Terraform Azure provider 2.19.0

az eventgrid resource event-subscription create -g myResourceGroup \
--provider-namespace Microsoft.Storage --resource-type storageAccounts \
--resource-name myblobstorage12345 --name myFuncSub  \
--included-event-types Microsoft.Storage.BlobCreated \
--subject-begins-with /blobServices/default/containers/images/blobs/ \
--endpoint https://mystoragetriggeredfunction.azurewebsites.net/runtime/webhooks/eventgrid?functionName=imageresizefunc&code=<key>

Note: Following this Terraform Github Issue, resource_group_name and topic_name are deprecated.


Solution

  • I'm afraid you use the wrong Azure CLI command, there is only CLI command for Event Grid like az eventgrid event-subscription create, and it does not have the parameter for the resource group. So you also do not need to care about it in the Terraform code.

    Update:

    With more attention to the parameter scope:

    Specifies the scope at which the EventGrid Event Subscription should be created.

    You can also understand it from parameter --source-resource-id the Azure CLI command :

    --source-resource-id

    Fully qualified identifier of the Azure resource to which the event subscription needs to be created.

    Terraform does not describe it clearly. So we need to understand it from the CLI or Azure REST API, that's the actual thing finally used when you create resources in Azure.

    And Terraform also does not support all the things that Azure supports. I'm also confused with Terraform sometimes. When this time, I recommend you using the CLI command directly or run the CLI command inside the Terraform code.