main.tf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. provider "aws" {
  2. region = local.region
  3. }
  4. locals {
  5. name = var.cluster_name
  6. cluster_version = "1.27"
  7. region = var.cluster_region
  8. serviceaccount_name = var.irsa_sa_name
  9. serviceaccount_namespace = var.irsa_sa_namespace
  10. tags = {
  11. Example = local.name
  12. GithubRepo = "external-secrets"
  13. GithubOrg = "external-secrets"
  14. }
  15. }
  16. module "eks" {
  17. source = "git::https://github.com/terraform-aws-modules/terraform-aws-eks?ref=v18.2.0"
  18. cluster_name = local.name
  19. cluster_version = local.cluster_version
  20. cluster_endpoint_private_access = true
  21. cluster_endpoint_public_access = true
  22. cluster_addons = {
  23. coredns = {
  24. resolve_conflicts = "OVERWRITE"
  25. }
  26. kube-proxy = {}
  27. vpc-cni = {
  28. resolve_conflicts = "OVERWRITE"
  29. }
  30. }
  31. vpc_id = module.vpc.vpc_id
  32. subnet_ids = module.vpc.private_subnets
  33. enable_irsa = true
  34. # EKS Managed Node Group(s)
  35. eks_managed_node_group_defaults = {
  36. ami_type = "AL2_x86_64"
  37. disk_size = 50
  38. instance_types = ["t3.large"]
  39. vpc_security_group_ids = [aws_security_group.additional.id]
  40. }
  41. eks_managed_node_groups = {
  42. example = {
  43. desired_size = 2
  44. instance_types = ["t3.large"]
  45. tags = local.tags
  46. }
  47. }
  48. tags = local.tags
  49. }
  50. ################################################################################
  51. # Supporting resources
  52. ################################################################################
  53. module "vpc" {
  54. source = "terraform-aws-modules/vpc/aws"
  55. version = "~> 3.14"
  56. name = local.name
  57. cidr = "10.0.0.0/16"
  58. azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
  59. private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  60. public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
  61. enable_nat_gateway = true
  62. single_nat_gateway = true
  63. enable_dns_hostnames = true
  64. enable_flow_log = false
  65. create_flow_log_cloudwatch_iam_role = false
  66. create_flow_log_cloudwatch_log_group = false
  67. public_subnet_tags = {
  68. "kubernetes.io/cluster/${local.name}" = "shared"
  69. "kubernetes.io/role/elb" = 1
  70. }
  71. private_subnet_tags = {
  72. "kubernetes.io/cluster/${local.name}" = "shared"
  73. "kubernetes.io/role/internal-elb" = 1
  74. }
  75. tags = local.tags
  76. }
  77. resource "aws_security_group" "additional" {
  78. name_prefix = "${local.name}-additional"
  79. vpc_id = module.vpc.vpc_id
  80. ingress {
  81. from_port = 22
  82. to_port = 22
  83. protocol = "tcp"
  84. cidr_blocks = [
  85. "10.0.0.0/8",
  86. "172.16.0.0/12",
  87. "192.168.0.0/16",
  88. ]
  89. }
  90. # allow control-plane to access webhook
  91. ingress {
  92. from_port = 9443
  93. to_port = 9443
  94. protocol = "tcp"
  95. cidr_blocks = ["0.0.0.0/0"]
  96. ipv6_cidr_blocks = ["::/0"]
  97. }
  98. ingress {
  99. from_port = 443
  100. to_port = 443
  101. protocol = "tcp"
  102. cidr_blocks = ["0.0.0.0/0"]
  103. ipv6_cidr_blocks = ["::/0"]
  104. }
  105. # 443, 53, 123 is already allowed
  106. egress {
  107. from_port = 80
  108. to_port = 80
  109. protocol = "tcp"
  110. cidr_blocks = ["0.0.0.0/0"]
  111. ipv6_cidr_blocks = ["::/0"]
  112. }
  113. tags = local.tags
  114. }