Terraform配置Azure Spring App自动扩缩容:如何获取正确资源URI?
解决Azure Spring Apps自动扩缩容Terraform配置错误
错误原因
你当前配置的target_resource_id使用了应用的服务主体ID(app_identities[0].principal_id),而Azure Monitor自动扩缩配置要求传入资源的完整URI格式ID,不是单纯的GUID,因此触发解析错误。
正确获取Azure Spring App资源URI的方法
1. 通过Terraform模块直接引用(推荐)
如果你的module.spring_apps_app_carrier_events是基于azurerm_spring_app资源封装的模块,只需引用该资源的id属性(这就是资源的完整URI)。
修正后的Terraform代码示例:
resource "azurerm_monitor_autoscale_setting" "spring_apps_app_carrier_events" { name = "default_auto_scale" enabled = true resource_group_name = module.rg.resource_group_name location = module.rg.resource_group_location # 替换为应用的资源ID,而非principal_id target_resource_id = module.spring_apps_app_carrier_events.id profile { name = "defaultProfile" capacity { default = 1 minimum = 1 maximum = 2 } } }
注意:如果你的模块没有对外输出id,需要在模块的outputs.tf中添加:
output "id" { type = string description = "The ID of the Azure Spring App" value = azurerm_spring_app.your_app_name.id }
2. 手动获取资源URI
如果需要手动确认资源ID,可通过两种方式:
- Azure CLI命令:
az spring app show --name <你的应用名称> --resource-group <资源组名称> --service <Spring Apps服务名称> --query id -o tsv - Azure门户:
进入目标Spring Apps服务的应用详情页,在「概述」面板中找到「资源ID」字段,复制其完整值即可。
内容的提问来源于stack exchange,提问作者Sanchelz
相关产品推荐
相关产品推荐

