我正在尝试使用 Terraform 和 Azure的Terraform提供程序在Azure中创建以下资源。
运行Terraform脚本时,出现以下错误
错误:创建/更新EventGrid事件订阅时出错 “ evtFileReceived”(范围 “ / subscriptions / c17cf5ee-d3d7-4f64-b863-f2a4d6948594 / resourceGroups / dominos-doodle”): eventgrid.EventSubscriptionsClient#CreateOrUpdate:发送失败 请求:StatusCode = 400-原始错误:Code =“ InvalidRequest” Message =“指定的主题属性与预期的不匹配 事件订阅范围中的主题。”
我该如何解决? Google搜索未给出任何结果。
生成错误的脚本如下。引发错误的步骤是terraform apply
显然,一种方法是使用ARM模板来实现此目的,但我试图查看是否可以使用本机Terraform脚本创建它。我参考了Terraform Docs并创建了以下内容。
variable "inp_resource_group_name" { }
variable "inp_geo_location" { }
variable "inp_account_name" { }
variable "inp_az_subscription_id" { }
variable "inp_resource_group_id" { }
resource "azurerm_storage_account" "cave" {
name = var.inp_account_name
resource_group_name = var.inp_resource_group_name
location = var.inp_geo_location
account_tier = "Standard"
account_replication_type = "LRS"
account_kind = "StorageV2"
}
resource "azurerm_storage_container" "validName" {
name = validName"
resource_group_name = var.inp_resource_group_name
storage_account_name = var.inp_account_name
container_access_type = "blob"
}
resource "azurerm_eventgrid_event_subscription" "evtFileReceived" {
name = "evtFileReceived"
scope = var.inp_resource_group_id
topic_name="/subscriptions/${var.inp_az_subscription_id}/resourceGroups/${var.inp_resource_group_name}/providers/Microsoft.Storage/storageAccounts/{var.inp_account_name}"
webhook_endpoint {
url = "https://myendpoint.that.works.well.across.all.osi.layers"
}
}
答案 0 :(得分:1)
根据错误消息,它表明资源azurerm_eventgrid_event_subscription
中的 topic_name 属性与事件订阅范围中的预期主题不匹配。
在这种情况下,因为主题与存储帐户资源相关联,所以应该在存储帐户级别创建范围。它会像这样:
resource "azurerm_eventgrid_event_subscription" "evtFileReceived" {
name = "evtFileReceived"
scope = ${azurerm_storage_account.cave.id}
topic_name="/subscriptions/${var.inp_az_subscription_id}/resourceGroups/${var.inp_resource_group_name}/providers/Microsoft.Storage/storageAccounts/{azurerm_storage_account.cave.name}"
webhook_endpoint {
url = "https://myendpoint.that.works.well.across.all.osi.layers"
}
}
或者,请参考此GitHub issue,您可以将作用域与 eventgrid主题。
意识到这种情况下的资源组是主题的艺术 输入要订阅的类型,而不是创建订阅的引用 资源。似乎“ topic_name”和“ resource_group_name”是 不推荐使用的参数。使用“范围”代替ID eventgrid主题。
它会像这样:
resource "azurerm_eventgrid_topic" "example" {
name = "my-eventgrid-topic"
location = "${azurerm_resource_group.default.location}"
resource_group_name = "${azurerm_resource_group.default.name}"
}
resource "azurerm_eventgrid_event_subscription" "evtFileReceived" {
name = "evtFileReceived"
scope = "${azurerm_eventgrid_topic.example.id}"
webhook_endpoint {
url = "https://myendpoint.that.works.well.across.all.osi.layers"
}
}
请告诉我这是否可行或需要进一步的帮助。
答案 1 :(得分:1)
我遇到了类似的问题,并通过将作用域和topic_name都设置为存储帐户ID来解决了该问题。因此,在您的示例中,我认为这应该可行;
resource "azurerm_eventgrid_event_subscription" "evtFileReceived" {
name = "evtFileReceived"
scope = azurerm_storage_account.cave.id
topic_name = azurerm_storage_account.cave.id
webhook_endpoint {
url = "https://myendpoint.that.works.well.across.all.osi.layers"
}
}