【发布时间】:2020-10-20 17:59:39
【问题描述】:
我正在为 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" {
【问题讨论】:
标签: terraform terraform-provider-azure