Skip to main content

Command Palette

Search for a command to run...

How I Installed AWS CLI and Terraform on macOS and Deployed an EC2 Instance Using Terraform (Beginner Step-by-Step Guide)

A beginner-friendly guide to installing AWS CLI, configuring access keys, installing Terraform, and deploying AWS infrastructure directly from macOS.

Updated
8 min read
How I Installed AWS CLI and Terraform on macOS and Deployed an EC2 Instance Using Terraform (Beginner Step-by-Step Guide)

Introduction

As I continue my journey into Cloud Engineering and DevOps, one of the first tools I needed to set up on my system was the AWS CLI and Terraform.

These tools are extremely important for cloud engineers because they allow you to interact with cloud services and automate infrastructure directly from your terminal. I decided to set up my local development environment so I could interact with AWS directly from my terminal and automate infrastructure using code.

In this guide, I will walk you through the exact steps I used to install AWS CLI and Terraform on my MacBook Air running macOS. This tutorial is beginner-friendly and designed for anyone starting their journey in Cloud Computing or DevOps.

Two essential tools for this are:

  • AWS CLI (Command Line Interface)

  • Terraform

What is AWS CLI?

The AWS Command Line Interface (AWS CLI) is a tool that allows you to manage AWS services from your terminal instead of using the AWS Management Console.

With AWS CLI you can:

  • Create EC2 instances

  • Manage S3 buckets

  • Configure IAM

  • Automate cloud tasks

Using the CLI is very important in DevOps workflows because it allows engineers to automate tasks and build scripts.


What is Terraform?

Terraform is an Infrastructure as Code (IaC) tool developed by HashiCorp.

It allows you to create and manage cloud infrastructure using code instead of manually clicking in the console.

With Terraform you can:

  • Launch servers

  • Create networks

  • Configure load balancers

  • Deploy full cloud architectures

This makes infrastructure reproducible, scalable, and automated.

In this guide, I will walk through the exact steps I followed to:

  • Install AWS CLI on macOS

  • Generate AWS Access Keys

  • Configure AWS CLI

  • Install Terraform

  • Verify the installations

  • Deploy a VPC and EC2 instance using Terraform

This guide is beginner-friendly and perfect for anyone starting their cloud or DevOps journey.


Prerequisites

Before starting, ensure you have the following:

  • A MacBook running macOS

  • An AWS account

  • Internet connection

  • Basic familiarity with the terminal


Step 1: Opening the Terminal on macOS

The first thing I did was open the Terminal application on my MacBook.

Steps:

  1. Press Command + Space

  2. Search for Terminal

  3. Press Enter

This opens the command line interface where we will run all our commands.


Step 2: Installing Homebrew (macOS Package Manager)

Before installing AWS CLI and Terraform, I installed Homebrew.

Homebrew is a package manager for macOS that makes it easy to install developer tools directly from the terminal.

I ran the following command in the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This command automatically downloads and installs Homebrew.

After the installation finished, I confirmed that Homebrew was successfully installed by running:

brew --version

If Homebrew is installed correctly, it should display the version number.

and


Step 3: Installing AWS CLI

Next, I installed the AWS Command Line Interface (AWS CLI) using Homebrew.

AWS CLI allows you to manage AWS services such as:

  • EC2

  • S3

  • VPC

  • IAM

directly from your terminal.

To install AWS CLI, I ran:

brew install awscli

Homebrew downloaded and installed the latest version automatically.


Step 4: Verifying AWS CLI Installation

After the installation completed, I verified the installation by running:

aws --version

If the installation was successful, the terminal displays something similar to:

aws-cli/2.x.x Python/3.x Darwin/x86_64

Step 5: Generating AWS Access Keys

Before configuring AWS CLI, I needed to generate AWS Access Keys from the AWS Management Console.

Steps I followed:

  1. Logged into the AWS Console

  2. Navigated to IAM

  3. Clicked Users

  4. Selected my user account

  5. Clicked Security Credentials

  6. Created Access Key

AWS then generated:

  • Access Key ID

  • Secret Access Key

These keys allow the AWS CLI to securely connect to my AWS account.

Screenshot Section


Step 6: Configuring AWS CLI

After generating the access keys, I configured AWS CLI on my MacBook.

I ran the command:

