【发布时间】:2021-11-14 11:31:55
【问题描述】:
我有一个在 Azure 中构建的逻辑应用的导出模板。 JSON 文件包含订阅 ID 等信息,这些信息会因环境而异。如何使用变量而不是文字值,例如:
"defaultValue": "/subscriptions/**328974123908741329180713290587125**/resourceGroups/rg-management/providers/Microsoft.Web/connections/azureblob-5"
被替换为:
"defaultValue": "/subscriptions/**var.subscription**/resourceGroups/rg-management/providers/Microsoft.Web/connections/azureblob-5"
我不确定两件事。首先,如何实际使用它来创建逻辑应用程序,其次,我从 Azure 门户导出的 JSON 模板不包含有关与存储帐户的连接的任何信息,因此不知道如何解决这个问题。 JSON 遵循我更新的模块,它相当大。
这是我更新的 terraform 模块:
terraform {
required_providers {
azurerm = {
configuration_aliases = [azurerm.env, azurerm.mgmt]
}
}
}
resource "azurerm_logic_app_workflow" "storage_replication" {
name = "logic-app-storage-replication-${var.environment_name}-${var.resource_location}"
location = var.resource_location
resource_group_name = var.resource_group
}
templatefile("${path.module}/LogicAppStorageReplicationTemplate.json", }"
{
subscription = var.subscription_id,
resource_group = var.resource_group,
resource_location = var.resource_location,
container = var.container
}
)
这是导出的 JSON 模板,其中添加了变量,稍后我将处理密钥库:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_ReplicateStorage_name": {
"defaultValue": "ReplicateStorage",
"type": "String"
},
"connections_azureblob_4_externalid": {
"defaultValue": "/subscriptions/${subscription}/resourceGroups/${resource_group}/providers/Microsoft.Web/connections/azureblob-4",
"type": "String"
},
"connections_azureblob_5_externalid": {
"defaultValue": "/subscriptions/${subscription}/resourceGroups/${resource_group}/providers/Microsoft.Web/connections/azureblob-5",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('workflows_ReplicateStorage_name')]",
"location": "${resource_location}",
"identity": {
"principalId": "#############",
"tenantId": "################",
"type": "SystemAssigned"
},
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_blob_is_added_or_modified_(properties_only)_(V2)_2": {
"recurrence": {
"frequency": "Minute",
"interval": 10
},
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 10
},
"splitOn": "@triggerBody()",
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/triggers/batch/onupdatedfile",
"queries": {
"checkBothCreatedAndModifiedDateTime": false,
"folderId": "/${container}",
"maxFileCount": 1
}
}
}
},
"actions": {
"Create_blob_(V2)": {
"runAfter": {
"Get_blob_content_using_path_(V2)": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"body": "@body('Get_blob_content_using_path_(V2)')",
"headers": {
"ReadFileMetadataFromServer": true
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob_1']['connectionId']"
}
},
"method": "post",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
"queries": {
"folderPath": "@{replace(body('Get_Blob_Metadata_using_path_(V2)')?['Path'], body('Get_Blob_Metadata_using_path_(V2)')?['Name'], '')}",
"name": "@body('Get_Blob_Metadata_using_path_(V2)')?['Name']",
"queryParametersSingleEncoded": true
}
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
}
},
"Get_Blob_Metadata_using_path_(V2)": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/GetFileByPath",
"queries": {
"path": "@triggerBody()?['Path']",
"queryParametersSingleEncoded": true
}
}
},
"Get_blob_content_using_path_(V2)": {
"runAfter": {
"Get_Blob_Metadata_using_path_(V2)": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/GetFileContentByPath",
"queries": {
"inferContentType": true,
"path": "@body('Get_Blob_Metadata_using_path_(V2)')?['Path']",
"queryParametersSingleEncoded": true
}
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"azureblob": {
"connectionId": "[parameters('connections_azureblob_4_externalid')]",
"connectionName": "azureblob-4",
"id": "/subscriptions/${subscription}/providers/Microsoft.Web/locations/${resource_location}/managedApis/azureblob"
},
"azureblob_1": {
"connectionId": "[parameters('connections_azureblob_5_externalid')]",
"connectionName": "azureblob-5",
"id": "/subscriptions/${subscription}/providers/Microsoft.Web/locations/${resource_location}/managedApis/azureblob"
}
}
}
}
}
}
]
}
【问题讨论】:
-
我已经阅读了该文档,但我仍然有点困惑,Terraform 不是我的强项。我还忘记了键/值对来自 Azure 密钥保管库。所以我不确定如何将这些拼凑在一起。
标签: terraform