【发布时间】:2021-12-18 02:49:00
【问题描述】:
我有 AmazonMQ 的配置模块
module "amazonmq_cluster" {
source = "git::https://github.com/cloudposse/terraform-aws-mq-broker.git?ref=0.15.0"
namespace = module.amazonmq_cluster_label.namespace
stage = module.amazonmq_cluster_label.stage
name = module.amazonmq_cluster_label.id
apply_immediately = true
auto_minor_version_upgrade = false
deployment_mode = var.cluster_deployment_mode[local.stage]
engine_type = var.cluster_engine_type[local.stage]
engine_version = var.cluster_engine_version[local.stage]
host_instance_type = var.cluster_host_instance_type[local.stage]
publicly_accessible = false
general_log_enabled = true
audit_log_enabled = false
encryption_enabled = true
use_aws_owned_key = true
vpc_id = module.vpc.vpc_id
subnet_ids = var.cluster_deployment_mode[local.stage] != "ACTIVE_STANDBY_MULTI_AZ" ? module.vpc.private_subnet_ids[0] : module.vpc.private_subnet_ids
security_groups = [module.sg.groups]
}
我需要通过字符串的变量映射有条件地描述子网ID。为 terraform 工作空间设置了字符串映射。但是当我尝试创建模块 terraform 时,会出现条件结果类型不一致的错误。
Error: Inconsistent conditional result types
on amazonmq.tf line 31, in module "amazonmq_cluster":
31: subnet_ids = var.cluster_deployment_mode[local.stage] != "ACTIVE_STANDBY_MULTI_AZ" ? module.vpc.private_subnet_ids[0] : module.vpc.private_subnet_ids
|----------------
| local.stage is "staging"
| module.vpc.private_subnet_ids is tuple with 2 elements
| module.vpc.private_subnet_ids[0] is "XXX"
| var.cluster_deployment_mode is map of string with 3 elements
如何正确设置此条件?如果 !=ACTIVE_STANDBY_MULTI_AZ 传递一个 VPC ID,否则从输出传递所有。
【问题讨论】:
标签: terraform