[英]azure function via terraform: how to connect to service bus
我在嘗試通過 Azure DevOps 管道和 Z3603E96F8ZAEB776 部署 Azure function 時卡住了
運行terraform apply
工作正常,服務總線看起來很好並且工作正常。 在 Azure 門戶中, function 似乎正在運行,但它抱怨找不到ServiceBusConnection
。
我通過以下 Terraform 聲明定義了它:
resource "azurerm_resource_group" "rg" {
name = "rg-sb-westeurope"
location = "westeurope"
}
resource "azurerm_servicebus_namespace" "sb" {
name = "ns-sb"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "Standard"
}
resource "azurerm_servicebus_queue" "sbq" {
name = "servicebusqueue"
resource_group_name = azurerm_resource_group.rg.name
namespace_name = azurerm_servicebus_namespace.sb.name
enable_partitioning = true
}
resource "azurerm_servicebus_namespace_authorization_rule" "sb-ar" {
name = "servicebus_auth_rule"
namespace_name = azurerm_servicebus_namespace.sb.name
resource_group_name = azurerm_resource_group.rg.name
listen = false
send = true
manage = false
}
在 function 應用程序中,我聲明:
resource "azurerm_function_app" "fa" {
name = "function-app"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
app_service_plan_id = azurerm_app_service_plan.asp.id
storage_account_name = azurerm_storage_account.sa.name
storage_account_access_key = azurerm_storage_account.sa.primary_access_key
app_settings = {
ServiceBusConnection = azurerm_servicebus_namespace_authorization_rule.sb-ar.name
}
}
這個 tf. 不能開箱即用,因為我沒有在這里復制完整的聲明。 我想我設置的連接環境變量錯誤,但不知道如何正確地做到這一點。
編輯在@Heye 的提示下,我得到了它的工作。 這是用primary_connection_string
替換name
的正確片段。
resource "azurerm_function_app" "fa" {
name = "function-app"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
app_service_plan_id = azurerm_app_service_plan.asp.id
storage_account_name = azurerm_storage_account.sa.name
storage_account_access_key = azurerm_storage_account.sa.primary_access_key
app_settings = {
ServiceBusConnection = azurerm_servicebus_namespace_authorization_rule.sb-ar.primary_connection_string
}
}
您將ServiceBusConnection
值設置為授權規則的name
。 但是,您可能希望將其設置為primary_connection_string
,因為它包含密鑰以及連接到服務總線所需的所有信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.