terraform用户数据虽然呈现不起作用

时间:2018-05-16 11:19:39

标签: amazon-web-services terraform user-data

我正在创建一台ec2机器,当它启动时,我想在其中安装docker并将自己添加到牧场服务器

同样的terraform脚本是

provider "aws" {
    region = "ap-south-1"
}

resource "aws_instance" "rancherHost" {
    tags {
        name = "tf-rancher-host-rmf44"
    }

    ami                    = "ami-0189d76e"
    instance_type          = "t2.micro"
    vpc_security_group_ids = ["${aws_security_group.port500and4500.id}"]
    user_data              = "${data.template_file.user-data.rendered}"
}

data template_file "user-data"
{
    template = "${file("script.sh")}"
}

resource "aws_security_group" "port500and4500" {
    ingress {
        from_port   = 500
        protocol    = "udp"
        to_port     = 500
        cidr_blocks = ["0.0.0.0/0"]
    }

    ingress {
        from_port   = 4500
        protocol    = "udp"
        to_port     = 4500
        cidr_blocks = ["0.0.0.0/0"]
    }
    ingress {
        from_port = 443
        protocol = "tcp"
        to_port = 443
        cidr_blocks = ["0.0.0.0/0"]
    }
    ingress {
        from_port = 80
        protocol = "tcp"
        to_port = 80
        cidr_blocks = ["0.0.0.0/0"]
    }
}
output "instanceDetail" {
    value = "${aws_instance.rancherHost.public_ip}"
}

我编写的脚本位于同一目录中,内容为:

#!/bin/bash
echo "fail fast learn fast"
echo "this is second line"
apt-get update -y || echo $?
apt-get install -y docker
apt-get install -y docker.io
echo "echo failing now maybe"
service docker start

当我运行它时,机器也被创建,用户数据也可见,我也检查了日志,只有前两个回声存在,没有别的。我在这里做错了,手动创建使用相同的用户数据工作,主机被添加到牧场服务器。 os是ubuntu 16.04

0 个答案:

没有答案