Terraform - 创建 Azure 事件网格订阅 - 它能做到吗?

Terraform - Creating Azure Event Grid Subscriptions - can it do it?

为了在 Azure 事件网格中创建事件订阅,我在 Terraform 中苦苦挣扎了一段时间

根据屏幕截图....

EVENT SUBSCRIPTION DETAILS
NAME : EventGrid-Sub1
(don't need to change Event Schema) 

TOPIC DETAILS
Event Grid Domain
Topic Resource: EDG-SBX-EventGrid1
Domain Type: EventGrid-DomainTopic1 

ENDPOINT DETAILS
Endpoint Type: Event Hubs
Endpoint : eh-sbx-Ingestion 

我一直在用这些作为参考,但它似乎不仅有点鸡与蛋,而且还缺了一块?

https://www.terraform.io/docs/providers/azurerm/r/eventgrid_event_subscription.html https://www.terraform.io/docs/providers/azurerm/r/eventgrid_topic.html

有人在 Terraform 中使用过吗?

提前致谢

Azure Screenshot on Event Grids / Create Event Subscription screen

@nmca70 有几种方法可以实现这一点:

  1. 从最终部署创建一个 ARM 模板,然后 运行 使用 Terraform 创建该 ARM 模板:

https://www.terraform.io/docs/providers/azurerm/r/template_deployment.html

  1. 按以下顺序创建资源:

样本:

resource "azurerm_resource_group" "test" {
  name     = "resourceGroup1"
  location = "West US 2"
}

resource "azurerm_eventhub_namespace" "test" {
  name                = "acceptanceTestEventHubNamespace"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
  sku                 = "Standard"
  capacity            = 1
  kafka_enabled       = false

  tags = {
    environment = "Production"
  }
}

resource "azurerm_eventhub" "test" {
  name                = "acceptanceTestEventHub"
  namespace_name      = "${azurerm_eventhub_namespace.test.name}"
  resource_group_name = "${azurerm_resource_group.test.name}"
  partition_count     = 2
  message_retention   = 1
}

resource "azurerm_eventgrid_topic" "test" {
  name                = "my-eventgrid-topic"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"

  tags = {
    environment = "Production"
  }
}

resource "azurerm_eventgrid_domain" "test" {
  name                = "my-eventgrid-domain"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
  input_schema        = "eventgridschema"

  input_mapping_fields= {
    topic = "my-eventgrid-topic"
  }

  tags = {
    environment = "Production"
  }
}

resource "azurerm_eventgrid_event_subscription" "default" {
  name  = "defaultEventSubscription"
  scope = "${azurerm_resource_group.default.id}"
  event_delivery_schema = "EventGridSchema"
  topic_name = "my-eventgrid-topic"

  eventhub_endpoint {
    storage_account_id = "${azurerm_eventhub.test.id}"
  }
}

希望对您有所帮助!