ryaninvents / terraform-node-pm2

Terraform configuration that keeps a Node.js app running.
3 stars 1 forks source link
aws aws-ec2 nodejs pm2 terraform

terraform-node-pm2

Make sure your SSH key is saved as ~/.ssh/$IAM_KEY_NAME.pem and has the correct permissions (400).

Deploying

Copy config/terraform/backend/sample.tfvars to config/terraform/backend.tfvars and edit before running these commands.

cd config/terraform
terraform init -backend-config=backend.tfvars
echo "ssh-key = \"$IAM_KEY_NAME\"" > terraform.tfvars
terraform apply

Verifying

Still in the config/terraform directory, run terraform output http-service. This will output a web address. Visit that address and you should see the "Hello world" message.

Then, SSH into your instance (username centos, IP from the web address, use the same key that's been added) and reboot it. It'll take a few minutes, but it should restart the HTTP server once the instance is back online.