As stated in the title, I was able to create an Azure Logic App in the portal where the workflow is a simple time trigger that runs every 5 minutes and as action it “start a given container group” that is an Azure Container Instance resource. During the deployment, the Azure portal created an “API connection” resource that I believe is the interface between the logic app action and the actual action through its API.
Anyway, how can I deploy the same resources with Terraform?
This is my attempt so far:
# Create the Azure Logic App resources
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group
resource "azurerm_logic_app_workflow" "example" {
name = "workflow"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_logic_app_trigger_recurrence" "example" {
name = "run-every-five-minutes"
logic_app_id = azurerm_logic_app_workflow.workflow.id
frequency = "Minute"
interval = 5
}
Thank you
Here there is the Microsoft documentation about the action type:
Schema reference for trigger and action types - Azure Logic Apps | Microsoft Learn
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/logic_app_action_custom
# https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-actions-triggers?redirectedfrom=MSDN#actions-overview
resource "azurerm_logic_app_action_custom" "machstat_prod_action" {
name = "start-container-group-action"
logic_app_id = azurerm_logic_app_workflow.machstat_prod_workflow.id
body = <<BODY
{
"type": "ApiConnection"
"description": "Start containers in a container group",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['aci']['connectionId']"
}
},
"method": "post",
"path": "/subscriptions/@{encodeURIComponent('my_subscription_string')}/resourceGroups/@{encodeURIComponent('my_resource_group_string')}/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent('my_container_group_string')}/start",
"queries": {
"x-ms-api-version": "2019-12-01"
}
"runAfter": {},
}
BODY
}
and the “ApiConnection” connection resource is given in the parameters field, note that when I was prompted to create this API connection in the Azure Portal, I gave it the name “aci”:
"parameters": {
"$connections": {
"value": {
"aci": {
"connectionId": "/subscriptions/my_subscription_string/resourceGroups/my_resource_group_string/providers/Microsoft.Web/connections/aci",
"connectionName": "aci",
"id": "/subscriptions/my_subscription_string/providers/Microsoft.Web/locations/westeurope/managedApis/aci"
}
}
}
}
Now I am reading about variables in order to get the needed strings from the terraform file directly. Do you know how can I define this ApiConnection in terraform as IaC?
I’m still investigating on how to resolve this if anyone has some inputs, thank you