terraform - parameters_content 值无法反序列化
问题描述
我正在为 azurerm_resource_group_template_deployment 使用内联部署,并且我正在传递一个使用另一个 terraform 资源名称的参数。
代码:
resource "azurerm_app_service" "webapi" {
name = "${lower(var.deploymentEnvironment)}-webapi"
location = azurerm_resource_group.frontendResourceGroup.location
resource_group_name = azurerm_resource_group.frontendResourceGroup.name
app_service_plan_id = azurerm_app_service_plan.appSvcPlan.id
}
resource "azurerm_resource_group_template_deployment" "webapi_virtual_directory" {
name = "webapi_virtual_directory"
resource_group_name = azurerm_resource_group.frontendResourceGroup.name
deployment_mode = "Incremental"
template_content = <<TEMPLATE
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"type": "String"
},
"virtualApplications":{
"type": "array",
"defaultValue":[
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": false,
"virtualDirectories": null
}
]
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/sites/config",
"name": "[concat(parameters('webAppName'), '/web')]",
"apiVersion": "2020-06-01",
"properties": {
"virtualApplications": "[parameters('virtualApplications')]"
},
"dependsOn": []
}
]
}
TEMPLATE
parameters_content = jsonencode({webAppName = azurerm_app_service.webapi.name})
depends_on = [azurerm_app_service.webapi]
}
当我运行 terraform apply 命令时,出现错误:
错误:验证模板部署“webapi_virtual_directory”(资源组“frontendapps-rg”):请求验证:resources.DeploymentsClient#Validate:发送请求失败:StatusCode=400 - 原始错误:Code="InvalidRequestContent" Message="请求内容无效且无法反序列化:“将值“ci-webapi”转换为类型“Azure.ResourceManager.Deployments.Templates.Definitions.DeploymentParameterDefinition”时出错。路径“properties.parameters.webAppName”,第 1 行,位置 861。 "
在 main.tf 第 134 行,在资源“azurerm_resource_group_template_deployment”“webapi_virtual_directory”中:134:资源“azurerm_resource_group_template_deployment”“webapi_virtual_directory”{
解决方案
我没有使用该parameters_content
属性,而是添加defaultValue
了template_content
这样的内容:
resource "azurerm_resource_group_template_deployment" "webapi_virtual_directory" {
name = "webapi_virtual_directory"
resource_group_name = azurerm_resource_group.frontendResourceGroup.name
deployment_mode = "Incremental"
template_content = <<TEMPLATE
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"type": "String",
"defaultValue": "${azurerm_app_service.webapi.name}"
},
"virtualApplications":{
"type": "array",
"defaultValue":[
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": false,
"virtualDirectories": null
}
]
}
},
"resources": [
{
"type": "Microsoft.Web/sites/config",
"name": "[concat(parameters('webAppName'), '/web')]",
"apiVersion": "2020-06-01",
"properties": {
"virtualApplications": "[parameters('virtualApplications')]"
}
}
]
}
TEMPLATE
depends_on = [azurerm_app_service.webapi]
}
现在我没有收到验证模板部署的错误。
推荐阅读
- javascript - 将插入符号放在 ContentEditable Div 的末尾不起作用
- swift - 如何使用 Swift 4 以编程方式获取授权以将视频文件从应用程序目录复制到照片库
- c++ - 带分隔符的 C++ 文件读取
- c# - 只能在按下向下键时获得 Combobox selectedValue
- c# - 完成远程连接 SQL 数据库的步骤(通过 WIFI)
- excel - 根据单元格值显示形状
- android - 第一次工作后,在 onActivityResult 上为 android.media.action.IMAGE_CAPTURE 的活动提供结果失败
- telegram - 如何在 api 结果中确定是否从电报群聊中删除了一条消息?
- android - Geocoder 对象的地址错误
- char - 如何在opengge progress 4gl中创建启用垂直滚动条的多行文本字段?