Deploy AWS EC2 Instance with Terraform - Step-by-Step Guide
Deploy an AWS EC2 instance with Terraform step by step. Complete guide with VPC, security groups, key pairs, user data, and production-ready configuration.
Terraform
Install Terraform on Amazon Linux 2023 and Amazon Linux 2. Official repository, manual install, and EC2 user data bootstrap for CI/CD pipelines.
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
terraform versionsudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo dnf -y install terraformsudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraformresource "aws_instance" "terraform_runner" {
ami = data.aws_ami.al2023.id
instance_type = "t3.micro"
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 -y install terraform git
terraform version
EOF
tags = { Name = "terraform-runner" }
}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 -y install terraform && \
terraform version# List available versions
yum list terraform --showduplicates | sort -r | head -10
# Install specific version
sudo yum install terraform-1.8.5-1Use the HashiCorp AmazonLinux repository (not RHEL) for Amazon Linux. Works on both AL2 and AL2023. For CI/CD pipelines, bake Terraform into your AMI or use the Docker image to avoid install time on every run.
Deploy an AWS EC2 instance with Terraform step by step. Complete guide with VPC, security groups, key pairs, user data, and production-ready configuration.
Deploy AWS CloudFront distributions with Terraform. S3 origin, ALB origin, custom domains, SSL certificates, cache policies, and WAF integration.
Deploy AWS ElastiCache Redis with Terraform. Cluster mode, replication groups, subnet groups, encryption, and parameter group configuration.
Deploy AWS Kinesis Data Streams with Terraform. Stream configuration, shard management, Lambda consumers, Firehose delivery, and encryption settings.