🌥️

Introduction to Terraform Basics

May 8, 2025

Lecture on Terraform

Introduction

  • Lecture on Terraform by Jayhawk.
  • Topics covered:
    • What is Terraform?
    • Terraform commands: init, plan, apply.
    • Creating the first Terraform file.
    • Installing Terraform on a system.
    • Demo:
      • Setting up a virtual machine on Google Cloud Platform using Terraform.
      • Setting up an EC2 instance on AWS using Terraform.
  • Recommended for beginners to watch the full session.

Understanding Terraform

  • Definition: Terraform is used to provision and set up infrastructure on cloud platforms like GCP and AWS.
  • Provisioning Infrastructure: Automates the setup of servers/VMs for application deployment.
  • Terraform File (.tf): Contains two main components:
    • Provider: Specifies the cloud platform (e.g., Google, AWS).
    • Resource: Specifies what is being provisioned (e.g., compute instance or EC2 instance).

Terraform Commands

  1. terraform init

    • Prepares the local environment for setting up cloud infrastructure.
    • Downloads necessary dependencies for the specified provider.
  2. terraform plan

    • Lists changes to be made: resources to add, update, or delete.
    • Does not make any changes, only informs the user of potential changes.
  3. terraform apply

    • Implements the changes outlined in the plan.
    • Provisions resources on the specified cloud platform.
  4. terraform destroy

    • Deletes resources created by apply command.

Creating a Terraform File

  • Provider Section:

    • Specify provider (e.g., Google, AWS).
    • Include authentication keys or project IDs as needed.
  • Resource Section:

    • Define resources like compute instances.
    • Specify details like machine type, OS, network interface.

Installing Terraform

  • Install necessary utilities (e.g., unzip).
  • Download Terraform CLI from terraform.io.
  • Follow steps to install on the local system.

Demo: Google Cloud Platform

  • Steps:
    1. Create a project on GCP.
    2. Create a service account for authorization.
    3. Download JSON key for service account.
    4. Create a main.tf file with necessary provider and resource configurations.
    5. Use terraform init, plan, and apply to provision VM.
    6. Verify VM creation on GCP.
    7. Use terraform destroy to remove resources.

Demo: AWS EC2

  • Steps:
    1. Set up AWS account and login as root user.
    2. Generate access keys for authorization.
    3. Create a main.tf file for AWS.
    4. Specify provider and resource details, including AMI ID and instance type.
    5. Use terraform init, plan, and apply to provision EC2 instance.
    6. Verify instance creation on AWS console.
    7. Use terraform destroy to remove resources.

Conclusion

  • Encouragement to explore further Terraform sessions and demos on different platforms.
  • Reference to additional resources available on the presenter's website and YouTube channel.