Exercise 1: Your First Terraform Configuration
Objective
Learn how to create a basic Terraform configuration, understand the core Terraform workflow, and deploy simple infrastructure to AWS or GCP.
Prerequisites
- Terraform installed (v1.0.0 or newer)
- For AWS: Access key and secret key with appropriate permissions
- For GCP: Google Cloud account with a project and appropriate credentials
Cloud Provider Selection
This exercise provides implementations for both AWS and GCP. Choose the cloud provider you’re most comfortable with or need to learn for your professional requirements:
Core Concepts Covered
Regardless of the cloud provider chosen, this exercise covers these key Terraform concepts:
- Provider Configuration
- Setting up Terraform providers
- Managing provider credentials
- Provider versioning
- Resource Definitions
- Basic resource syntax
- Resource attributes
- Resource identification
- Terraform Workflow
terraform init
- Initialize working directoryterraform plan
- Create execution planterraform apply
- Apply changesterraform destroy
- Remove resources
- State Management
- Local state file
- State inspection
Exercise Overview
In both AWS and GCP implementations, you will:
- Create a basic configuration file
- Configure the appropriate provider
- Define networking resources (VPC/VNet in AWS, VPC in GCP)
- Initialize the working directory
- Create an execution plan
- Apply the plan to create the resources
- Verify resource creation
- Destroy the resources
Learning Outcomes
After completing this exercise, you should be able to:
- Write basic Terraform configuration files
- Understand how to configure cloud providers
- Create and manage resources through Terraform
- Execute the core Terraform workflow
- Read and interpret Terraform plan output
- Clean up resources to avoid unnecessary costs
Additional Challenges
To further enhance your learning, try these additional challenges after completing the basic exercise:
- Add more resources to your configuration (e.g., subnets, security groups)
- Modify existing resources and observe the plan output
- Try changing a resource in a way that forces recreation
- Explore the state file contents using
terraform state list
andterraform state show
Next Steps
After completing this exercise, proceed to Exercise 2: Variables and Outputs, where you’ll learn how to parameterize your configurations and extract useful information.