我尝试将ARM模板转换为Terraform,首先创建Microsoft.Web/connections资源到Slack。我一直遇到一个问题,让我感到困惑。使用以下Terraform:
provider "azurerm" {
features {}
}
provider "azapi" {
}
locals {
name = "slack-notification-test"
resource_location = "South Central US"
logic_app_sku = "Standard"
resource_group_name = "deleteme"
slack_channel_name = "critical-alerts"
}
data "azurerm_subscription" "current" { }
resource "azurerm_resource_group" "group" {
name = local.resource_group_name
location = local.resource_location
}
resource "azapi_resource" "slackIntegrationAccount" {
type = "Microsoft.Logic/integrationAccounts@2016-06-01"
name = "${local.name}-slackIntegration"
parent_id = azurerm_resource_group.group.id
location = local.resource_location
body = jsonencode({
"sku": {
"name": "Free"
},
"properties": {
"state": "Enabled"
}
})
}
resource "azapi_resource" "slackConnection" {
type = "Microsoft.Web/connections@2016-06-01"
name = "${local.name}-slackConnection"
parent_id = azurerm_resource_group.group.id
location = local.resource_location
body = jsonencode({
"properties": {
"displayName": "Slack",
"statuses": [
{
"status": "Connected"
}
],
"customParameterValues": {},
"nonSecretParameterValues": {},
"createdTime": "2022-09-20T17:10:26.9106346Z",
"changedTime": "2022-09-20T17:10:37.870701Z",
"api": {
"name": "${local.name}-slackConnection",
"displayName": "Slack",
"description": "Slack is a team communication tool, that brings together all of your team communications in one place, instantly searchable and available wherever you go.",
"iconUri": "https://connectoricons-prod.azureedge.net/releases/v1.0.1582/1.0.1582.2855/${local.name}-slackConnection/icon.png"
"brandColor": "#78D4B6",
"id": "/subscriptions/${data.azurerm_subscription.current.subscription_id}/providers/Microsoft.Web/locations/${local.resource_location}/managedApis/${local.name}-slackConnection"
"type": "Microsoft.Web/locations/managedApis"
},
"testLinks": [
{
"requestUri": "https://management.azure.com:443/subscriptions/${data.azurerm_subscription.current.subscription_id}/resourceGroups/${local.resource_location}/providers/Microsoft.Web/connections/${local.name}-slackConnection/extensions/proxy/conversations.list?api-version=2016-06-01"
"method": "get"
}
]
}
})
}
我在输出中得到错误“ApiNotFound”,并创建了资源组和集成帐户,但仅此而已。x1c 0d1x
2条答案
按热度按时间5lhxktic1#
我检查了以下代码:
main.tf:
我收到错误
当你在Terraform中定义一个自定义API连接时,它似乎并没有在Azure中创建API连接。
您可能需要使用Azure门户文档手动在Azure中创建自定义API连接资源,或者使用PowerShell或Azure CLI以编程方式创建。
在我的例子中,我使用资源
"azurerm_api_connection"
创建了API连接:使用下面的ARM模板,尝试在terraform中创建ARM模板部署:
示例:
摘录:
main.tf:
参考:Unable to connect the API connection to the logic App via ARM template in terraform - Stack Overflow by @Ansuman Bal
krugob8w2#
正如@kavyaS提到的,使用azurerm_managed_API而不是azapi_resource。下面是一个工作片段: