Skip to content

Latest commit

 

History

History

Terraform_intro_cheatsheet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Introduction to Terraform

What is Terraform? 🛠️

Terraform is an open-source Infrastructure as Code (IaC) tool by HashiCorp, enabling you to define and provision infrastructure using declarative configuration files.

When is Terraform Used? 🤔

Terraform is used:

  • To automate the provisioning and management of infrastructure.
  • For creating and updating infrastructure components in a repeatable and scalable manner.
  • To enforce consistency and reliability across deployments.

Real World Application of Terraform 🌐

In real-world scenarios, Terraform is utilized for:

  • Cloud Provisioning: Automating the creation of virtual machines, networks, and storage in AWS, Azure, Google Cloud, etc.
  • Multi-Cloud Deployment: Managing infrastructure across multiple cloud providers with consistent configurations.
  • DevOps Automation: Integrating with CI/CD pipelines to automate infrastructure deployment and updates.

Getting Started 🚀

Installation

  1. Download Terraform:

  2. Install Terraform:

    • Linux/macOS:

      • Extract the downloaded ZIP archive:
        unzip terraform*.zip
      • Move the terraform binary to a directory included in your system's PATH (e.g., /usr/local/bin/):
        sudo mv terraform /usr/local/bin/
    • Windows:

      • Extract the downloaded ZIP archive.
      • Move the terraform.exe binary to a directory included in your system's PATH (e.g., C:\Windows\System32\).
  3. Verify Installation: Open a new terminal/command prompt and check that Terraform is properly installed:

    terraform --version
    

Initializing a Terraform Project

  1. Create a Working Directory:

    mkdir my-terraform-project
    cd my-terraform-project
  2. Initialize Terraform:

    terraform init

Terraform Configuration (HCL) 📄

Example: Provisioning AWS EC2 Instance

# main.tf

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

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
  tags = {
    Name = "ExampleInstance"
  }
}

Terraform Commands Cheatsheet

Initializing Terraform

terraform init

Planning Infrastructure Changes

terraform plan

Applying Changes

terraform apply

Destroying Resources

terraform destroy

Best Practices

Use Version Control: Store Terraform configurations in version control systems (e.g., Git) for collaboration and change tracking. Modularization: Organize Terraform code into reusable modules for better management and scalability.

Additional Resources

Explore more about Terraform and Infrastructure as Code concepts at Terraform Documentation.