首页 > 解决方案 > 计数=真。适用于 terraform 11 但不适用于 terrafom 12

问题描述

我正在升级到 terraform 12 并面临一些问题。我们有一个自动缩放模块(非根),它调用中央存储库(根)中的另一个模块。所以这个模块;

     module "cef_fleet" {
           source  = "git::ssh://git@github.com/asg-repo.git?ref=terraform12"
           instance_type                            = var.instance_type
           ami                                      = var.ami
           etc ...

调用存储库“asg-repo”,在这里一些资源具有计数功能,例如;

resource "aws_autoscaling_schedule" "schedule_stop" {
    count = var.create_resource * var.auto_stop

中央存储库中的这两个变量都设置为“真”。这适用于 terraform 11,但是当我升级到 12 时,我现在得到了错误;

    var.create_resource is true
      Unsuitable value for left operand: number required.

解决这个问题的方法是简单地用 1 替换真实值吗?或者应该是类似的东西;

count = signum(count = var.create_resource * var.auto_start) - where both are also 1?

标签: amazon-web-servicesterraform

解决方案


使用三元运算符:

count = var.create_resource && var.auto_start ? 1 : 0

推荐阅读