我是Terraform的新手,正在使用AWS学习template_file。我刚刚使用template_file构建了如下代码,但是在启动EC2实例后,我发现未执行template_file中的脚本-未安装tcpdump和httpd,并且未进行主机名和名称服务器配置。有人可以指出我在这里做错了吗?
模板文件:user_data.sh.tpl:
#!/usr/bin/bash
sudo yum install -y tcpdump
sudo yum update -y
sudo yum install -y httpd24 php56 php56-mysqlnd
sudo service httpd start
sudo hostname www.xyz.com
echo "${nameserver}" >> /etc/resolv.conf
application.tf文件中模块目录下的资源和数据:
data "template_file" "user_data" {
template = "${file("/Users/user1/Documents/Terraform/Code/started/modules/application/user_data.sh.tpl")}"
vars {
nameserver = "${var.external_nameserver}"
}
}
resource "aws_instance" "app-server" {
ami = "ami-b2b55cd5"
key_name = "privatekey"
instance_type = "${lookup(var.instance_type, var.environment)}"
subnet_id = "${var.subnet_id}"
vpc_security_group_ids = ["${distinct(concat(var.extra_sgs, aws_security_group.allow_http.*.id))}"]
user_data = "${data.template_file.user_data.rendered}"
tags {
Name = "${var.name}"
}
}