我正在创建一个Azure逻辑应用程序(使用它解压缩到Blob存储)。为此,我需要Logic App工作流程以及与Blob存储的连接。我使用Terraform创建空的Logic App工作流,并使用Visual Studio创建实际的Logic App实现,然后将其部署到使用tf创建的Logic App。
我使用以下tf代码创建空的Logic App工作流:
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中,我可以创建Logic App,并使用azureblob
连接选择正确的Blob存储。
现在,当我从Visual Studio部署Logic App Workflow并运行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
命令将在删除绑定的连接时断开Logic App。显然,Visual Studio部署已在Logic App和连接之间创建了绑定。
如何告诉Terraform不要从Logic App中删除连接(由Visual Studio部署创建)?
答案 0 :(得分:2)
Terraform不知道在arm模板中部署的资源,因此它检测到状态更改并尝试“修复”该更改。我没有看到用于逻辑应用程序连接的任何CF资源,因此看到它如何检测参数。将连接从0
更改为1
可以将您的连接直接添加到工作流资源中可能有效,但是CF提到:{{ 1}},但我看不到架构中的连接,这有点奇怪,但是我认为我误读了架构
您还可以使用ignore_changes:
Any parameters specified must exist in the Schema defined in workflow_schema
根据评论和this
阅读:
https://www.terraform.io/docs/configuration/resources.html#ignore_changes