通过Terraform配置Auto Scaling实例刷新自动回滚遇错求助
问题解决:Auto Scaling Group实例刷新自动回滚配置错误
错误原因
AWS要求开启自动回滚时必须指定期望配置(DesiredConfiguration),因为回滚操作需要明确知道要恢复到哪个配置版本。你的Terraform配置里只开启了自动回滚,但没有定义期望配置,所以触发了ValidationError。
正确配置方式
在instance_refresh块内添加desired_configuration,指定要使用的启动模板信息,这样AWS就有了回滚的目标配置。修改后的main.tf如下:
resource "aws_autoscaling_group" "example" { availability_zones = ["us-west-2a"] desired_capacity = 1 max_size = 2 min_size = 1 launch_template { id = aws_launch_template.example.id version = aws_launch_template.example.latest_version } tag { key = "Key" value = "Value" propagate_at_launch = true } instance_refresh { strategy = "Rolling" # 添加期望配置,指定回滚时的目标启动模板版本 desired_configuration { launch_template { id = aws_launch_template.example.id version = aws_launch_template.example.latest_version } } preferences { min_healthy_percentage = 50 auto_rollback = true } } } resource "aws_launch_template" "example" { image_id = "ami-*********" instance_type = "i3.large" }
关于Desired Configuration的说明
这个功能并没有在Terraform AWS Provider中缺失,只是它是instance_refresh块的子配置,而非ASG的顶层参数。当你通过控制台或CLI启用自动回滚时,控制台/CLI会自动填充当前的实例配置作为期望配置,但Terraform需要显式声明该配置。
内容的提问来源于stack exchange,提问作者wasay
相关产品推荐
相关产品推荐

