我正在创建一个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}"
}
由于逻辑应用需要连接到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
连接选择正确的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模板中部署的资源,因此它检测到状态的变化并试图"修复"该资源。我看不到逻辑应用程序连接的任何CF资源,因此请查看其检测到该参数的方式。连接从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