Apache configration via terraform using provisioner
in every instance use key pair
craete one file index.html
write anything
here we haven't used security group it will use the default but make sure
you will go to inbound rules do it anywhere.
now check public IP it will show our index message
if we want to go inside instance
ssh -I developer ec2-user@publickey
====================================================
VI AWS.TF
provider "aws" {
region = "us-east-1"
access_key = "AQ"
secret_key = "Kaurid"
}
resource "aws_key_pair" "developer" {
key_name = "developer"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhI176Z0ylP2WdWAbI2hrFf5oEHlnZ0zcSm85SGysuwx/lMl0F+muOcke0wS90f5NU+bUAKNL2hWFozx/HxEtaquM77go+eWY9lg1E7q9Ls8nzVv1pddNgtS7Cihgzd7UaXDq0ayhOUBO1y6nMZYobFNy4E63vBuCYyhHwPAT7mheZm2GphKYrkd1Qt4qvcZcJ4CBmjCwQ3VBdwOhk8ZdKc7BdpLNPENNCLkzswhNcpRInRADMAM1ZgPikKt8wEaeMX/Hg2Mrk0MS49mYFnPxc1G5DuSsW7P9L+7IzbGI2pl4RSLM8/IlFef/i1HWgdaDCJpejgxLX4Hux9EUyqtd1 root@ip-172-31-46-6.ap-south-1.compute.internal"
}
resource "aws_instance" "web" {
ami = "ami-02e136e904f3da870"
instance_type = "t3.nano"
key_name = "developer"
tags = {
Name = "prod"
}
provisioner "file" {
source = "/home/ec2-user/projectB/index.html"
destination = "/tmp/index.html"
}
provisioner "remote-exec" {
inline = [
"sudo yum install httpd -y",
"systemctl start httpd",
"systemctl enable httpd",
"sudo cp /tmp/index.html /var/www/html",
"sudo systemctl restart httpd"
]
}
connection {
host = self.public_ip
user = "ec2-user"
type = "ssh"
private_key = file("./developer") { learn how to use private key because its on current path thats y we use file
}
}
Comments
Post a Comment