DEV Community

Stephanie Makori
Stephanie Makori

Posted on

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

Setting up a proper Terraform environment is the first critical step in working with Infrastructure as Code (IaC). A correct setup ensures smooth deployments, secure authentication, and efficient workflow when managing cloud resources.

1. Creating and Securing an AWS Account

I started by setting up my AWS account and immediately secured it:

Enabled Multi-Factor Authentication (MFA) on the root account

Configured billing alerts to avoid unexpected charges

Instead of using the root account for daily operations, I created an IAM user with programmatic access. This is important because root credentials have unrestricted access and pose a major security risk.

2. Installing and Configuring AWS CLI

Next, I installed the AWS CLI and configured it using:

aws configure

I provided:

Access Key ID

Secret Access Key

Default region (I chose us-east-1)

Output format (json)

To confirm everything worked:

aws sts get-caller-identity

This returned my IAM user details, confirming successful authentication.

3. Installing Terraform

I installed the latest version of Terraform and verified it with:

terraform version

Terraform allows me to define infrastructure using a declarative approach, making deployments consistent and repeatable.

4. Connecting Terraform to AWS

Terraform uses the AWS CLI credentials stored locally to authenticate with AWS. This means once AWS CLI is configured, Terraform can automatically interact with AWS services without requiring additional login steps.

5. VS Code Setup

To improve productivity, I installed:

  • HashiCorp Terraform Extension
  • AWS Toolkit

These tools provide syntax highlighting, linting, and better integration with AWS services.

6. Challenges Faced

Initially misconfigured AWS credentials, causing authentication errors

Fixed by re-running aws configure with correct IAM credentials

Conclusion

This setup ensures a secure and fully functional environment for deploying infrastructure using Terraform. With everything configured, I am now ready to start building real-world cloud resources.

Top comments (0)