0

I am creating an Azure Logic App (using it to unzip to a blob storage). For this I need the Logic App workflow and a connection to the blob storage. I create the empty Logic App Workflow with Terraform and the actual Logic App implementation with Visual Studio that I just then deploy to the Logic App created with tf.

I use following tf code to create the empty Logic App Workflow:

resource "azurerm_logic_app_workflow" "logic_unzip" {                    
  name                    = "ngh-${var.deployment}-unziplogic"     
  resource_group_name     = "${azurerm_resource_group.rg.name}"    
  location                = "${azurerm_resource_group.rg.location}"
}                                                                        

As the Logic App needs connection to the Blob storage I will use following template to create it:

resource "azurerm_template_deployment" "depl_connection_azureblob" {                                                                               
        name                    = "azureblob"                                                                                                      
        resource_group_name     = "${azurerm_resource_group.rg.name}"                                                                              

        template_body = <<DEPLOY                                                                                                                   
{                                                                                                                                                  
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",                                              
        "contentVersion": "1.0.0.0",                                                                                                               
        "parameters": {                                                                                                                            
                "connection_name": {"type": "string"},                                                                                             
                "storage_name": {"type": "string"},                                                                                                
                "storage_access_key": {"type": "string"},                                                                                          
                "location": {"type": "string"},                                                                                                    
                "api_id": {"type": "string"}                                                                                                       
        },                                                                                                                                         
        "resources": [{                                                                                                                            
                "type": "Microsoft.Web/connections",                                                                                               
                "name": "[parameters('connection_name')]",                                                                                         
                "apiVersion": "2016-06-01",                                                                                                        
                "location": "[parameters('location')]",                                                                                            
                "scale": null,                                                                                                                     
                "properties": {                                                                                                                    
                        "displayName": "[parameters('connection_name')]",                                                                          
                        "api": {                                                                                                                   
                                "id": "[parameters('api_id')]"                                                                                     
                        },                                                                                                                         
                        "parameterValues": {                                                                                                       
                                "accountName": "[parameters('storage_name')]",                                                                     
                                "accessKey": "[parameters('storage_access_key')]"                                                                  
                        }                                                                                                                          
                },                                                                                                                                 
                "dependsOn": []                                                                                                                    
        }]                                                                                                                                         
}                                                                                                                                                  
DEPLOY                                                                                                                                             
        parameters              = {                                                                                                                
                "connection_name"       = "azureblob"                                                                                              
                "storage_name"          = "${azurerm_storage_account.sa-main.name}"                                                                
                "storage_access_key"    = "${azurerm_storage_account.sa-main.primary_access_key}"                                                  
                "location"              = "${azurerm_resource_group.rg.location}"                                                                  
                "api_id"                = "${data.azurerm_subscription.current.id}/providers/Microsoft.Web/locations/${azurerm_resource_group.rg.location}/managedApis/azureblob"                                                                                                                     
        }                                                                                                                                          
        deployment_mode         = "Incremental"                                                                                                    
}                                                                                                                                                  

Running plan and apply, these work perfect. In Visual Studio I can then create the Logic App and use the azureblob connection to select the correct blob storage.

Now, when I have deployed the Logic App Workflow from Visual Studio and run terraform plan I get following changes:

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ azurerm_logic_app_workflow.logic_unzip
      parameters.$connections: "" => ""
      parameters.%:            "1" => "0"


Plan: 0 to add, 1 to change, 0 to destroy.

Running the apply command now will break the Logic App as it removes the bound connection. Clearly the Visual Studio deploy has created the binding between the Logic App and the connection.

How can I tell Terraform not to remove the connections (created by the Visual Studio deploy) from the Logic App?

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
Juho Rutila
  • 2,316
  • 1
  • 25
  • 40

1 Answers1

2

Terraform is not aware of the resources deployed in the arm template, so it detects the state change and tries to "fix" that. I dont see any CF resources for logic app connections, so seeing how it detects that parameters.connections changed from 0 to 1 adding your connection directly to the workflow resource might work, but CF mentions : Any parameters specified must exist in the Schema defined in workflow_schema, but I dont see connections in the schema, which is a bit weird, but I assume I'm misreading the schema

you can also use ignore_changes:

lifecycle {
    ignore_changes = [
        "parameters.$connections"
    ]
}

according to the comments and this

reading:
https://www.terraform.io/docs/configuration/resources.html#ignore_changes

Juho Rutila
  • 2,316
  • 1
  • 25
  • 40
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • 5
    Going to ask again but please stop calling it "crappyform" just because you don't like the tool. Also you can use `ignore_changes` to have Terraform play nicely with other tooling. – ydaetskcoR Mar 18 '19 at 10:26
  • Yup, ignore_changes is enough. Thanks a lot. And if not "crappyform" what then? – Juho Rutila Mar 18 '19 at 11:58
  • you are only using cf to apply the template, i dont see any reason to use it in this case, just use the template? – 4c74356b41 Mar 18 '19 at 12:50
  • Ah, that was only excerpt of the bigger whole file. But I quite like the idea behind Terraform. Thanks, anyway. – Juho Rutila Mar 18 '19 at 21:07
  • the idea is okay (nothing new, though), implementation is crap – 4c74356b41 Mar 18 '19 at 21:11
  • I also had to remove the tags I had on my logic app. It forced change again in the Logic App causing a badrequest. – Jorn.Beyers Sep 03 '20 at 09:51
  • Please note that the syntax for ignore_changes has changed in later versions of TF. I am using `lifecycle { ignore_changes = [ # Ignore changes to connections made outside of TF (TF does not currently support connections) parameters ] } ` – Jonny Leigh Sep 03 '20 at 15:00