You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform导入aws_appautoscaling_policy因PolicyName含/报错求助

解决Terraform导入aws_appautoscaling_policy时因资源ID含斜杠导致的解析错误

问题原因

Terraform AWS Provider对aws_appautoscaling_policy的默认导入ID格式使用/作为四个组件(namespace/resource_id/scalable_dimension/policy_name)的分隔符,但你的:

  • resource_id:service/sandbox/myservice 本身包含/
  • policy_name:ECSServiceAverageCPUUtilization:service/sandbox/myservice 也包含/

这导致Terraform错误拆分字段,将sandbox识别为scalable_dimension的值,触发了AWS API的枚举值验证错误(scalable_dimension必须是指定的枚举集合之一)。

解决方案

使用逗号分隔组件的替代格式构造导入ID,该格式不会将字段内的/误判为分隔符。

正确的导入命令

terraform import aws_appautoscaling_policy.ecs_targettrackingcpu "ecs,service/sandbox/myservice,ecs:service:DesiredCount,ECSServiceAverageCPUUtilization:service/sandbox/myservice"

注意事项

  • 务必将整个ID用引号包裹(Linux/macOS用单引号或双引号,Windows命令行用双引号),避免Shell解析逗号或斜杠时出现异常。
  • 此格式是Terraform AWS Provider官方支持的导入格式,适用于任何组件包含分隔符的场景。

内容的提问来源于stack exchange,提问作者Dutn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 21:30:53