Saturday, September 28, 2024

Cloud: Terraform, Cloudformation (Home Lab)

 Create an EC2 instance by terraform code


-Create an ubuntu ec2 machine wherein I will install terraform to perform the tasks in the cloud

- Download terraform









sudo su


wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install terraform















Lets now create  a directory inside the machine where we will write terraform scripts


# mkdir terraform 

# cd terraform


Generate an access key and secret key





Documentation : https://registry.terraform.io/providers/hashicorp/aws/latest/docs


nano connection.tf 

(remember that all the terraform scripts ends with .tf) 









Press x > y > enter

now, write the code to create ec2 instance via terraform
























resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "HelloWorld"
  }


















##now we have written two terraform files (tf). Execute them.


terraform init














terraform apply --auto-approve




























Resources created






Cloudformation

Create a cloudformation stack








Fork a GitHub repository














Back to cloudformation

sync from Git













specify stack details

-Link a Git repository
-Create a connection
-Connect to GitHub > install a new app


















































Go back to cloudfrmation page
Create Role





























Submit


























The machine is created via terraform cloud formation















No comments:

Post a Comment

Waviz Project: Building a Visualizer Without External Libraries

  Back in the day , music visualizers were magic. Whether it was the old Windows Media Player or Winamp, watching sound morph into motion fe...