Terraform:If-else不使用alb_lb_侦听器资源
我正在尝试为if-else条件创建带有地形插值的资源aws_lb_侦听器。但它告诉我基础设施没有变化。但是,它还没有在基础设施上创建https侦听器。以下代码中是否缺少任何内容 alb.tfTerraform:If-else不使用alb_lb_侦听器资源,terraform,Terraform,我正在尝试为if-else条件创建带有地形插值的资源aws_lb_侦听器。但它告诉我基础设施没有变化。但是,它还没有在基础设施上创建https侦听器。以下代码中是否缺少任何内容 alb.tf resource "aws_lb_listener" "https" { count = "${var.https_listener_enable == true ? 1 : 0}" load_balancer_arn = "${aws_lb.main.arn}" port
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"
}
}
}
变量.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}"
}
将count=${var.https\u listener\u enable==true?1:0}替换为count=${var.https\u listener\u enable==true?1:0}。如果您已经在.tfvars文件中定义了变量https\u listener\u enable值或从命令行传递,则此操作应该有效。将计数值更改为此${var.https\u listener\u enable?1:0}对我有效 您的三元组要求将https_listener_enable设置为true,因此您可能没有在任何地方这样做。至少在显示的任何代码中都没有这样做。在main.tf中,我将该变量作为true传递。我尚未测试此解决方案。但这似乎应该行得通。