Reputation: 39
I am currently deploying logic apps standard using terraform and want to create a set of standard workflows. I can create the workflows manually though the azure porta but - how can I create the workflows in terraform? does terraform support this? possible to link the module or how this could be achieved
any help on this much appreciated, thank you.
Upvotes: 0
Views: 2415
Reputation: 861
We solved it by simply replacing the .json workflow and connections file in the storage account like this:
locals {
content_type_json = "application/json" # Content type for the file uploads
logic_app_workflow_root_path = "site/wwwroot" # Destination wwwroot path
workflow_file_name = "workflow.json" # Local and remote workflow file naming
connections_file_name = "connections.json" # Local and remote connections file naming
workflow_name = "default"
}
resource "azurerm_logic_app_standard" "logic_app_standard" {
name = "my-logic-app"
location = var.location
resource_group_name = var.resource_group
app_service_plan_id = var.service_plan_id
storage_account_name = var.storage_account_name
storage_account_access_key = var.storage_account_key
storage_account_share_name = azurerm_storage_share.storage_share.name
}
# Storage Account share which has all the logic app files
resource "azurerm_storage_share" "storage_share" {
name = "logic-app-share"
storage_account_name = var.storage_account_name
quota = 5
}
# Create the directory containing workflow files in the storage account share
resource "azurerm_storage_share_directory" "directory" {
name = "${local.logic_app_workflow_root_path}/${local.workflow_name}"
storage_share_id = azurerm_storage_share.storage_share.id
}
# This will replace the workflow file in the storage account share thus effectivly deploying the workflow
resource "azurerm_storage_share_file" "workflow" {
name = local.workflow_file_name
storage_share_id = azurerm_storage_share.storage_share.id
path = "${local.logic_app_workflow_root_path}/${local.workflow_name}"
source = "somePath/${local.workflow_file_name}"
content_md5 = filemd5("somePath/${local.workflow_file_name}")
content_type = local.content_type_json
}
resource "azurerm_storage_share_file" "connections" {
name = local.connections_file_name
storage_share_id = azurerm_storage_share.storage_share.id
path = local.logic_app_workflow_root_path
source = "somePath${local.connections_file_name}"
content_md5 = filemd5("somePath/${local.connections_file_name}")
content_type = local.content_type_json
}
The downside (if you can call it that) of this approach is that the MD5 hash will be calculated every time. So there will always be a diff in the plan. Of course you have to adapt the local filepaths. The example here expects connections.json
and workflow.json
to be in the same directory.
Upvotes: 0
Reputation: 8018
It is possible to create a logic app standard workflow using terraform.
Terraform code:
data "azurerm_resource_group" "example" {
name = "xxxx"
}
resource "azurerm_storage_account" "logicapp_std_storage" {
name = "strplatlasta${var.environment_name}"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_app_service_plan" "logicappplan" {
name = "asp-platform-logicapps"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
kind = "elastic"
is_xenon = "false"
per_site_scaling = "false"
reserved = "false"
tags = {}
zone_redundant = "false"
sku {
tier = "WorkflowStandard"
size = "WS1"
}
}
resource "azurerm_log_analytics_workspace" "logicapplogs" {
name = "log-platform-logicapps"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_application_insights" "platform_logicapp_appinsights" {
name = "${var.context_prefix}-ai-platform-logicapps-${var.environment_name}"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
application_type = "web"
workspace_id = azurerm_log_analytics_workspace.logicapplogs.id
}
resource "azurerm_logic_app_standard" "helloworld" {
name = "la-hello-world"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.logicappplan.id
storage_account_name = azurerm_storage_account.logicapp_std_storage.name
storage_account_access_key = azurerm_storage_account.logicapp_std_storage.primary_access_key
storage_account_share_name = "la-hello-world"
https_only = true
version = "~3"
site_config {
always_on = false
dotnet_framework_version = "v4.0"
ftps_state = "Disabled"
pre_warmed_instance_count = "0"
app_scale_limit = "1"
}
identity {
type = "SystemAssigned"
}
}
variable "workflow_name"{}
data "template_file" "workflow" {
template = file(local.arm_file_path)
}
// Deploy the ARM template workflow
resource "azurerm_template_deployment" "workflow" {
depends_on = [azurerm_logic_app_standard.hello-world]
resource_group_name = var.shared_env.rg.name
parameters = merge({
"workflowName" = var.workflow_name,
"location" = "eastus"
}, var.parameters)
template_body = data.template_file.workflow.template
}
References:
Upvotes: 0