Azure Schema Registry schema creation failing with 404 errors in Event Hub namespace
I'm attempting to automate the creation of Avro schemas in Azure Event Hub's Schema Registry using Terraform, but all approaches (azapi_resource, ARM templates, null_resource with local-exec) result in 404 errors when trying to create the schemas.
Environment Details
Provider versions:
azurerm: ~> 4.0
azapi: ~> 1.14
null: ~> 3.2
external: ~> 2.3
Azure Event Hub namespace tier: Standard
Azure region: westus
Approaches Tried
1. Using azapi_resource:
terraformresource "azapi_resource" "_schema" {
type = "Microsoft.EventHub/namespaces/schemaGroups/schemas@2021-11-01"
name = "schema_name"
parent_id = azurerm_eventhub_namespace_schema_group.schema_group.id
schema_validation_enabled = false
body = jsonencode({
properties = {
schemaType = "Avro"
content = filebase64("${path.module}/schemas/schema_name.avsc")
}
})
}
Error:
Error: Failed to create/update resource
...
RESPONSE 404: 404 Not Found
ERROR CODE UNAVAILABLE
2. Using ARM template deployment:
terraformresource "azurerm_resource_group_template_deployment" "schema" {
name = "schema-deployment"
resource_group_name = data.azurerm_resource_group.eventhub_rg.name
deployment_mode = "Incremental"
template_content = <<TEMPLATE
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.EventHub/namespaces/schemaGroups/schemas",
"apiVersion": "2021-11-01",
"name": "${azurerm_eventhub_namespace.eventhub_ns.name}/schema-group/schema_name",
"properties": {
"schemaType": "Avro",
"content": "${filebase64("${path.module}/schemas/schema_name.avsc")}"
}
}
]
}
TEMPLATE
}
Error:
Error: waiting for creation of Template Deployment "schema-deployment" (Resource Group ""): Code="DeploymentFailed" Message="At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details." Details=[{"code":"NotFound","message":"{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"\"\r\n }\r\n}"}]
3. Using null_resource with local-exec:
`terraformresource "null_resource" "register_schemas" {
provisioner "local-exec" {
command = <<EOT
TOKEN=$(az account get-access-token --resource=https://management.azure.com/ --query accessToken -o tsv)
curl -X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"properties": {
"schemaType": "Avro",
"content": "$(base64 -w 0 ${path.module}/schemas/schema_name.avsc)"
}
}' \
"https://management.azure.com/subscriptions/${var.subscription_id}/resourceGroups/${data.azurerm_resource_group.eventhub_rg.name}/providers/Microsoft.EventHub/namespaces/${azurerm_eventhub_namespace.eventhub_ns.name}/schemaGroups/ro-data-schema-group/schemas/recovery_obligation?api-version=2021-06-01-preview"
EOT
interpreter = ["/bin/bash", "-c"]
}
}`
Result: Similar 404 errors
I've searched for documentation on this specific scenario but haven't found anything conclusive about how to properly create schemas programmatically using Terraform.
I expect to be able to create and register schemas in the Azure Schema Registry as part of my Terraform infrastructure deployment.
Is there a supported way to manage Schema Registry schemas using Terraform?
Are there specific API versions or configuration requirements needed for this to work?
Could there be a regional limitation or preview feature flag needed?
Any guidance would be greatly appreciated!
关闭于 2025-04-11 0 条评论