I’m attempting to convert an ARM template to Terraform that starts of by creating a Microsoft.Web/connections resource to Slack. I keep running into an issue that has me stumped. Using the following 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"
}
]
}
})
}
I get the error "ApiNotFound" in the output, and the resource group and integration account are created but that is it.
2
Answers
As @kavyaS mentioned using a azurerm_managed_api instead of azapi_resource. Here is a working snippet:
I checked with following with following code:
main.tf:
I received the error
When you define a custom API connection in Terraform, it seems it is not actually creating the API connection in Azure.
one may need to create the custom API connection resource in Azure manually by using Azure portal documentation, or programmatically using PowerShell or Azure CLI.
In my case I created api connection using resource
"azurerm_api_connection"
:With the below ARM template , tried to create arm template deployment in terraform:
example :
snippet:
main.tf:
Reference : Unable to connect the API connection to the logic App via ARM template in terraform – Stack Overflow by @Ansuman Bal