【问题标题】:Add private IPs to a file - Terraform将私有 IP 添加到文件 - Terraform
【发布时间】:2018-05-12 11:03:31
【问题描述】:

我希望能够转储 Terraform 创建的 EC2 服务器的私有 IP。

resource "aws_instance" "hello"  {
  count = "3"
  tags {
      Name = "${var.name}"

  }

  ami = "${var.AWS_AMI}"
  instance_type = "${var.aws_instance_type}"
  subnet_id = "${var.aws_subnet_id}"

如何将为此实例创建的私有 IP 作为逗号分隔列表转储到文件中,以便另一个 bash 脚本可以从那里读取它?

【问题讨论】:

    标签: terraform


    【解决方案1】:

    一种选择是在 terraform 文件中指定一个输出变量:

    例子:

    output hello_ec2_private_ip {
      value = "${join(",",aws_instance.hello.*.private_ip)}"
    }
    

    然后使用terraform output 命令列出输出 并将其通过管道传输到文件

    例子:

    terraform output  hello_ec2_private_ip > private_hello.txt
    

    【讨论】:

      猜你喜欢
      • 2018-08-11
      • 1970-01-01
      • 2021-10-15
      • 2020-08-06
      • 2021-05-02
      • 2021-06-21
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      相关资源
      最近更新 更多