【发布时间】:2021-07-16 08:34:39
【问题描述】:
假设我有一个通过 terraform 管理的自动缩放组。而且我希望该 Auto Scaling 组能够根据我们的营业时间扩大和缩小规模。
管理 ASG 的 TF 模板:
resource "aws_autoscaling_group" "foobar" {
availability_zones = ["us-west-2a"]
name = "terraform-test-foobar5"
max_size = 1
min_size = 1
health_check_grace_period = 300
health_check_type = "ELB"
force_delete = true
termination_policies = ["OldestInstance"]
}
resource "aws_autoscaling_schedule" "foobar" {
scheduled_action_name = "foobar"
min_size = 0
max_size = 1
desired_capacity = 0
start_time = "2016-12-11T18:00:00Z"
end_time = "2016-12-12T06:00:00Z"
autoscaling_group_name = aws_autoscaling_group.foobar.name
}
正如我们在这里看到的,我必须为该操作设置一个特定的日期和时间。
我想要的是:我想在星期六晚上 9 点按当前容量的 10% 缩小,然后在星期一早上 6 点再次扩大 10%。
我怎样才能做到这一点。
非常感谢任何帮助。请告诉我如何解决这个问题。
【问题讨论】:
-
当前代码有什么问题?有什么错误吗?
-
这里是否还有更多的复杂性你没有展示出来?现在您有一个非常静态的 ASG,然后您在特定时间更改它。如果您还没有将自动扩展策略附加到 ASG 以扩展实例数量,那么您的上述代码没有任何问题(尽管我假设您在一周内有 10 个实例,然后在周末缩减到 9 个实例)。如果比这更复杂,那么您应该在问题中进行解释,并理想地显示进行该缩放所需的最少代码。
-
我创建了一个新帖子,其中包含我正在使用的详细代码以及我想要实现的目标。链接在这里。 :stackoverflow.com/questions/67212282/manage-asg-via-terraform。请参考this和帮助
标签: terraform terraform-provider-aws aws-auto-scaling