Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of logic app standard deployment bug #316

Merged
merged 8 commits into from
Apr 26, 2023
38 changes: 30 additions & 8 deletions modules/azure/logic_app_standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ provider "azurerm" {
provider "archive" {
}

locals {
is_linux = length(regexall("/home/", lower(abspath(path.root)))) > 0
}

resource "azurerm_logic_app_standard" "app" {
name = var.logic_app_name
location = var.location
Expand Down Expand Up @@ -54,11 +58,26 @@ resource "azurerm_logic_app_standard" "app" {
virtual_network_subnet_id = var.integration_subnet_id
}

# First, create a zip file containing the workflow
data "archive_file" "workflow" {
# First, create a check.zip with archive_file to check diffs (this step is required)
# replacing this step by checking of deploy.zip created by local-exec doesn't work
# because local-exec is not executed during 'plan' so it would take old deploy.zip
data "archive_file" "check_zip" {
type = "zip"
source_dir = var.workflows_source_path
output_path = "${path.module}/files/deploy.zip"
output_path = "${path.module}/files/check.zip"
}

resource "null_resource" "zip_logic_app" {
depends_on = [data.archive_file.check_zip]

triggers = {
deploy = data.archive_file.check_zip.output_sha
}
# if check.zip file changes, create deploy.zip file
provisioner "local-exec" {
interpreter = local.is_linux ? ["bash", "-c"] : ["PowerShell", "-Command"]
command = local.is_linux ? "cd ${path.module} && mkdir -p files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/files/deploy.zip ." : "New-Item -Path \"${path.module}\" -Name \"files\" -ItemType \"directory\" -Force; Compress-Archive -Path \"${var.workflows_source_path}\\*\" -DestinationPath \"${path.module}\\files\\deploy.zip\""
}
}

# After the logic app is created, start a deployment using the Azure CLI
Expand All @@ -70,11 +89,14 @@ data "archive_file" "workflow" {
# deployment to make sure the app settings are available before the deployment is started.

resource "time_sleep" "wait_for_app_settings" {
depends_on = [azurerm_logic_app_standard.app]
depends_on = [
azurerm_logic_app_standard.app,
null_resource.zip_logic_app
]
create_duration = "${var.deployment_wait_timeout}s"

triggers = {
time = timestamp()
deploy = data.archive_file.check_zip.output_sha
}
}

Expand All @@ -83,7 +105,7 @@ resource "null_resource" "install-extension" {
depends_on = [time_sleep.wait_for_app_settings]

triggers = {
deploy = data.archive_file.workflow.output_sha
deploy = data.archive_file.check_zip.output_sha
}

provisioner "local-exec" {
Expand All @@ -99,10 +121,10 @@ resource "null_resource" "deploy" {
depends_on = [null_resource.install-extension]

triggers = {
deploy = data.archive_file.workflow.output_sha
deploy = data.archive_file.check_zip.output_sha
}

provisioner "local-exec" {
command = "az logicapp deployment source config-zip --name ${var.logic_app_name} --resource-group ${var.resource_group_name} --subscription ${data.azurerm_subscription.current.display_name} --src ${data.archive_file.workflow.output_path}"
command = "az logicapp deployment source config-zip --name ${var.logic_app_name} --resource-group ${var.resource_group_name} --subscription ${data.azurerm_subscription.current.display_name} --src ${path.module}/files/deploy.zip"
}
}