ec2启动时,我试图执行一次脚本,因此在instance.tf中关注以下内容。
resource "aws_instance" "test" {
ami = "i-33434"
user_data = "${data.template_file.user-data.rendered}"
}
data "template_file" "user-data" {
template = "${file("templates/init.tpl")}"}
并在模板文件夹下创建具有以下内容的init.tpl文件:
#!/bin/bash
sudo mkdir /ecs
mkfs -t ext4 /dev/xvdt10
mkfs -t ext4 /dev/xvdt11
mkdir /ecs/folder1
mkdir /ecs/folder2
mount /dev/xvdt10 /ecs/folder1
mount /dev/xvdt11 /ecs/folder2
echo /dev/xvdt10 /ecs/folder1 ext4 defaults,nofail 0 2 >> /etc/fstab
echo /dev/xvdt11 /ecs/folder2 ext4 defaults,nofail 0 2 >> /etc/fstab