Terraform 复制,但(云初始化)无法在 Bitnami EC2 实例上运行user_data脚本



我正在尝试让Terraform在部署我的Bitnami EC2实例(AMI:ami-0f185ef928bf37528(后运行我的bash脚本。我可以在/var/lib/cloud/instance/scripts/part-001找到该文件,但它没有运行。

我想要的脚本有点复杂,但即使这样也没有运行:

#!/bin/sh
set -x
echo "Hello World.  The time is now $(date -R)!" | tee /root/output.txt
mkdir /opt/bitnami/projects
exit

main.tf包含

resource "aws_instance" "app_server" {
ami             = "ami-0f185ef928bf37528"
instance_type   = "t2.micro"
key_name        = "app_server"
security_groups = [aws_security_group.ec2_sg.name]
user_data       = file("init.sh")
}

我在/var/log/cloud-init-output.log/var/log/cloud-init.log中没有看到任何明显的问题或指标

我试图复制您的问题,但您的代码运行良好:

___ _ _                   _
| _ |_) |_ _ _  __ _ _ __ (_)
| _  |  _| ' / _` | '  | |
|___/_|__|_|_|__,_|_|_|_|_|

*** Welcome to the Node.js packaged by Bitnami 17.8.0-2                 ***
*** Documentation:  https://docs.bitnami.com/aws/infrastructure/nodejs/ ***
***                 https://docs.bitnami.com/aws/                       ***
*** Bitnami Forums: https://community.bitnami.com/                      ***
bitnami@ip-172-31-37-75:~$ sudo su -
root@ip-172-31-37-75:~# ls
output.txt
root@ip-172-31-37-75:~# cat output.txt 
Hello World.  The time is now Sat, 02 Apr 2022 22:53:55 +0000!
root@ip-172-31-37-75:~# cd /opt/bitnami/
apache/       bncert/       common/       gonit/        node/         python/       scripts/      var/          
apache2/      bndiagnostic/ git/          nami/         projects/     redis/        stats/        
root@ip-172-31-37-75:~# cd /opt/bitnami/p
projects/ python/   
root@ip-172-31-37-75:~# cd /opt/bitnami/p
projects/ python/   
root@ip-172-31-37-75:~# cd /opt/bitnami/projects/

因此,您使用的真实代码可能与问题中的代码不同。

最新更新