DEV Community

saheed
saheed

Posted on

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

INTRODUCTION

Building a production-grade infrastructure starts with a rock-solid environment. Below is the exact walkthrough of how I configured my system, the commands I used, and the logic behind my decisions.

Preparing the AWS "House"
The first step is ensuring Terraform has the right permissions to act on your behalf. As noted in the sources, you should never use your root account for daily operations.

IAM User Creation: I navigated to the IAM Console and created a new user with Programmatic Access.

Permissions: I attached the AdministratorAccess Managed Policy
While broad, this is recommended for learning environments to ensure Terraform isn't blocked when trying to create complex networking resources like VPCs or NAT Gateways.

Security: I immediately saved my Access Key ID and Secret Access Key Once you leave that screen, AWS will never show the secret key again.

Installing the Tooling
Terraform Installation: Since I am working on a MacBook Air (Darwin arm64), I used Homebrew to install Terraform

brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Enter fullscreen mode Exit fullscreen mode

Verification: I ran a quick check to ensure everything was installed correctly.

My Version: Terraform v1.14.7
Provider: AWS Provider v6.36.0

Configuring the Environment

Terraform needs to know who is running the commands. I configured my credentials as environment variables to keep them out of my source code.
Decision: I chose to deploy in the us-east-1 region This is a standard choice as it is often the first to receive new AWS features

Executing the Terraform Lifecycle
With the environment ready, I implemented a foundational networking stack (VPC, subnets, and gateways). I followed the core workflow commands defined in the sources.

Step A: terraform init This initialized the backend and downloaded the AWS Provider v6.36.0 this step is idempotent, meaning I can run it safely multiple times if I add new providers later

Step B: terraform plan This is the "sanity check" My plan (seen in the screenshots) confirmed exactly what would happen: 18 resources to add, 0 to change, 0 to destroy. It detailed the creation of a VPC with a CIDR block of 10.0.0.0/16 and tags like demo_vpc

Step C: terraform apply This command executed the plan

Result: The terminal confirmed: "Apply complete! Resources: 18 added"

Step D: terraform destroy To avoid unnecessary costs from resources like the NAT Gateway and Elastic IP, I immediately tested the cleanup process. Terraform correctly identified all 18 resources and tore them down in the reverse order of their dependencies.

CONCLUSION

Terraform is incredibly efficient. It doesn't just build one thing at a time; it maps dependencies and builds everything it can simultaneously.

Top comments (0)