From 345c1264b697c00a024c9f253faa3cc6d7acffd8 Mon Sep 17 00:00:00 2001 From: Tomas Jezek Date: Wed, 26 Apr 2023 08:02:59 +0200 Subject: [PATCH 1/5] fix logic app standard changes deployment --- modules/azure/logic_app_standard/main.tf | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/azure/logic_app_standard/main.tf b/modules/azure/logic_app_standard/main.tf index e3f39f55..01e3ebf5 100644 --- a/modules/azure/logic_app_standard/main.tf +++ b/modules/azure/logic_app_standard/main.tf @@ -54,11 +54,25 @@ 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" { + command = "cd ${path.module} && mkdir -p files && cd files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/deploy.zip ." + } } # After the logic app is created, start a deployment using the Azure CLI @@ -70,11 +84,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 } } @@ -83,7 +100,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" { @@ -99,10 +116,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" } } From 4919f2c099f9f841d1154c786a701d695f472eb0 Mon Sep 17 00:00:00 2001 From: Tomas Jezek Date: Wed, 26 Apr 2023 08:03:54 +0200 Subject: [PATCH 2/5] fix formatting in logic_app_standard main.tf --- modules/azure/logic_app_standard/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/azure/logic_app_standard/main.tf b/modules/azure/logic_app_standard/main.tf index 01e3ebf5..04248d43 100644 --- a/modules/azure/logic_app_standard/main.tf +++ b/modules/azure/logic_app_standard/main.tf @@ -84,7 +84,7 @@ resource "null_resource" "zip_logic_app" { # deployment to make sure the app settings are available before the deployment is started. resource "time_sleep" "wait_for_app_settings" { - depends_on = [ + depends_on = [ azurerm_logic_app_standard.app, null_resource.zip_logic_app ] From a014431d1e0966f1793ccbb71deb94bf9414d024 Mon Sep 17 00:00:00 2001 From: Tomas Jezek Date: Wed, 26 Apr 2023 12:08:58 +0200 Subject: [PATCH 3/5] add PowerShell command for non-linux machines --- modules/azure/logic_app_standard/main.tf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/azure/logic_app_standard/main.tf b/modules/azure/logic_app_standard/main.tf index 04248d43..413201c7 100644 --- a/modules/azure/logic_app_standard/main.tf +++ b/modules/azure/logic_app_standard/main.tf @@ -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 @@ -71,7 +75,8 @@ resource "null_resource" "zip_logic_app" { } # if check.zip file changes, create deploy.zip file provisioner "local-exec" { - command = "cd ${path.module} && mkdir -p files && cd files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/deploy.zip ." + interpreter = local.is_linux ? ["bash", "-c"] : ["PowerShell", "-Command"] + command = local.is_linux ? "cd ${path.module} && mkdir -p files && cd files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/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\"" } } From eb915612c0ed3e98ebf7d69d2b33eceff965af7d Mon Sep 17 00:00:00 2001 From: Tomas Jezek Date: Wed, 26 Apr 2023 12:09:34 +0200 Subject: [PATCH 4/5] fix formatting in logic_app_standard main.tf --- modules/azure/logic_app_standard/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/azure/logic_app_standard/main.tf b/modules/azure/logic_app_standard/main.tf index 413201c7..fc9683d6 100644 --- a/modules/azure/logic_app_standard/main.tf +++ b/modules/azure/logic_app_standard/main.tf @@ -76,7 +76,7 @@ resource "null_resource" "zip_logic_app" { # 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 files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/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\"" + command = local.is_linux ? "cd ${path.module} && mkdir -p files && cd files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/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\"" } } From e56d2be92d5c9d91c56924934500d12313dda2d4 Mon Sep 17 00:00:00 2001 From: tjezek <122079792+tjezek@users.noreply.github.com> Date: Wed, 26 Apr 2023 16:52:34 +0200 Subject: [PATCH 5/5] simplify zip command Co-authored-by: tom-reinders --- modules/azure/logic_app_standard/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/azure/logic_app_standard/main.tf b/modules/azure/logic_app_standard/main.tf index fc9683d6..2ab83323 100644 --- a/modules/azure/logic_app_standard/main.tf +++ b/modules/azure/logic_app_standard/main.tf @@ -76,7 +76,7 @@ resource "null_resource" "zip_logic_app" { # 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 files && cd ${var.workflows_source_path} && zip -rq $OLDPWD/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\"" + 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\"" } }