【问题标题】:Creating an Azure event-subscription filtering by Microsoft.Storage.BlobCreated event using Terraform使用 Terraform 通过 Microsoft.Storage.BlobCreated 事件创建 Azure 事件订阅过滤
【发布时间】:2020-11-09 11:19:17
【问题描述】:

使用 Terraform Azure 提供程序 2.19.0 的这个 Azure Cli 示例 (from Azure doc) 的等效项是什么

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>

注意: 在此之后,Terraform Github Issueresource_group_nametopic_name 已弃用。

【问题讨论】:

    标签: azure terraform azure-storage azure-blob-storage terraform-provider-azure


    【解决方案1】:

    所以看起来 Terraform 正在使用范围参数来推断部分参数。

    所以这是 Terraform 中的等价物:

    resource "azurerm_eventgrid_event_subscription" "my_func_sub" {
      name  = "myFuncSub"
      scope = azurerm_storage_account.images.id
    
      included_event_types = [
        "Microsoft.Storage.BlobCreated"
      ]
    
      subject_filter {
        subject_begins_with = "/blobServices/default/containers/${azurerm_storage_container.images.name}/blobs/"
      }
    
      webhook_endpoint {
        url = "https://mystoragetriggeredfunction.azurewebsites.net/runtime/webhooks/eventgrid?functionName=imageresizefunc&code=<key>"
      }
    
    }
    

    当然,在您的情况下,您需要将 azurerm_storage_container.images 和 webhook url 替换为正确的值。

    请注意scope。它应该是将发布事件的资源的 ID。在我们的例子中,它是一个存储容器。

    【讨论】:

      【解决方案2】:

      恐怕你用错了Azure CLI命令,只有az eventgrid event-subscription create之类的Event Grid的CLI命令,没有资源组的参数。所以你也不需要在 Terraform 代码中关心它。

      更新:

      更多注意参数scope

      指定 EventGrid 事件订阅的范围 被创建。

      您也可以从参数--source-resource-id Azure CLI 命令中理解:

      --source-resource-id

      事件所在的 Azure 资源的完全限定标识符 需要创建订阅。

      Terraform 没有清楚地描述它。所以我们需要从 CLI 或 Azure REST API 来理​​解它,这就是你在 Azure 中创建资源时最终使用的实际东西。

      而且 Terraform 也不支持 Azure 支持的所有东西。我有时也对 Terraform 感到困惑。这个时候,我建议你直接使用 CLI 命令或者在 Terraform 代码中运行 CLI 命令。

      【讨论】:

      • 然后,看起来文档是错误的。我在 Azure 文档中添加了指向示例的链接。顺便说一句,我想出了怎么做。
      • @angelcervera 我认为这与资源组无关。这只是您要创建事件网格的范围。它没有回答你的问题,或者你问错了问题!
      • 对不起,我不明白。我要求 terraform 中的等价物。这将生成相同的事件订阅,如 cli 命令。不必创建事件网格,因为与使用 CLI 一样,它会自动创建为事件网格系统主题。也许我错过了什么。
      • @angelcervera 我看到你关注关于resource_group_nametopic_name 的Github 问题,所以这就是你关心的。我只是回答你不关心它们,只需要注意其他参数。
      • 好的,所以也许是我的错误。我添加了该注释,因为在以前版本的 terraform 中,使用这两个参数是一种方式。实际上,stackoverflow 中有使用这两个参数的旧响应。很抱歉造成混乱。
      猜你喜欢
      • 2020-02-22
      • 2020-04-29
      • 1970-01-01
      • 1970-01-01
      • 2020-03-09
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      相关资源
      最近更新 更多