This quickstart guide will walk you through installing Terraform and creating your first infrastructure. You’ll learn the basic Terraform workflow: write, initialize, plan, and apply.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hashicorp/terraform/llms.txt
Use this file to discover all available pages before exploring further.
This guide uses the
local provider to create a file on your local system. This is a simple example to demonstrate Terraform’s workflow without requiring cloud credentials.Prerequisites
Before you begin, make sure you have:- A terminal or command prompt
- Basic familiarity with the command line
- Approximately 10 minutes
Step 1: Install Terraform
First, you’ll need to install Terraform on your system. The easiest way is to download a pre-built binary from the HashiCorp releases website.- macOS
- Linux
- Windows
Using Homebrew:
Step 2: Create Your First Configuration
Create a new directory for your Terraform project and navigate to it:main.tf with the following content:
main.tf
This configuration uses the
local provider to create two files on your local filesystem. The terraform block specifies the required provider, and the resource blocks define the infrastructure.Step 3: Initialize Terraform
Before you can use Terraform, you need to initialize the working directory. This downloads the required provider plugins.Step 4: Preview Changes with Plan
Before creating any infrastructure, it’s a good practice to preview what Terraform will do:+ symbol indicates that Terraform will create these resources.
Step 5: Apply the Configuration
Now, let’s create the infrastructure:yes to proceed:
Terraform has created two files in your directory:
hello.txt and config.json. You can verify this by running ls or cat hello.txt.Step 6: Modify Infrastructure
Let’s modify the configuration to see how Terraform handles changes. Editmain.tf and update the content of the hello file:
main.tf
terraform plan again to see what will change:
Step 7: Inspect State
Terraform keeps track of your infrastructure in a state file. You can inspect the current state:Step 8: Destroy Infrastructure
When you’re done experimenting, you can destroy the infrastructure:yes to proceed:
Understanding the Terraform Workflow
You’ve now experienced the core Terraform workflow:Next Steps
Now that you understand the basics, explore these topics:Core Concepts
Learn about providers, resources, variables, and state
CLI Reference
Explore all available Terraform commands
Configuration Language
Deep dive into HCL syntax and features
Cloud Providers
Work with AWS, Azure, GCP, and other providers
Common Commands Reference
| Command | Description |
|---|---|
terraform init | Initialize a working directory |
terraform validate | Validate configuration files |
terraform plan | Show changes required to reach desired state |
terraform apply | Create or update infrastructure |
terraform destroy | Destroy all managed infrastructure |
terraform fmt | Format configuration files to canonical style |
terraform show | Display the current state or a saved plan |
terraform state list | List resources in the state |
terraform output | Show output values |