Knowledge Base
Software
2025-09-12
6 min

A concise reference to a basic setup of Terraform

This quick Terraform reference guide explores the setting up of AWS and Terraform on your machine and then to create S3 buckets using the Terraform CLI.

Terraform
AWS
Infrastructure as Code
S3
Setup Guide

A reference for getting Terraform ready to manage AWS resources on a fresh machine. Covers installing dependencies, configuring the AWS CLI, and running the basic Terraform workflow of init, plan, and apply.

đŸ“ĻPrerequisites

Before running Terraform you need:

  • An AWS account with programmatic access enabled.
  • The AWS CLI installed and configured.
  • Terraform installed on your machine.
  • An IAM user for Terraform with appropriate permissions.

đŸ› ī¸Install Tools

  1. 1
    Install AWS CLI

    Download from AWS or install via your package manager.

    bash
    # Linux/macOS
    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
    unzip awscliv2.zip && sudo ./aws/install
    aws --version
    
    # Windows (PowerShell, with Chocolatey)
    choco install awscli
    aws --version
  2. 2
    Install Terraform
    bash
    # macOS with Homebrew
    brew tap hashicorp/tap
    brew install hashicorp/tap/terraform
    
    # Windows (PowerShell, with Chocolatey)
    choco install terraform
    
    terraform -version

🔑Configure AWS Profile

Set up a dedicated profile for Terraform. This keeps its credentials isolated from other AWS use.

bash
aws configure --profile terraform-user
# Paste Access Key + Secret
# Default region: af-south-1 (or your chosen region)
# Output format: json
â„šī¸
Use aws sts get-caller-identity to confirm the profile works and shows the correct account ID.

🚀Run Terraform

  1. 1
    Set environment variables
    bash
    # Bash
    export AWS_PROFILE=terraform-user
    export AWS_REGION=af-south-1
    
    # PowerShell
    $env:AWS_PROFILE = "terraform-user"
    $env:AWS_REGION  = "af-south-1"
  2. 2
    Initialize Terraform
    bash
    terraform init -reconfigure
  3. 3
    Review the plan
    bash
    terraform plan
  4. 4
    Apply the changes
    bash
    terraform apply
    # Confirm with "yes"

🐛Troubleshooting

  • waiting for S3 Bucket ... create: empty result: Often a propagation delay in opt-in regions. Check if the bucket exists with aws s3api list-buckets.
  • Cannot import non-existent remote object: Usually region/profile mismatch or missing IAM permissions (add s3:GetBucket* actions).
  • AccessDenied: The error text names the missing IAM action - add it to your Terraform user policy.

Filed under: Terraform, AWS, Infrastructure as Code, S3, Setup Guide

Last updated: 2025-09-12