main.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. locals {
  2. name = var.cluster_name
  3. cluster_version = "1.33"
  4. region = var.cluster_region
  5. serviceaccount_name = var.irsa_sa_name
  6. serviceaccount_namespace = var.irsa_sa_namespace
  7. }
  8. data "aws_caller_identity" "current" {}
  9. module "eks" {
  10. source = "terraform-aws-modules/eks/aws"
  11. version = "~> 21.0"
  12. name = local.name
  13. kubernetes_version = local.cluster_version
  14. compute_config = {
  15. enabled = true
  16. node_pools = ["general-purpose"]
  17. }
  18. vpc_id = module.vpc.vpc_id
  19. subnet_ids = module.vpc.private_subnets
  20. endpoint_private_access = true
  21. endpoint_public_access = true
  22. enable_irsa = true
  23. addons = {
  24. coredns = {
  25. most_recent = true
  26. }
  27. kube-proxy = {
  28. most_recent = true
  29. }
  30. vpc-cni = {
  31. most_recent = true
  32. }
  33. eks-pod-identity-agent = {
  34. most_recent = true
  35. }
  36. }
  37. access_entries = {
  38. tf-admin = {
  39. principal_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/admin"
  40. policy_associations = {
  41. tf-admin = {
  42. policy_arn = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy"
  43. access_scope = {
  44. type = "cluster"
  45. }
  46. }
  47. }
  48. }
  49. github-actions = {
  50. principal_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/github-actions-external-secrets"
  51. policy_associations = {
  52. github-actions = {
  53. policy_arn = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy"
  54. access_scope = {
  55. type = "cluster"
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. ################################################################################
  63. # Supporting resources
  64. ################################################################################
  65. module "vpc" {
  66. source = "terraform-aws-modules/vpc/aws"
  67. version = "~> 6.0"
  68. name = local.name
  69. cidr = "10.0.0.0/16"
  70. azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
  71. private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  72. public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
  73. enable_nat_gateway = true
  74. single_nat_gateway = true
  75. enable_dns_hostnames = true
  76. public_subnet_tags = {
  77. "kubernetes.io/cluster/${local.name}" = "shared"
  78. "kubernetes.io/role/elb" = 1
  79. }
  80. private_subnet_tags = {
  81. "kubernetes.io/cluster/${local.name}" = "shared"
  82. "kubernetes.io/role/internal-elb" = 1
  83. }
  84. }