首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从terraform中的变量设置aws_autoscaling_policy中的step_adjustment

从terraform中的变量设置aws_autoscaling_policy中的step_adjustment
EN

Stack Overflow用户
提问于 2020-04-17 21:26:12
回答 1查看 361关注 0票数 0

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

当前设置:

代码语言:javascript
复制
  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作为变量提供给我的模块。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-18 01:17:27

所以你可以这样做:

代码语言:javascript
复制
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
}]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61272777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档