Terraform script for ubuntu ec2 and following

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

ubuntu ec2-instance and copy a ansible playbook, install ansible and run it:::.

Step 1 – Create ec2-instance with key and group

Step 2 – COpy playbook using file prov*

Step 3 – Install Ansible using remote prov*

Step 4 – RUn Ansinle playbook command using remote prv*

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}
provider "aws" {
  region = "us-west-2"

  access_key = "XXXXXXXXXXXXX"
  secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
resource "aws_instance" "manideep" {
  ami           = "ami-03d5c68bab01f3496"
  instance_type = "t2.micro"
  key_name = "manideep"

    tags = {
    Name = "manideep"
  }
connection {
	
      type     = "ssh"
      user     = "ubuntu"
      private_key = file("manideep.pem")
      host = self.public_ip
}
 provisioner "file" {
    source      = "C:\Users\ansible\playbook.yaml"
    destination = "/tmp/"
  } 
provisioner "remote-exec" {
    inline = [
	  "sudo apt-get update",
          "sudo apt-get install ansible -y",
	  "sudo systemctl start ansible",
    ]
  }
provisioner "remote-exec" {
              inline = [
ansible-playbook -i inventory playbook.yaml -u root -k,
] 
}


}