首页 > 解决方案 > Terraform 错误:运行 terraform 计划时条件类型不正确

问题描述

在代码 .tf 文件中:

resource "aws_vpc_peering_connection" "this_1" {
  count         = var.create_peering_1 ? 1 : 0
  peer_owner_id = var.peer_account_id_1
  peer_vpc_id   = var.vpc_peer_id_1
  vpc_id        = module.vpc.vpc_id
  auto_accept   = var.auto_accept_peering_1
}

variables.tf 中的变量:

variable "create_peering_1" {
  description = "Create peering connection, 0 to not create"
  default     = 0
}

我得到的错误:

Error: Incorrect condition type

  on peering_1.tf line 6, in resource "aws_vpc_peering_connection" "this_1":
   6:   count         = var.create_peering_1 ? 1 : 0
    |----------------
    | var.create_peering_1 is 0

The condition expression must be of type bool.

我应该怎么做才能修复这个错误?

标签: amazon-web-servicesbooleansyntax-errorterraformterraform-provider-aws

解决方案


0用作_false

variable "create_peering_1" {
  description = "Create peering connection, false to not create"
  default     = false
  type        = bool
}

推荐阅读