- This Terraform configuration sets up an AWS EKS (Elastic Kubernetes Service) Cluster.
- It includes configurations for providers, variables, main settings, a VPC, an EKS cluster, and outputs.
- Terraform v1.6.3 or higher.
- AWS Provider version ~> 5.25.0.
- Additional providers:
random
(> 3.5.1),> 4.0.4),tls
(time
(> 0.10.0),> 2.3.2),cloudinit
(kubernetes
(>= 2.23.2).
- Backend: AWS S3 for state management.
- Bucket: Specified in configuration (replace
<bucket-name>
with actual bucket name). - Key:
terraform.tfstate
. - Region:
us-east-1
.
- Bucket: Specified in configuration (replace
variables.tf
: Defines variables like AWS region and cluster name.- Default region:
us-east-1
. - Default cluster name:
quizapp-eks
.
- Default region:
main.tf
: Configures the Kubernetes and AWS providers.- Sets up the connection to the EKS cluster.
vpc.tf
: Sets up the VPC for the EKS cluster.- CIDR block:
10.20.0.0/16
. - Configures both private and public subnets.
- CIDR block:
eks-cluster.tf
: Configures the EKS cluster.- Cluster version:
1.29
. - Node groups: master and worker with specified instance types and sizes.
- Cluster version:
outputs.tf
: Outputs the cluster name, endpoint, region, and security group ID.
- Initialize Terraform:
terraform init
. - Validate Terraform code:
terraform validate
. - Plan Terraform:
terraform plan
. - Apply configuration:
terraform apply
. - Validate outputs after successful apply.
- Replace placeholder values (like
<bucket-name>
) with actual values. - Ensure you have appropriate AWS permissions.
- Install Terraform CLI
- Install AWS CLI
- Install VS Code Editor - recommended for this course
- Install HashiCorp Terraform plugin for VS Code - recommended
- Download Terraform MAC
- Install CLI
- Unzip the package
# Copy binary zip file to a folder
mkdir /Users/<YOUR-USER>/Documents/terraform-install
COPY Package to "terraform-install" folder
# Unzip
unzip <PACKAGE-NAME>
unzip terraform_1.0.10_darwin_amd64.zip
# Copy terraform binary to /usr/local/bin
echo $PATH
mv terraform /usr/local/bin
# Verify Version
terraform version
# To Uninstall Terraform (NOT REQUIRED)
rm -rf /usr/local/bin/terraform
# Install AWS CLI V2
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
which aws
aws --version
# Uninstall AWS CLI V2 (NOT REQUIRED)
which aws
ls -l /usr/local/bin/aws
sudo rm /usr/local/bin/aws
sudo rm /usr/local/bin/aws_completer
sudo rm -rf /usr/local/aws-cli
-
Pre-requisite: Should have AWS Account.
-
Role: -If your terraform server is in the cloud, then create a role and attach the role to your server.
-
Generate Security Credential s using AWS Management Console
- Go to Services -> IAM -> Users -> "Your-Admin-User" -> Security Credentials -> Create Access Key
-
Configure AWS credentials using SSH Terminal on your local desktop
$ aws configure
Default region name [None]: us-west-2
Default output format [None]: json
# Verify if we are able list S3 buckets
aws s3 ls
- Verify the AWS Credentials Profile
cat $HOME/.aws/credentials
#Command to reset your AWS credentials incase of a credentials error:
$ for var in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SECURITY_TOKEN ; do eval unset $var ; done
-
Unzip the package
-
Create new folder
binaries
-
Copy the
terraform.exe
to abinaries
-
Set PATH in windows How to set the windows path: Windows 8/10 In Search, search for and then select: System (Control Panel) Click the Advanced system settings link. Click Environment Variables. In the section System Variables find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
-
Install AWS CLI
-Install terraform on windows using the windows package manager(Use powershell and install as administrator). $ choco install terraform
$sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
$curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
$sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
$sudo apt-get update && sudo apt-get install terraform
**Install aws cli**
sudo yum update -y
sudo yum install curl unzip wget -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
**Install Terraform**
a) *Download binary*
sudo yum update -y
sudo yum install wget unzip -y
sudo wget https://releases.hashicorp.com/terraform/1.4.4/terraform_1.1.4_linux_amd64.zip
sudo unzip terraform_1.1.4_linux_amd64.zip -d /usr/local/bin
terraform -v
b) *Install from hashicorp repo*
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform