terraform无法与tpl脚本的远程exec一起使用

时间:2018-09-23 09:24:35

标签: terraform

我有一个简单的AWS ec2实例,如下所示

resource "aws_instance" "App01" {
    ##ami = "ami-846144f8"
    ami = "${data.aws_ami.aws_linux.id}"
    instance_type = "t1.micro"
    subnet_id = "${aws_subnet.public_1a.id}"
    associate_public_ip_address = true
    vpc_security_group_ids = ["${aws_security_group.web_server.id}","${aws_security_group.allow_ssh.id}"]
    key_name = "key"
    provisioner "remote-exec"{
        inline = ["${template_file.bootstrap.rendered}"]
    }
    tags {
        Name = "App01"
    }

}

data "aws_ami" "aws_linux" {
  most_recent = true
  filter {
    name   = "name"
    values = ["amzn2-ami-*-x86_64-gp2"]
  }
  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }
  filter {
    name   = "owner-alias"
    values = ["amazon"]
  }
}


resource "template_file" "bootstrap" {
  template = "${file("bootstrap.tpl")}"
    vars {
      app01ip = "${aws_instance.App01.private_ip}"
      app02ip = "${aws_instance.App02.private_ip}"
      DBandMQip = "${aws_instance.DBandMQ.private_ip}"
    }
}

这是我的tbl脚本

#!/bin/bash -xe
# install necessary items like ansible and
sudo yum-config-manager --enable epel
sudo amazon-linux-extras install ansible2


echo "${app01ip}  App01" > /etc/hosts
echo "${app02ip}  App02" > /etc/hosts
echo "${DBandMQip}  DBandMQ" > /etc/hosts

我不断收到

Error: Error asking for user input: 1 error(s) occurred:

* Cycle: aws_instance.App01, template_file.bootstrap

我相信它来自remote-exec的资源部分,但是我不确定出什么问题了,因为它对我来说很好。有人知道我在做什么错吗?

0 个答案:

没有答案