aws configure

The terminal prompted me to enter:

  • AWS Access Key ID

  • AWS Secret Access Key

  • Default region

  • Output format

Example:

AWS Access Key ID: ***************
AWS Secret Access Key: ***************
Default region name: us-east-1
Default output format: json

After entering these details, the AWS CLI was successfully connected to my AWS account.

Screenshot Section


Step 7: Testing AWS CLI Connection

To confirm that the configuration worked correctly, I tested the connection using:

aws s3 ls

This command lists all S3 buckets in your AWS account.

If everything is configured correctly, the CLI returns your bucket list.

Screenshot Section


Step 8: Installing Terraform

After successfully setting up AWS CLI, the next step was installing Terraform.

Terraform is an Infrastructure as Code (IaC) tool that allows engineers to provision cloud infrastructure using configuration files.

I installed Terraform using Homebrew with the following command:

brew install terraform

Homebrew downloaded and installed Terraform automatically.

Screenshot Section


Step 9: Verifying Terraform Installation

After installation, I verified that Terraform was installed correctly by running:

terraform version

If successful, Terraform displays its version number.

Example output:

Terraform v1.x.x

Screenshot Section


Step 10: Creating Terraform Configuration

After installing Terraform, I created a Terraform project folder and configuration file.

First, I created a new directory:

mkdir terraform-project
cd terraform-project

Then I created a Terraform configuration file:

main.tf

Screenshot Section


Step 11: Writing Terraform Code to Create a VPC

In the main.tf file, I defined a VPC resource.

Example configuration:

provider "aws" {
  region = "us-east-1"
}

resource "aws_vpc" "my_vpc" {
  cidr_block = "10.0.0.0/16"
}

This code tells Terraform to create a VPC in AWS.

Screenshot Section

Terraform VPC configuration


Step 12: Creating an EC2 Instance with Terraform

Next, I added an EC2 instance resource to the Terraform configuration.

Example:



# Create Subnet
resource "aws_subnet" "my_subnet" {
  vpc_id     = aws_vpc.my_vpc.id
  cidr_block = "10.0.1.0/24"

  tags = {
    Name = "my-subnet"
  }
}

# Create EC2 Instance
resource "aws_instance" "my_ec2" {
  ami           = "ami-0694d931cee176e7d"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.my_subnet.id

  tags = {
    Name = "Terraform-EC2"
  }
}

This configuration instructs Terraform to create a t2.micro EC2 instance.

Screenshot Section

Terraform EC2 configuration


Step 13: Initializing Terraform

Before deploying infrastructure, Terraform must initialize the project.

I ran:

terraform init

This downloads the required AWS provider plugins.

Screenshot Section


Step 14: Planning Infrastructure

Next, I ran:

terraform plan

This command shows what resources Terraform will create before actually deploying them.

Screenshot Section


Step 15: Deploying Infrastructure

Finally, I deployed the infrastructure using:

terraform apply

Terraform then created the:

  • VPC

  • EC2 Instance

in my AWS account.

Screenshot Section


Step 16: Verifying Resources in AWS Console

After the deployment finished, I confirmed the resources in the AWS Console.

I navigated to:

  • VPC Dashboard

  • EC2 Dashboard

and verified that the resources were successfully created.

Screenshot Section

  • Created VPC
  • Running EC2 instance

Step 17: How to Delete Everything (Important)

To remove everything you created:

terraform destroy

This will delete:

  • VPC

  • Subnet

  • EC2 instance

Screenshot Section


Challenges I Encountered

During this process, I encountered a few beginner challenges:

  • Understanding how AWS Access Keys work

  • Ensuring Terraform syntax was correct

  • Running terraform init before applying configurations

However, once everything was configured correctly, Terraform made it very easy to deploy infrastructure.


Final Thoughts

Setting up AWS CLI and Terraform on macOS was a major step in my cloud engineering journey.

With these tools, I can now:

  • Manage AWS services from the terminal

  • Automate infrastructure deployment

  • Build scalable cloud environments using code

For anyone starting in Cloud Computing, DevOps, or Infrastructure Engineering, learning AWS CLI and Terraform is an essential skill.


✍️ Author

Silias Odion Adodo
Cloud Engineering Student | Linux & DevOps Enthusiast
AltSchool Africa