TerraformPilot

DevOps

Install Terraform on Amazon Linux 2023: Step-by-Step Guide

Install Terraform on Amazon Linux 2023 using the HashiCorp repository or manual binary download. Verify installation, configure autocomplete

LLuca Berton1 min read

Amazon Linux 2023 uses dnf (not yum) and doesn't include amazon-linux-extras. Here's how to install Terraform on AL2023 — whether on an EC2 instance, ECS container, or local development.

#
# Install dnf config-manager
sudo dnf install -y dnf-plugins-core
 
# Add HashiCorp repository
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
 
# Install Terraform
sudo dnf install -y terraform
 
# Verify
terraform version
# Terraform v1.10.0

Method 2: Manual Binary Download

#
# Download latest version
TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
 
# Install unzip if needed
sudo dnf install -y unzip
 
# Extract and install
unzip terraform.zip
sudo mv terraform /usr/local/bin/
rm terraform.zip
 
# Verify
terraform version

ARM/Graviton Instances

#

For Graviton-based EC2 instances (t4g, m7g, c7g):

TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/

Enable Autocomplete

#
terraform -install-autocomplete
# Adds to ~/.bashrc
 
# Reload shell
source ~/.bashrc
 
# Now: terraform pl<TAB> → terraform plan

Configure AWS Credentials

# #

If your EC2 instance has an IAM role, Terraform uses it automatically:

# Verify instance role
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/
# YourRoleName
 
# Terraform uses this automatically — no config needed
terraform init
terraform plan

AWS CLI Credentials

#
# Install AWS CLI (pre-installed on AL2023)
aws --version
 
# Configure credentials
aws configure
# AWS Access Key ID: AKIA...
# AWS Secret Access Key: ****
# Default region name: us-east-1
# Default output format: json
 
# Terraform reads ~/.aws/credentials automatically
terraform init
terraform plan

Environment Variables

#
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="us-east-1"
 
terraform plan

Quick Test

#
mkdir ~/terraform-test && cd ~/terraform-test
 
cat > main.tf << 'EOF'
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
 
provider "aws" {
  region = "us-east-1"
}
 
data "aws_caller_identity" "current" {}
 
output "account_id" {
  value = data.aws_caller_identity.current.account_id
}
EOF
 
terraform init
terraform plan
# Should show your AWS account ID

User Data (EC2 Bootstrap)

#

Install Terraform automatically when launching an EC2 instance:

#!/bin/bash
# User data script for AL2023
 
# Install Terraform via HashiCorp repo
dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
dnf install -y terraform git
 
# Verify
terraform version

In Terraform (yes, Terraform installing Terraform):

resource "aws_instance" "ci_runner" {
  ami           = data.aws_ami.al2023.id
  instance_type = "t3.medium"
 
  user_data = <<-EOF
    #!/bin/bash
    dnf install -y dnf-plugins-core
    dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
    dnf install -y terraform git
  EOF
 
  iam_instance_profile = aws_iam_instance_profile.ci.name
}

Docker (AL2023 Base)

#
FROM amazonlinux:2023
 
RUN dnf install -y dnf-plugins-core unzip && \
    dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo && \
    dnf install -y terraform && \
    dnf clean all
 
ENTRYPOINT ["terraform"]
docker build -t terraform-al2023 .
docker run --rm terraform-al2023 version

Update Terraform

#
# Repository method — update like any package
sudo dnf update -y terraform
 
# Manual method — download new version and replace
TERRAFORM_VERSION="1.10.1"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/

Troubleshooting

#

"dnf config-manager: command not found"

#
sudo dnf install -y dnf-plugins-core

"No such file or directory: terraform"

#
# Check if terraform is in PATH
which terraform
 
# If installed manually, ensure /usr/local/bin is in PATH
echo $PATH | grep -q '/usr/local/bin' || echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Permission Denied

#
# Ensure binary is executable
sudo chmod +x /usr/local/bin/terraform

Hands-On Courses

#

Conclusion

#

Install Terraform on Amazon Linux 2023 via the HashiCorp dnf repository for easy updates, or download the binary manually for airgapped environments. Use IAM instance roles for EC2-based workflows — no credential management needed. For Graviton instances, use the linux_arm64 binary.

#Terraform#AWS#Amazon Linux#Installation#DevOps

Share this article