如何获取弹性负载均衡器 dns 名称?

Dan*_*Dan 5 terraform

我通过 terraform 创建了一个弹性豆茎环境。我想添加一个指向负载均衡器 dns 的 route53 记录,但我不知道如何从 EB 环境的输出中获取完整的 url。

aws_elastic_beanstalk_environment.xxx.load_balancers 属性包含名称但不包含FQDN。

iqu*_*ard 5

一旦你像这样创建了两个 beanstalk 资源

resource "aws_elastic_beanstalk_application" "eb_app" {
    name = "eb_app"
    description = "some description"
}

resource "aws_elastic_beanstalk_environment" "eb_env" {
    name = "eb_env"
    application = "${aws_elastic_beanstalk_application.eb_app.name}"
    solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4"
    setting {
        namespace = "aws:ec2:vpc"
        name      = "VPCId"
        value     = "something"
    }

    setting {
        namespace = "aws:ec2:vpc"
        name      = "Subnets"
        value     = "somethingelse"
    }
}
Run Code Online (Sandbox Code Playgroud)

此处包含的文档指定您可以使用“cname”来输出环境的完全限定 DNS 名称

要做到这一点,你会写一些像

output "cname" {
  value = "${aws_elastic_beanstalk_environment.eb_env.cname}"
}
Run Code Online (Sandbox Code Playgroud)

然后,在调用模块的同一目录中,您可以

cname_to_pass_to_route53 = "${module.some_eb_module.cname}"
Run Code Online (Sandbox Code Playgroud)

如果 cname 不是您需要的 url 的确切版本,您可以在传入时附加或预先添加变量名称。不过它确实说的是完全限定的 DNS 名称,所以我认为您不需要这样做.

cname_to_pass_to_route53 = "maybeHere://${module.some_eb_module.cname}/orOverHere"
Run Code Online (Sandbox Code Playgroud)