Introduction
Setting up your environment correctly is one of the most important steps when learning Terraform. Before deploying infrastructure, you need a solid foundation - properly configured tools, secure credentials, and a working connection between Terraform and AWS.
In this guide, I walk through my exact setup process, including the tools I installed, how I configured AWS access, and the real issues I encountered along the way.
What I Accomplished
By the end of this setup, I was able to:
- Set up a secure AWS environment
- Create an IAM user for Terraform
- Configure AWS CLI with credentials
- Validate Terraform configuration
- Debug real-world Terraform deployment errors
1. AWS Account Setup
I already had an AWS account, but I ensured it followed best practices.
Key steps:
- Enabled MFA on the root account
- Set up a billing alert
- Avoided using root credentials for daily work
2. Creating an IAM User (Important Step)
To follow AWS best practices, I created a dedicated IAM user for Terraform instead of using the root account.
Steps I followed:
- Created a new IAM user
- Enabled programmatic access
- Attached permissions (AdministratorAccess for learning purposes)
- Generated:
- Access Key ID
- Secret Access Key
This ensures safer access and better control over permissions
3. Configuring AWS CLI
I installed and configured AWS CLI using the IAM user credentials.
Command used:
aws configure
Configuration:
- Access Key ID → IAM user key
- Secret Access Key → IAM user secret
- Default region → us-east-1
- Output format → json
4. Terraform Setup (Already Installed)
Terraform was installed previously, so I focused on verification and validation.
Commands I ran:
terraform version
terraform fmt
terraform validate
What these commands do:
- terraform version → Confirms Terraform is installed
- terraform fmt → Formats code for consistency
- terraform validate → Checks configuration for errors
This step helped ensure my Terraform code was clean and ready for deployment.
5. Setting Up Visual Studio Code
To improve my workflow, I installed:
- HashiCorp Terraform Extension
- AWS Toolkit
These tools made it easier to write and manage Terraform code.
6. Validating the Setup
To confirm everything was working correctly, I ran:
terraform version
aws --version
aws sts get-caller-identity
aws configure list
This confirmed:
- Terraform is working
- AWS CLI is configured
- IAM authentication is successful
7. Issues I Encountered and How I Fixed Them
Issue 1: Invalid AMI ID
Error:
InvalidAMIID.NotFound
Cause:
The AMI ID did not exist in the selected region.
Solution:
- Verified region (us-east-1)
- Selected a valid AMI from AWS Console
- Updated the Terraform configuration
Issue 2: Instance Type Not Eligible for Free Tier
Error:
InvalidParameterCombination: instance type not eligible for Free Tier
Cause:
The instance type (t2.micro) was not eligible for my account.
Solution:
Changed to a supported type:
instance_type = "t3.micro"
8. What I Learned (Chapter 2 Insights)
From Chapter 2 of Terraform: Up & Running by Yevgeniy Brikman, I gained a deeper understanding of how Terraform authenticates with AWS and how the different components connect.
Key takeaways:
- Terraform interacts with AWS through a provider, which acts as the bridge between your code and cloud resources
- Authentication is handled externally using: AWS CLI credentials Environment variables IAM roles
- Terraform does not store credentials in code, which improves security and follows best practices
Important lesson:
Using an IAM user instead of root credentials is critical because:
- It limits access and reduces risk
- It allows better permission control
- It follows AWS security best practices
What stood out to me:
Understanding how Terraform relies on AWS CLI configuration made everything click - especially how all tools (Terraform, AWS CLI, IAM) work together seamlessly.
9. Conclusion
Day 2 was all about strengthening my setup and truly understanding how Terraform connects with AWS behind the scenes.
Instead of just installing tools, I:
- Verified my environment
- Fixed real-world errors
- Learned how authentication works
- Successfully deployed an EC2 instance using
terraform apply - Then safely destroyed it using
terraform destroy
This was an important milestone because it proved that my setup is fully working end-to-end - from writing Terraform code to provisioning and cleaning up infrastructure.
Running terraform apply and seeing resources created in AWS, then cleaning them up with terraform destroy, made the entire workflow clear and practical.
This hands-on experience gave me confidence to move forward into building real infrastructure.
Follow My Journey
I’ll be posting my progress daily.
See you on Day 3 🚀
Top comments (0)