Introduction
Setting up your environment correctly is the foundation of working with Terraform. In this guide, I’ll walk through how I installed Terraform, configured the AWS CLI, and connected everything to AWS.
1. Setting Up AWS
- Created an AWS account
- Enabled MFA for security
- Created an IAM user with programmatic access
- Attached necessary permissions
2. Installing AWS CLI
Installed AWS CLI and configured it:
3. Installing Terraform
Downloaded and installed Terraform, then verified:
4. Connecting Terraform to AWS
Terraform automatically uses AWS CLI credentials.
Tested connection using:
VSCode Extensions
I installed the following extensions in Visual Studio Code:
- HashiCorp Terraform
- AWS Toolkit
SETUP CHALLENGES
1.Confusion Between Root User and IAM User*
Initially, I was unsure whether to use root credentials or create a new user.
Solution:
I learned that it is best practice to create an IAM user with programmatic access instead of using the root account. I created a dedicated user and generated Access Key ID and Secret Access Key.
2.AWS CLI Configuration Errors
After running aws configure, some commands failed due to incorrect credentials.
Solution:
I rechecked my credentials and region, then reconfigured using aws configure.
CHAPTER TWO LEARNINGS
From Chapter 2, I learned how Terraform authenticates with AWS.
Terraform does not store credentials directly. Instead, it relies on credentials configured through the AWS CLI using the aws configure command. These credentials are stored locally and used whenever Terraform interacts with AWS services.
Terraform uses:
- Access Key ID
- Secret Access Key
- Default region to authenticate and provision infrastructure on AWS.
What Happens If You Use Root Credentials?
Using root credentials is strongly discouraged because:
- The root account has full administrative access
- Any mistake could lead to serious security risks or unexpected charges
- It violates security best practices
Using an IAM user is safer because:
- It follows the principle of least privilege
- Permissions can be controlled and limited
- It reduces risk in case credentials are exposed
Conclusion
By completing this setup, I now have a fully working environment ready to deploy infrastructure using Terraform.



Top comments (0)