Terraform Basics

intermediateterraformIaCcloud

Create and manage cloud infrastructure using Terraform

← Back to Intermediate

Learning Objectives

  • Understand Terraform's core concepts and workflow
  • Create infrastructure resources using Terraform HCL
  • Manage infrastructure state and dependencies
  • Implement modular and reusable Terraform code
  • Apply Terraform best practices for organization and security

Requirements

You are required to implement basic infrastructure using Terraform:

  1. Terraform Configuration Basics
    • Create a new Terraform project with proper structure:
      terraform-project/
      ├── main.tf       # Main configuration file
      ├── variables.tf  # Input variables
      ├── outputs.tf    # Output values
      ├── providers.tf  # Provider configuration
      └── .gitignore    # Exclude state files and secrets
      
    • Configure the AWS or Azure provider
    • Set up provider authentication
    • Initialize the Terraform working directory (terraform init)
  2. Basic Infrastructure Deployment
    • Create a Virtual Private Cloud (VPC) or Virtual Network
    • Implement at least two subnets (public and private)
    • Create security groups or network security groups
    • Deploy a simple virtual machine
    • Configure network interfaces
  3. Resource Organization and Variables
    • Use input variables for customization
    • Implement local variables for internal calculations
    • Create meaningful outputs
    • Use data sources to query existing resources
    • Implement resource dependencies
    • Use proper naming conventions and tags
  4. State Management
    • Understand Terraform state concepts
    • Configure a local backend for state storage
    • Perform state operations (terraform state list, etc.)
    • Implement state locking for collaborative work
    • Document backup procedures for state files
  5. Testing and Validation
    • Validate configurations (terraform validate)
    • Generate an execution plan (terraform plan)
    • Apply the configuration (terraform apply)
    • Verify created resources via cloud console
    • Destroy resources when finished (terraform destroy)

Stretch goals

  • Implement a remote backend (S3 + DynamoDB or Azure Storage)
  • Create a reusable module for network configuration
  • Use Terraform workspaces for managing multiple environments
  • Implement dynamic blocks for repeated resource patterns
  • Add automated tests for Terraform code

Deliverables

  • Complete Terraform project implementing the required infrastructure
  • Documentation of the infrastructure architecture with diagrams
  • Screenshots showing successful apply and resources created
  • README with instructions for using the Terraform configuration
  • Summary of lessons learned and challenges encountered

Once you have completed this project, you will be able to create and manage infrastructure using Terraform - a fundamental skill for implementing Infrastructure as Code in modern DevOps environments.

Submit Your Solution

Completed this project? Share your solution with the community!

  1. Push your code to a GitHub repository
  2. Open an issue on our GitHub repo with your solution link
  3. Share on X with the hashtag #DevOpsDiary