【问题标题】:Cannot add more than one ec2 instances to AWS ELB using terraform无法使用 terraform 向 AWS ELB 添加多个 ec2 实例
【发布时间】:2018-04-02 15:35:23
【问题描述】:

我已使用 terraform 成功预置 AWS 基础设施。

在将多个实例(多个实例)附加到 AWS ELB 时,我可以使用 Autoscaling 附加实例。

resource "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" listener { } listener { } listener { } } security_groups = ["${aws_security_group.xxxx}"] subnets = ["${xxxxx}"] instances = ["${aws_instance.myinstance.id}"]

我也尝试过:

"instances = "${element(aws_instance.mqttcluster.id, count.index)}" 

在这两种情况下它都不起作用

但是在添加没有自动缩放的实例时,我只能使用 terraform 添加一个实例,我无法添加多个实例 来自同一组实例。如何解决这个问题?我没有找到任何模块。

【问题讨论】:

  • 请出示您的代码

标签: amazon-web-services terraform


【解决方案1】:

只需从实例中删除 [] 即可

instances = ["${aws_instance.myinstances.*.id}"]

【讨论】:

    【解决方案2】:

    你是如何定义你的 elb 的?它应该是这样的:

    resource "aws_elb" "my-elb" {
        ...
        instances = ["${aws_instance.myinstances.*.id}"]
        ...
    }
    

    【讨论】:

    • 资源 "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" 监听器 { } 监听器 { } 监听器 { } } security_groups = [" ${aws_security_group.xxxx}"] 子网 = ["${xxxxx}"] 实例 = ["${aws_instance.myinstance.id}"]
    • 资源 "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" 监听器 { } 监听器 { } 监听器 { } } security_groups = [" ${aws_security_group.xxxx}"] 子网 = ["${xxxxx}"] 实例 = ["${aws_instance.myinstance.id}"]
    • 我也尝试过像“instances =”${element(aws_instance.mqttcluster.id,count.index)}”一样。在这两种情况下它都没有工作。
    • 如果你有很多资源实例,这应该可以工作aws_instance.myinstances.*.id。看看答案
    • 感谢胡里奥的回复。我现在试试,让你知道
    猜你喜欢
    • 2021-11-15
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 2021-11-05
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多