Terraform 中断 Azure 逻辑应用程序连接

Terraform breaking Azure Logic App connections

我正在创建一个 Azure 逻辑应用程序(使用它解压缩到 blob 存储)。为此,我需要逻辑应用程序工作流和到 blob 存储的连接。我使用 Terraform 创建空的逻辑应用程序工作流,使用 Visual Studio 创建实际的逻辑应用程序实现,然后我将其部署到使用 tf.

创建的逻辑应用程序

我使用以下 tf 代码创建空的逻辑应用程序工作流:

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}"
}                                                                        

由于 Logic App 需要连接到 Blob 存储,我将使用以下模板来创建它:

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"                                                                                                    
}                                                                                                                                                  

运行 计划并应用,这些工​​作非常完美。在 Visual Studio 中,我可以创建逻辑应用程序并使用 azureblob 连接到 select 正确的 blob 存储。

现在,当我从 Visual Studio 和 运行 terraform plan 部署逻辑应用程序工作流时,我得到以下更改:

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.

运行 apply 命令现在会在删除绑定连接时中断逻辑应用程序。显然 Visual Studio 部署已经创建了逻辑应用程序和连接之间的绑定。

如何告诉 Terraform 不要从逻辑应用程序中删除连接(由 Visual Studio 部署创建)?

Terraform 不知道 arm 模板中部署的资源,因此它会检测状态变化并尝试 "fix"。我没有看到任何用于逻辑应用程序连接的 CF 资源,因此查看它如何检测到 parameters.connections 从 0 更改为 1 将您的连接直接添加到工作流资源可能会起作用,但 CF 提到: Any parameters specified must exist in the Schema defined in workflow_schema,但我没有看到模式中的连接,这有点奇怪,但我认为我误读了模式

你也可以使用ignore_changes:

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

根据评论和

阅读中:
https://www.terraform.io/docs/configuration/resources.html#ignore_changes