Free stock photo of bar-tailed godwit

Migrating EKS from CloudFormation to Terraform: A Step-by-Step Guide

Free stock photo of bar-tailed godwit
Photo by Stuart Robinson on Pexels. Source.

Update (2025-12-21 09:03 CET): We’ve reviewed additional resources on EKS migrations to improve our guidance. While migrating, ensure to monitor for any updates in best practices shared by the community. See the linked discussion for more insights.

Migrating your Amazon EKS cluster from CloudFormation to Terraform can optimize your infrastructure management. This guide provides a practical approach to achieve this, focusing on importing clusters, configuring load balancers, and troubleshooting issues.

Prerequisites

Before starting the migration, ensure you have the following:

  • Access to your existing CloudFormation EKS setup.
  • Installed and configured AWS CLI and Terraform.
  • Basic understanding of Kubernetes and Infrastructure as Code (IaC).

Setting Up Terraform for EKS

Initialize a new Terraform directory and configure the AWS provider.

provider "aws" {
  region = "us-west-2"
}

terraform {
  required_version = ">= 0.12"
}

Run the following commands to set up your environment:

terraform init
terraform plan

Importing Existing EKS Infrastructure

Use Terraform to import your existing EKS resources.

terraform import aws_eks_cluster.my_cluster eks-cluster-name

Configuring Load Balancers with Terraform

Ensure your load balancer configurations are compatible with Terraform.

resource "aws_lb" "example" {
  name               = "example-lb"
  internal           = false
  load_balancer_type = "application"
}

Validating the Migration

Verify the migration with the following checkpoints:

  • Cluster status check: aws eks describe-cluster --name my-cluster
  • Node status: kubectl get nodes

Troubleshooting and Common Failures

Address common issues like misconfigurations and resource conflicts:

  • Check Terraform state if conflicts occur.
  • Ensure IAM roles are properly assigned.

Cleaning Up and Best Practices

After migration, clean up any residual resources and follow best practices to maintain your setup efficiently.

terraform apply

Sources

Information sourced from: Discussion on EKS migration.

Transparency Note: This guide was assisted by AI and sources were validated by automation. Content is reviewed to comply with security guidelines.