I want to automatically run a node app by configuring its steps inside the remote-exec of my Terraform script. However, when I run "terraform apply -auto-approve" I get an "Still creating... [10m21s elapsed]" message until it crashes.
This is the script I am using:
resource "aws_instance" "server_1" {
ami = "ami-<id>"
instance_type = "t3.micro"
associate_public_ip_address = true
key_name = "server_1_kp"
iam_instance_profile = aws_iam_instance_profile.ec2_access_profile.name
root_block_device {
volume_size = 25
}
connection {
type = "ssh"
user = "centos"
private_key = file("server_1_kp.pem")
host = self.public_ip
}
provisioner "remote-exec" {
inline = [
"echo 'Installing Git'",
"sudo yum -y install git",
"sudo yum install awscli -y",
"git config --global credential.helper '!aws codecommit credential-helper $@'",
"git config --global credential.UseHttpPath true",
"git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/server-1",
"curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash",
"source ~/.bashrc",
"nvm install 16.18.1",
"cd server-1-app",
"npm install",
"npm run dev / node src/index.js ",
"echo 'node server.js > /dev/null 2>&1' > app.sh",
"nohup ./app.sh"
]
}
}
The output I get:
aws_instance.server-1: Still creating... [12m51s elapsed]
aws_instance.server-1: Still creating... [13m1s elapsed]
aws_instance.server-1: Still creating... [13m11s elapsed]
aws_instance.server-1: Still creating... [13m21s elapsed]
aws_instance.server-1: Still creating... [13m31s elapsed]
aws_instance.server-1: Still creating... [13m41s elapsed]
aws_instance.server-1: Still creating... [13m51s elapsed]
aws_instance.server-1: Still creating... [14m1s elapsed]
aws_instance.server-1: Still creating... [14m11s elapsed]
aws_instance.server-1: Still creating... [14m21s elapsed]
aws_instance.server-1: Still creating... [14m31s elapsed]
aws_instance.server-1: Still creating... [14m41s elapsed]
aws_instance.server-1: Still creating... [14m51s elapsed]
aws_instance.server-1: Still creating... [15m1s elapsed]
aws_instance.server-1: Still creating... [15m11s elapsed]
aws_instance.server-1: Still creating... [15m21s elapsed]
aws_instance.server-1: Still creating... [15m31s elapsed]
aws_instance.server-1: Still creating... [15m41s elapsed]
aws_instance.server-1: Still creating... [15m51s elapsed]
I tried to execute these commands in place of the following commands:
New options | Original value |
---|---|
npm run dev / node src/index.js | "echo 'node server.js > /dev/null 2>&1' > app.sh", "nohup ./app.sh" |
nohup node server.js > /dev/null 2>&1 & | = |