I'm using an inline deployment for azurerm_resource_group_template_deployment and I'm passing a parameter that uses the name of another terraform resource.
Code:
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]
}
When I run the terraform apply command, I get the error:
Error: validating Template Deployment "webapi_virtual_directory" (Resource Group "frontendapps-rg"): requesting validating: resources.DeploymentsClient#Validate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidRequestContent" Message="The request content was invalid and could not be deserialized: 'Error converting value "ci-webapi" to type 'Azure.ResourceManager.Deployments.Templates.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.webAppName', line 1, position 861.'."
on main.tf line 134, in resource "azurerm_resource_group_template_deployment" "webapi_virtual_directory": 134: resource "azurerm_resource_group_template_deployment" "webapi_virtual_directory" {