DEV Community

Udoh Deborah
Udoh Deborah

Posted on

Day 2: Step-by-Step Guide to Setting Up Terraform, AWS CLI, and Your AWS Environment

Step-by-Step Guide to Setting Up Terraform, AWS CLI, and Your AWS Environment

Getting started with Terraform can feel overwhelming at first, especially when you have to connect multiple tools like AWS, the CLI, and your local environment. But once your setup is done correctly, everything else becomes much easier.

In this guide, I’ll walk through how I set up my environment step-by-step so I’m ready to start deploying real infrastructure using Terraform.

Step 1: Set Up Your AWS Account

If you don’t already have an AWS account, create one and make sure to secure it properly.

The first thing I did after creating my account was:

  • Enable Multi-Factor Authentication (MFA) on the root account
  • Set up a billing alert to avoid unexpected charges

This is important because even small mistakes in cloud environments can lead to costs.

Step 2: Create an IAM User for Terraform

Instead of using the root account (which is not recommended), I created a dedicated IAM user for Terraform.

Key steps:

  • Enabled programmatic access
  • Attached appropriate permissions (for learning, I used broad access, but in production, least privilege is best)
  • Saved the Access Key ID and Secret Access Key

This IAM user will be used by Terraform to interact with AWS securely.

Step 3: Install and Configure AWS CLI

Next, I installed the AWS CLI, which allows me to interact with AWS from the terminal.

After installation, I configured it using:

aws configure
Enter fullscreen mode Exit fullscreen mode

I entered:

  • Access Key
  • Secret Key
  • Default region (I chose us-east-1)
  • Output format (json)

To confirm everything was working, I ran:

aws sts get-caller-identity
Enter fullscreen mode Exit fullscreen mode

This returned my AWS account details, which confirmed that authentication was successful.

Step 4: Install Terraform

I then installed Terraform on my machine.

To confirm installation, I ran:

terraform version
Enter fullscreen mode Exit fullscreen mode

Once this worked, I knew Terraform was ready to use.

Step 5: Connect Terraform to AWS

One thing I learned is that Terraform doesn’t need separate credentials if AWS CLI is already configured.

Terraform automatically uses the credentials stored by the AWS CLI.

This makes things much simpler because once your CLI is working, Terraform can immediately interact with AWS.

Step 6: Set Up Visual Studio Code

To make development easier, I installed:

  • HashiCorp Terraform extension
  • AWS Toolkit extension

These help with syntax highlighting, validation, and managing resources more efficiently.

Common Issues and Fixes

One issue I ran into was Terraform not recognizing AWS credentials.

This was resolved by:

  • Re-running aws configure
  • Making sure the correct IAM user credentials were used
  • Verifying setup using aws sts get-caller-identity

This step is important because most Terraform errors at the beginning come from misconfigured credentials.

Key Takeaways

  • Always use an IAM user, not the root account
  • Verify your setup early using CLI commands
  • Terraform depends on AWS CLI configuration for authentication
  • A proper setup saves time and prevents errors later

Final Thoughts

Day 2 was all about getting the foundation right. It might not feel as exciting as deploying infrastructure, but this setup is what makes everything else possible.

Now that everything is configured and working, I’m ready to start building real infrastructure with Terraform.

Top comments (0)