---
# System prepended metadata

title: 'provider “aws” {region = “us-w'

---

provider "aws" {
  region = "us-east-2"  # Replace with your desired AWS region
}

resource "aws_iam_role" "eks_cluster_role" {
  name = "eks-cluster-role"
  assume_role_policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Action = "sts:AssumeRole",
        Effect = "Allow",
        Principal = {
          Service = "eks.amazonaws.com"
        }
      }
    ]
  })
}

module "eks" {
  source           = "terraform-aws-modules/eks/aws"
  cluster_name     = "my-eks-cluster"
  cluster_version  = "1.21"
  subnets          = ["subnet-12345678", "subnet-87654321"]  # Replace with your subnet IDs
  vpc_id           = "vpc-01234567"                         # Replace with your VPC ID
  node_groups = {
    eks_nodes = {
      desired_capacity = 2
      max_capacity     = 3
      min_capacity     = 1
      instance_type    = "t2.medium"  # Choose an appropriate instance type
      key_name          = "my-keypair-name"  # Replace with your SSH key pair name
      additional_tags   = {
        "Environment" = "Development"
      }
    }
  }

  create_eks_cluster = true
  create_eks_workers = true
  worker_groups = {
    eks_nodes = {
      instance_type = "t2.medium"  # Choose an appropriate instance type
    }
  }

  eks_cluster_role_arn = aws_iam_role.eks_cluster_role.arn
}

output "eks_cluster_endpoint" {
  value       = module.eks.cluster_endpoint
  description = "EKS cluster endpoint"
}

output "eks_cluster_name" {
  value       = module.eks.cluster_name
  description = "EKS cluster name"
}

output "eks_cluster_security_group_ids" {
  value       = module.eks.cluster_security_group_ids
  description = "Security group IDs attached to the EKS cluster"
}