Amazon ec2 从terraform中的变量在aws自动校准策略中设置步骤调整
我正在设置一个模块,以便在terraform中的ASG中配置自动缩放。理想情况下,我希望将一个映射列表传递给我的模块,并让它循环通过它们,为策略列表中的每个映射添加步骤调整,但是这似乎不起作用 当前设置:Amazon ec2 从terraform中的变量在aws自动校准策略中设置步骤调整,amazon-ec2,terraform,terraform-provider-aws,Amazon Ec2,Terraform,Terraform Provider Aws,我正在设置一个模块,以便在terraform中的ASG中配置自动缩放。理想情况下,我希望将一个映射列表传递给我的模块,并让它循环通过它们,为策略列表中的每个映射添加步骤调整,但是这似乎不起作用 当前设置: name = "Example Auto-Scale Up Policy" policy_type = "StepScaling" autoscaling_group_name = "${aws_autoscaling_group.example_asg.name}" adju
name = "Example Auto-Scale Up Policy"
policy_type = "StepScaling"
autoscaling_group_name = "${aws_autoscaling_group.example_asg.name}"
adjustment_type = "PercentChangeInCapacity"
estimated_instance_warmup = 300
step_adjustment {
scaling_adjustment = 20
metric_interval_lower_bound = 0
metric_interval_upper_bound = 5
}
step_adjustment {
scaling_adjustment = 25
metric_interval_lower_bound = 5
metric_interval_upper_bound = 15
}
step_adjustment {
scaling_adjustment = 50
metric_interval_lower_bound = 15
}
min_adjustment_magnitude = 4
}
我只想将三个
步骤调整
作为变量提供到我的模块中。因此,您可以按如下方式执行:
variable "step_adjustments" {
type = list(object({ metric_interval_lower_bound = string, metric_interval_upper_bound = string, scaling_adjustment = string }))
default = []
}
# inside your resource
resource "aws_appautoscaling_policy" "scale_up" {
name = "Example Auto-Scale Up Policy"
policy_type = "StepScaling"
autoscaling_group_name = "${aws_autoscaling_group.example_asg.name}"
adjustment_type = "PercentChangeInCapacity"
estimated_instance_warmup = 300
dynamic "step_adjustment" {
for_each = var.step_adjustments
content {
metric_interval_lower_bound = lookup(step_adjustment.value, "metric_interval_lower_bound")
metric_interval_upper_bound = lookup(step_adjustment.value, "metric_interval_upper_bound")
scaling_adjustment = lookup(step_adjustment.value, "scaling_adjustment")
}
}
}
# example input into your module
step_adjustments = [
{
scaling_adjustment = 2
metric_interval_lower_bound = 0
metric_interval_upper_bound = 5
},
{
scaling_adjustment = 1
metric_interval_lower_bound = 5
metric_interval_upper_bound = "" # indicates infinity
}]
这是一个很好的答案,清晰而简洁。非常感谢你,这真是太好了!