Terraform eventgrid partner topic activation

I’m trying to configure a log stream using Azure Event Grid using Terraform. I’m able to create an eventgrid partner configuration and then set up a log stream on auth0 that uses this configuration to create a partner topic.

How can, using terraform, I activate this topic once Auth0 creates it? Or am I going about this in the wrong way?

I’ve include my current code below.

locals {
  auth0_immutable_id = "804a11ca-ce9b-4158-8e94-3c8dc7a072ec"
  auth0_partner_name = "Auth0"
}

/////// auth0 partner configuration ///////
resource "azapi_resource" "egpc_auth0" {
  type      = "Microsoft.EventGrid/partnerConfigurations@2021-10-15-preview"
  name      = "default"
  location  = "Global"
  parent_id = azurerm_resource_group.this.id
  tags      = local.common_tags
  body = jsonencode({
    properties = {
      partnerAuthorization = {
        authorizedPartnersList = [
          {
            partnerName                    = local.auth0_partner_name
            partnerRegistrationImmutableId = local.auth0_immutable_id
          }
        ]
      }
    }
  })
}

//////////// auth0 log stream /////////////
resource "auth0_log_stream" "auth0" {
  name   = "ls-${local.prefix_long}"
  type   = "eventgrid"
  status = "active"
  sink {
    azure_subscription_id = var.subscription_id
    azure_resource_group  = azurerm_resource_group.this.name
    azure_region          = azurerm_resource_group.this.location
  }
}

I managed to get this to work using the below code, but this won’t work through gitlab because the hashicorp/terraform container doesn’t have access to the az cli and I cannot install it because it won’t let me elevate privileges. I’m still looking for a solution, but am posting this here in case someone else has the same problem and this can work for them. My next step is to try to work this out using curl against the api, but won’t be able to work on this until next week.

If anyone has anything that might help, I would greatly appreciate it.

locals {
  auth0_partner_name = "Auth0"
  auth0_immutable_id = "804a11ca-ce9b-4158-8e94-3c8dc7a072ec"
}

/////// auth0 partner configuration ///////
resource "azapi_resource" "egpc_auth0" {
  type      = "Microsoft.EventGrid/partnerConfigurations@2021-10-15-preview"
  name      = "default"
  location  = "Global"
  parent_id = azurerm_resource_group.this.id
  tags      = local.common_tags

  body = jsonencode({
    properties = {
      partnerAuthorization = {
        defaultMaximumExpirationTimeInDays = 1
        authorizedPartnersList = [
          {
            partnerName                    = local.auth0_partner_name
            partnerRegistrationImmutableId = local.auth0_immutable_id
          }
        ]
      }
    }
  })
}

//////////// auth0 log stream /////////////
resource "auth0_log_stream" "auth0" {
  name       = "ls-${local.prefix_long}"
  type       = "eventgrid"
  status     = "active"
  depends_on = [azapi_resource.egpc_auth0]

  sink {
    azure_subscription_id = var.subscription_id
    azure_resource_group  = azurerm_resource_group.this.name
    azure_region          = azurerm_resource_group.this.location
  }

  provisioner "local-exec" {
    interpreter = ["/bin/bash", "-c"]
    command     = <<EOF
      partner_topics=$(az eventgrid partner topic list --odata-query "Contains(name, 'auth0-domain-${var.environment}-')" --query [].name --output tsv)
      for partner_topic in $${partner_topics}; do
        echo "Activating EventGrid Partner Topic $${partner_topic}"
        az eventgrid partner topic activate --name $${partner_topic} --resource-group ${azurerm_resource_group.this.name}
      done
    EOF
  }
}