我正在尝试为if-else条件使用地形插值创建资源aws_lb_listener
。但是它说我的基础架构没有变化。但是,它尚未在基础结构上创建https侦听器。以下代码中缺少任何内容吗?
alb.tf
resource "aws_lb_listener" "https" {
count = "${var.https_listener_enable == true ? 1 : 0}"
load_balancer_arn = "${aws_lb.main.arn}"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "Nothing is here. Go Away."
status_code = "200"
}
}
}
variables.tf
variable "https_listener_enable" {}
main.tf
module "public_alb" {
source = "../modules/alb"
load_balancer_name = "example-production"
https_listener_enable = true
security_groups = ["${module.security_group.sg_http}"]
load_balancer_is_internal = false
idle_timeout = 60
enable_deletion_protection = false
enable_http2 = true
tags = "${map("Environment", "production",
"Name", "example-production",)}"
subnets = "${module.vpc.public_subnets}"
vpc_id = "${module.vpc.vpc_id}"
}
答案 0 :(得分:1)
用count =“ $ {var.https_listener_enable ==” true“?1:0}”替换count =“ $ {var.https_listener_enable == true?1:0}”。如果您已经在.tfvars文件中定义了变量“ https_listener_enable”值或从命令行进行了传递,则此方法应该有效。
答案 1 :(得分:0)
将计数值更改为此"${var.https_listener_enable ? 1 : 0}"
对我有用。