Last active
July 12, 2023 03:57
-
-
Save rohitg00/5e130470885175fb93550be6db9cb7c0 to your computer and use it in GitHub Desktop.
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
resource "null_resource" "remote1" { | |
depends_on = [ aws_instance.web, ] | |
//Executing Commands to initiate WebServer in Instance Over SSH | |
provisioner "remote-exec" { | |
connection { | |
agent = "false" | |
type = "ssh" | |
user = "ec2-user" | |
private_key = "${tls_private_key.tls_key.private_key_pem}" | |
host = "${aws_instance.web.public_ip}" | |
} | |
inline = [ | |
"sudo yum install httpd git -y", | |
"sudo systemctl start httpd", | |
"sudo systemctl enable httpd", | |
] | |
} | |
} | |
//Creating EBS Volume | |
resource "aws_ebs_volume" "web-vol" { | |
availability_zone = "${aws_instance.web.availability_zone}" | |
size = 1 | |
tags = { | |
Name = "ebs-vol" | |
} | |
} | |
//Attaching EBS Volume to a Instance | |
resource "aws_volume_attachment" "ebs_att" { | |
device_name = "/dev/sdh" | |
volume_id = "${aws_ebs_volume.web-vol.id}" | |
instance_id = "${aws_instance.web.id}" | |
force_detach = true | |
provisioner "remote-exec" { | |
connection { | |
agent = "false" | |
type = "ssh" | |
user = "ec2-user" | |
private_key = "${tls_private_key.tls_key.private_key_pem}" | |
host = "${aws_instance.web.public_ip}" | |
} | |
inline = [ | |
"sudo mkfs.ext4 /dev/xvdh", | |
"sudo mount /dev/xvdh /var/www/html/", | |
"sudo rm -rf /var/www/html/*", | |
"sudo git clone https://github.com/rohitg00/Terraform-Build-AWS.git /var/www/html/", | |
] | |
} | |
depends_on = [ | |
aws_instance.web, | |
aws_ebs_volume.web-vol | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment