Search code examples
terraformazure-rm

When creating Event Grid Subscription for topic getting 'ID contained more segments than required'


Created code for deploying Event Grid subscription (which subscribes to existing topic, uses existing storage account and resource group).

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

Subscription pushes messages to storage queue. Quite simple case. Terraform plan executed correctly for the first time. When I run apply it errored out with:

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

Right now I see that after apply this worked fine (subscription is there and saves message to storage queue). However after applying it not able to run terraform plan, because above error.

Does anyone know how to resolve it? Terraform 0.12.25 + provider.azurerm v.2.10.0


Solution

  • Seems like this is known bug, will be fixed in 2.11.0 link

    Going back to version 2.6.0 resolves the issue, same as updating to 2.11.0 (which just got released).