Today is day 2 of the 30 Day Challenge actually day 3 of the challenge i seem to have slacked a bit but we are here for the task: Environment setup.
In todays task we are going to cover the following:
- Set Up AWS Account
- Install and Configure the AWS CLI
- Install Terraform
- Connect Terraform to AWS
These are our matching orders and we are going to tackle them one after the other ensuring that i show you each and every step while explaining exactly what is happening as simple as i can get.
SETUP AWS ACCOUNT
In order to create this account you will need to have:
- valid email address
- phone number for verification
- credit or debit card (for this series we will not exceed the free tier. best believe we will not fall prey to AWS charges only if you follow my guide step by step -- also terraform address resource creation and management to mitigate running unused resource that may be forgotten in the event of clickOps)
REGISTRATION STEPS
- Go to AWS Sign-Up page: visit url https://aws.amazon.com and click Create AWS Account
- Enter Root Email and Account Name
- Verify Your Email
- Set a Strong Root Password
- Enter Contact Information
- Verify Your Identity
- Choose a Support Plan
INSTALL AND CONFIGURE AWS CLI
In order for terraform to authenticate it use's AWS CLI's credentials. Below are the steps to configure it.
Install AWS CLI
macOS
# Using Homebrew
brew install awscli
# Verify installation
aws --version
Linux (ubuntu/Debian)
# Download and install
curl 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip' -o 'awscliv2.zip' unzip awscliv2.zip sudo ./aws/install
# Verify
aws --version
Windows
Download the MSI installer from https://aws.amazon.com/cli/ and run the installer, then verify in
aws --version
CONFIGURE AWS CLI
- We shall head over to AWS and navigate to IAM.
- Here we shall navigate to Users.
- Where we are going to click on Create user
- Enter a username and select checkbox - Provide user access to the AWS Management Console
- You will then proceed to Set Permissions
- Select Attach policies directly
- In the Permissions Policies add AdministratorAccess
- Click Create User and you will be given a password that you will need to save to be used later on.
CREATE ACCESS KEYS
- Select you created user in the Users list
- Click Create access key in the Summary box or Select Security credentials and scroll to Access Keys
- Select Command Line Interface under use case
- add description and confirm
- you will be shown the in the next view Access key and Secret Access key that you will save.
CONFIGURE AWS CLI
- Run command below to configure CLI
aws configure
- You will be prompted with the following
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json
- Verify configs
aws sts get-caller-identity
Note: your credentials will be stored in two files on your machines
~/.aws/credentials— stores your keys~/.aws/config— stores region and output format
INSTALL TERRAFORM
Once you have successfully installed and configured AWS CLI we will proceed with the start of the show Terraform.
In order to install terraform run the commands below
macOS
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Linux
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Windows - use chocolatey (recommended)
choco install terraform
Confirm installation:
terraform -version
You should see something like:
Terraform v1.7.5 on linux_amd64
CONNECT TERRAFORM TO AWS
First of all you are almost done this is where the magic happens. Connecting Terraform to AWS.
We are going to create an EC2 instance on amazon using terrafrom.
- Create a new project on visual studio.
- Create a file called main.tf and add the following code
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "name-example" {
ami = "ami-0735c191cf914754d"
instance_type = "t3.micro"
}
The above code creates a simple instance of a linux box in the region us-west-s.
Note: different regions have different resource id so if you change the region you will need to search the corresponding ami
The table below shows the command you need to run to initialize and create an instance on AWS
| Command | Description |
|---|---|
terraform init |
Initialize a working directory |
terraform plan |
Preview changes before applying |
terraform apply |
Apply the infrastructure changes |
terraform destroy |
Tear down all managed resources |
terraform fmt |
Format your .tf files |
terraform validate |
Check config for errors |
Now we you head over to AWS you will see you instance initalized and running
Just like that you have created your first instance programatically!
i'll see you on Day 3
Part of the #30DayTerraformChallenge | #Terraform | #IaC | #HashiCorp | #AWSUserGroupKenya | #EveOps




Top comments (0)