从地形中的变量在aws_autoscaling_policy中设置step_adjustment



我正在设置一个模块来配置地形中ASG的自动缩放。理想情况下,我想将一个映射列表传递给我的模块,并让它在其中循环,为列表中的每个映射添加一个step_adjustment到策略中,但这似乎不起作用。

当前设置:

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
}

我只想在我的模块中提供三个step_adjustments作为变量。

因此,您可以按照以下方式进行操作:

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
}]

相关内容

  • 没有找到相关文章