Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Terraform Tutorials: Basic Workflow Getting Started Guide

  • init – Init. Initialize the (local) Terraform environment. Usually executed only once per session.
  • plan – Plan. Compare the Terraform state with the as-is state in the cloud, build and display an execution plan. This does not change change the deployment (read-only).
  • apply – Apply the plan from the plan phase. This potentially changes the deployment (read and write).
  • destroy – Destroy all resources that are governed by this specific terraform environment.

Terraform workflow

Step – 1 – Install terraform

Step – 2 – Decide a providers name which you want to work with?

  • Create one directory under your workspace
  • Inside directory, create one file called “providers.tf”
  • Content of the providers.tf are as follow
  • run init command to download aws providers. $ terraform init

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "4.61.0"
    }
	github = {
      source = "integrations/github"
      version = "5.18.3"
    }
  }
}

provider "aws" {
  region     = "us-east-1"
  access_key = ""
  secret_key = ""
}

provider "github" {
  # Configuration options
}

Step – 3 – Create 1 AWS ec2 instance using Terraform

  • Create aws.tf file in the same directory where providers.tf is located
  • Put the following content. Modify AMI id as per your region

resource "aws_instance" "web" {
  ami           = "ami-007855ac798b5175e"
  instance_type = "t2.micro"

  tags = {
    Name = "HelloWorld-DevOpsSchool"
  }
}

Step – 4 – PLAN (DRY RUN) using terraform plan

  • RUN a Dry run command $ terraform plan

Step – 5 – APPLY (Create a Resoureces) using terraform apply

  • Run apply command to create resources $ terraform apply

Step – 6 – Verify a AWS ec2 instance at AWS

Step – 7 – APPLY (Update a Resoureces) using terraform apply

  • Update tag info in your aws.tf code
  • Run $ terraform apply

resource "aws_instance" "web" {
  ami           = "ami-007855ac798b5175e"
  instance_type = "t2.micro"

  tags = {
    Name = "HelloWorld-Terraform"
  }
}

Step – 8 – Terraform show

Check Statefile in the same directory

Step – 9 – Terraform destroy

Check AWS Account if AWS ec2-instance is destroyed or not

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.