Skip to content

Instantly share code, notes, and snippets.

@iamtheindian
Created June 13, 2020 13:24
Show Gist options
  • Save iamtheindian/81f2e34a992c08a27103989b1927e4a7 to your computer and use it in GitHub Desktop.
Save iamtheindian/81f2e34a992c08a27103989b1927e4a7 to your computer and use it in GitHub Desktop.
#combined use of remote and local execution
resource "null_resource" "nl1" {
depends_on = [ aws_volume_attachment.ebs_att,aws_s3_bucket.b,aws_cloudfront_distribution.s3_distribution ]
#sending local data to remote instance using scp
provisioner "local-exec" {
command = "chmod 400 /root/HybridCloud/Terraform/MyKeyPair.pem && scp -o StrictHostKeyChecking=no -r -i /root/HybridCloud/Terraform/MyKeyPair.pem /root/HybridCloud/Terraform/php ec2-user@${aws_instance.webos.public_dns}:/home/ec2-user"
}
connection {
type = "ssh"
user = "ec2-user"
private_key = data.local_file.key_file.content
host = aws_instance.webos.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo rm -fr /var/www/html/*",
"sudo mkfs.ext4 /dev/xvdd",
"sudo mount /dev/xvdd /var/www/html",
"sudo mv -f /home/ec2-user/php/* /var/www/html/"
]
}
provisioner "local-exec" {
command = "curl ${aws_instance.webos.public_ip} "
}
}
/////////////////////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment