Last active
March 29, 2020 05:01
-
-
Save pavan168/8126eef4d7a69e5ddfa0b545e0e2de7a to your computer and use it in GitHub Desktop.
A script file with Terraform commands and a set of ssh/scp commands to remotely execute in new ec2 instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
projectfolder=$1 | |
if [ -z "$projectfolder" ]; then | |
exit 1 | |
fi | |
./terraform apply -auto-approve | |
ssh -i ~/.ssh/<aws-ssh-pem-file> -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@<new-instance-private-ip> "mkdir -p /home/ubuntu/\"$projectfolder\"" | |
scp -i ~/.ssh/<aws-ssh-pem-file> -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r /var/www/$projectfolder ubuntu@<new-instance-private-ip>:/home/ubuntu | |
scp -i ~/.ssh/<aws-ssh-pem-file> -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r /var/www/build-server/setup.sh ubuntu@<new-instance-private-ip>:/home/ubuntu/ | |
ssh -i ~/.ssh/<aws-ssh-pem-file> -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@<new-instance-private-ip> "/home/ubuntu/setup.sh \"$projectfolder\"" | |
scp -i ~/.ssh/<aws-ssh-pem-file> -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@<new-instance-private-ip>:/home/ubuntu/$projectfolder.tar /var/www/tmp | |
./terraform destroy -auto-approve |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment