Terraform Provider Block
# Terraform Block
terraform {
required_version = "~> 1.0.11"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
#Provider Block
provider "aws" {
region = "us-east-1"
}
Terraform Resource Block
resource "aws_instance" "myec2vm" { ami = "ami-04902260ca3d33422" instance_type = "t2.micro" key_name = "terraform" provisioner "remote-exec" { inline = [ "sudo yum update -y", "sudo yum install -y httpd", "sudo systemctl enable httpd", "sudo service httpd start", "sudo echo 'Welcome to Infra Xpertzz - Apache-install
' | sudo tee /var/www/html/index.html", "sudo mkdir /var/www/html/webserver1", "sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/webserver1/metadata.html", ] connection { type = "ssh" user = "ec2-user" private_key = file("./terraform.pem") host = self.public_ip } } tags = { "Name" = "EC Demo" } }