Deploying Logic App in Terraform with ARM template + CI/CD

Shervyna Ruan
2 min readOct 21, 2020

Terraform manages logic app in separate actions, triggers, etc. Since we usually create logic app from GUI, we find this a bit nonintuitive and complicated to break down the full json into separate parts. We would like to create logic app resources with the full json that is generated automatically after creating logic from GUI. We found some github issues that were same as what we wanted to achieve, but from the replies, looks like terraform will not support this feature for now:
ex: https://github.com/terraform-providers/terraform-provider-azurerm/issues/5197

https://www.terraform.io/docs/providers/azurerm/r/logic_app_action_custom.html

In this post, I will share our workaround to deploy logic app ARM template within terraform, and how to automate this process with azure pipelines.

  1. First, check in your ARM template(not workflow definition!) and parameters file for your logic app to your repo. It is an easy step if you are using visual studio to create logic app. If you created one from the portal, you can also quickly get a ARM template from portal -> your logic app -> export template.

2. In CI pipeline, you can publish the ARM templates and parameter files to artifact for the other pipeline that runs terraform to consume. The jq command is used to extract only the “parameters” part in the parameter file, as explained in the terraform official doc:

jobs:
- job: build
displayName: Publish ARM template and params to artifacts
steps:
- task: Bash@3
displayName: Prepare parameter files for Terraform
inputs:
targetType: 'inline'
workingDirectory: $(Build.SourcesDirectory)/MyFolder
script: |
cat mylogicapp.parameters.json | jq .parameters > my logicapp_extracted_params.json
- task: CopyFiles@2
displayName: Copy files to artifact staging directory
inputs:
Contents: |
mylogicapp.json
*extracted_params.json
sourceFolder: $(Build.SourcesDirectory)/MyFolder
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishPipelineArtifact@1
displayName: Publish_to_Artifact
inputs:
targetPath: '$(build.artifactstagingdirectory)'
artifact: 'LogicAppArmTemplate'

3. In terraform:

resource "azurerm_template_deployment" "my_logic_app" {
name = "your-logic-app-name"
resource_group_name = "your_rg_name"
template_body = file("mylogicapp.json")
parameters_body = file("mylogicapp_extracted_params.json")
deployment_mode = "Incremental"
}

4. In your pipeline to run terraform, add a step before deploying terraform to download the ARM template/parameters artifacts from CI pipeline:

- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: specific
project: # your ADO project id
definition: 38 # Id of your CI pipeline that publishes the logic app ARM template artifact
artifactName: 'LogicAppArmTemplate'
targetPath: '$(System.DefaultWorkingDirectory)/terraform'

That’s it! Thanks for reading :)

--

--