2

创建了用于部署事件网格订阅的代码(订阅现有主题,使用现有存储帐户和资源组)。

locals {
  environment = terraform.workspace
}

# existing data
data "azurerm_resource_group" "rg" {
  name = "rg-1"
}

data "azurerm_storage_account" "sa" {
  name                = "sa1${local.environment}"
  resource_group_name = data.azurerm_resource_group.rg.name
}

data "azurerm_eventgrid_topic" "topic" {
  name                = "topic-${local.environment}"
  resource_group_name = data.azurerm_resource_group.rg.name
}

# Resources
resource "azurerm_storage_queue" "queue" {
  name                 = "sq-${local.environment}"
  storage_account_name = data.azurerm_storage_account.sa.name
}

resource "azurerm_eventgrid_event_subscription" "sub" {
  name       = "sub-${local.environment}"
  scope      = data.azurerm_eventgrid_topic.topic.id

  storage_queue_endpoint {
    storage_account_id = data.azurerm_storage_account.sa.id
    queue_name         = azurerm_storage_queue.queue.name
  }
}

订阅将消息推送到存储队列。很简单的案例。Terraform 计划第一次正确执行。当我运行应用时,它出错了:

azurerm_storage_queue.queue: Creating...
azurerm_storage_queue.queue: Creation complete after 1s [id=https://sa1dev.queue.core.windows.net/sq-dev]
azurerm_eventgrid_event_subscription.sub: Creating...
azurerm_eventgrid_event_subscription.sub: Still creating... [10s elapsed]
azurerm_eventgrid_event_subscription.sub: Still creating... [20s elapsed]
azurerm_eventgrid_event_subscription.sub: Still creating... [30s elapsed]
azurerm_eventgrid_event_subscription.sub: Still creating... [40s elapsed]
azurerm_eventgrid_event_subscription.sub: Still creating... [50s elapsed]
azurerm_eventgrid_event_subscription.sub: Still creating... [1m0s elapsed]

Error: ID contained more segments than required: "/subscriptions/[SUBSCRIPTION]/resourceGroups/rg-1/providers/Microsoft.EventGrid/topics/topic-dev/providers/Microsoft.EventGrid/eventSubscriptions/sub-dev"

  on main.tf line 27, in resource "azurerm_eventgrid_event_subscription" "sub":
  27: resource "azurerm_eventgrid_event_subscription" "sub" {

现在我看到应用后效果很好(订阅在那里并将消息保存到存储队列)。但是应用它后无法运行 terraform 计划,因为上述错误。

有谁知道如何解决它?Terraform 0.12.25 + provider.azurerm v.2.10.0

4

1 回答 1

2

似乎这是已知的错误,将在 2.11.0链接中修复

回到版本 2.6.0 可以解决问题,与更新到 2.11.0(刚刚发布)相同。

于 2020-05-21T11:51:40.807 回答