Cloud Migration Strategy with Terraform - From Manual to Automated
A step-by-step guide to migrating existing cloud infrastructure to Terraform. Import resources, automate deployments, and build a scalable IaC practice.
DevOps
Complete guide to using Terraform with Kubernetes — provision clusters on AWS EKS, Azure AKS, and GCP GKE, then manage K8s resources with the Kubernetes.
Terraform and Kubernetes are a powerful combination. Terraform provisions the cluster infrastructure (EKS, AKS, GKE), while the Kubernetes provider manages the resources running inside it (deployments, services, configmaps). This guide covers both levels of the stack.
For Kubernetes-specific recipes and patterns, visit Kubernetes Recipes.
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"
cluster_name = "production"
cluster_version = "1.28"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
general = {
instance_types = ["t3.medium"]
min_size = 2
max_size = 10
desired_size = 3
}
}
}resource "azurerm_kubernetes_cluster" "main" {
name = "production-aks"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
dns_prefix = "production"
default_node_pool {
name = "default"
node_count = 3
vm_size = "Standard_D2_v2"
}
identity {
type = "SystemAssigned"
}
}resource "google_container_cluster" "primary" {
name = "production-gke"
location = "us-central1"
initial_node_count = 3
node_config {
machine_type = "e2-medium"
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]
}
}provider "kubernetes" {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
token = data.aws_eks_cluster_auth.cluster.token
}
resource "kubernetes_namespace" "app" {
metadata {
name = "production"
labels = {
environment = "production"
}
}
}
resource "kubernetes_deployment" "app" {
metadata {
name = "web-app"
namespace = kubernetes_namespace.app.metadata[0].name
}
spec {
replicas = 3
selector {
match_labels = { app = "web-app" }
}
template {
metadata {
labels = { app = "web-app" }
}
spec {
container {
name = "web"
image = "nginx:latest"
port {
container_port = 80
}
}
}
}
}
}Terraform manages everything:
Cloud Provider (AWS/Azure/GCP)
└── VPC / Network
└── Kubernetes Cluster (EKS/AKS/GKE)
├── Namespaces
├── Deployments
├── Services
├── ConfigMaps
├── Secrets
└── Ingress| Tool | Best For |
|---|---|
| Terraform | Cluster provisioning, core K8s resources, GitOps-managed infra |
| Helm | Application packaging, templating, release management |
| kubectl | Debugging, ad-hoc commands, quick changes |
Terraform: Terraform for Beginners Course
Kubernetes: Kubernetes Recipes — production patterns
Ansible + K8s: Ansible for Kubernetes — automating K8s with Ansible
Enterprise: OpenEmpower — AWS Partner for cloud architecture
Terraform gives you a single language to manage both the Kubernetes cluster and the workloads running on it. Combined with Kubernetes Recipes for K8s-specific patterns and our Terraform course for IaC fundamentals, you have everything you need to build production Kubernetes infrastructure.
A step-by-step guide to migrating existing cloud infrastructure to Terraform. Import resources, automate deployments, and build a scalable IaC practice.
Learn how to combine Terraform for infrastructure provisioning with Ansible for configuration management. A complete guide to full-stack automation using.
Set up OCI Load Balancer with Terraform — backend sets, listeners, SSL certificates, and health checks. Step-by-step guide with code examples and best practi...
Configure OCI Object Storage buckets with Terraform — lifecycle policies, pre-authenticated requests, and replication. Step-by-step guide with code examples ...