diff --git a/eks/.terraform.lock.hcl b/eks/.terraform.lock.hcl new file mode 100644 index 0000000..57f6569 --- /dev/null +++ b/eks/.terraform.lock.hcl @@ -0,0 +1,124 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.54.1" + constraints = ">= 4.0.0, >= 4.33.0, >= 4.57.0, >= 5.0.0" + hashes = [ + "h1:h6AA+TgBpDNQXFcLi4xKYiDbn94Dfhz7lt8Q8x8CEI8=", + "zh:37c09b9a0a0a2f7854fe52c6adb15f71593810b458a8283ed71d68036af7ba3a", + "zh:42fe11d87723d4e43b9c6224ae6bacdcb53faee8abc58f0fc625a161d1f71cb1", + "zh:57c6dfc46f28c9c2737559bd84acbc05aeae90431e731bb72a0024028a2d2412", + "zh:5ba9665a4ca0e182effd75575b19a4d47383ec02662024b9fe26f78286c36619", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b55980be0237644123a02a30b56d4cc03863ef29036c47d6e8ab5429ab45adf5", + "zh:b81e7664f10855a3a6fc234a18b4c4f1456273126a40c41516f2061696fb9870", + "zh:bd09736ffafd92af104c3c34b5add138ae8db4402eb687863ce472ca7e5ff2e2", + "zh:cc2eb1c62fba2a11d1f239e650cc2ae94bcab01c907384dcf2e213a6ee1bd5b2", + "zh:e5dc40205d9cf6f353c0ca532ae29afc6c83928bc9bcca47d74b640d3bb5a38c", + "zh:ebf1acdcd13f10db1b9c85050ddaadc70ab269c47c5a240753362446442d8371", + "zh:f2fc28a4ad94af5e6144a7309286505e3eb7a94d9dc106722b506c372ff7f591", + "zh:f49445e8435944df122aa89853260a2716ba8b73d6a6a70cae1661554926d5a2", + "zh:fc3b5046e60ae7cab20715be23de8436eb12736136fd6d0f0cc1549ebda6cc73", + "zh:fdb98a53500e245a3b5bec077b994da6959dba8fc4eb7534528658d820e06bd5", + ] +} + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.4" + constraints = ">= 2.0.0" + hashes = [ + "h1:+J2rgfJH5B0vyFR0Wfcoyt4SHWfZLDe+WtUMtmZLDeY=", + "zh:09f1f1e1d232da96fbf9513b0fb5263bc2fe9bee85697aa15d40bb93835efbeb", + "zh:381e74b90d7a038c3a8dcdcc2ce8c72d6b86da9f208a27f4b98cabe1a1032773", + "zh:398eb321949e28c4c5f7c52e9b1f922a10d0b2b073b7db04cb69318d24ffc5a9", + "zh:4a425679614a8f0fe440845828794e609b35af17db59134c4f9e56d61e979813", + "zh:4d955d8608ece4984c9f1dacda2a59fdb4ea6b0243872f049b388181aab8c80a", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:a48fbee1d58d55a1f4c92c2f38c83a37c8b2f2701ed1a3c926cefb0801fa446a", + "zh:b748fe6631b16a1dafd35a09377c3bffa89552af584cf95f47568b6cd31fc241", + "zh:d4b931f7a54603fa4692a2ec6e498b95464babd2be072bed5c7c2e140a280d99", + "zh:f1c9337fcfe3a7be39d179eb7986c22a979cfb2c587c05f1b3b83064f41785c5", + "zh:f58fc57edd1ee3250a28943cd84de3e4b744cdb52df0356a53403fc240240636", + "zh:f5f50de0923ff530b03e1bca0ac697534d61bb3e5fc7f60e13becb62229097a9", + ] +} + +provider "registry.terraform.io/hashicorp/helm" { + version = "2.14.0" + hashes = [ + "h1:QHpOJbeU6V8Qt6YFRWkQ7/kttJu8cN3egyG7TImZEKw=", + "zh:087a475fda3649e4b6b9aeb5f21704972f5d85c10d0bf334289b0a1b8c1a5575", + "zh:1877991d976491d4e2a653a89491bd3b92123a00f442f15aa62caea8902677c7", + "zh:233d9e550b900be8bbf62871322964239bb4827b3500b77d7e2652a8bae6a106", + "zh:6ed09d405ade276dfc6ec591d113ca328ea3fe423405d4bc1116f7a06dfd86ec", + "zh:9039de4cbee5ae006d9cbf27f40f0a285feb02c3b00901535a1112853de55b5f", + "zh:aea6311b0f29edddefa21b8c7953314459caeace77d72d60588d1277f1723c54", + "zh:bd6a4fea3461c2751527f1c4e4c2c160e72f5b5a3b5cfbfe051adf61badd5ead", + "zh:c5f12a2ea4c3b62d9dd2d8f62c9918ef77b1f9dd4d6ccf1758a2a24139ab5319", + "zh:cd84d7258f263c3bd24138e7633b022451fdc1935a11e34932b63f71bbe6059f", + "zh:e637d01ee4dc2e5702d62c158399ab0d0ba3269e71f5db38db922ff05505ae2a", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:fbf9c9936ae547b75a81170b7bd20f72bc5538e015efcf7d12f822358d758f57", + ] +} + +provider "registry.terraform.io/hashicorp/kubernetes" { + version = "2.31.0" + constraints = ">= 2.10.0" + hashes = [ + "h1:WHHHlt0hm+I7edol7FQJzHiaQHoGr800dtpXrR9QJVc=", + "zh:0d16b861edb2c021b3e9d759b8911ce4cf6d531320e5dc9457e2ea64d8c54ecd", + "zh:1bad69ed535a5f32dec70561eb481c432273b81045d788eb8b37f2e4a322cc40", + "zh:43c58e3912fcd5bb346b5cb89f31061508a9be3ca7dd4cd8169c066203bcdfb3", + "zh:4778123da9206918a92dfa73cc711475d2b9a8275ff25c13a30513c523ac9660", + "zh:8bfa67d2db03b3bfae62beebe6fb961aee8d91b7a766efdfe4d337b33dfd23dd", + "zh:9020bb5729db59a520ade5e24984b737e65f8b81751fbbd343926f6d44d22176", + "zh:90431dbfc5b92498bfbce38f0b989978c84421a6c33245b97788a46b563fbd6e", + "zh:b71a061dda1244f6a52500e703a9524b851e7b11bbf238c17bbd282f27d51cb2", + "zh:d6232a7651b834b89591b94bf4446050119dcde740247e6083a4d55a2cefd28a", + "zh:d89fba43e699e28e2b5e92fff2f75fc03dbc8de0df9dacefe1a8836f8f430753", + "zh:ef85c0b744f5ba1b10dadc3c11e331ba4225c45bb733e024d7218c24b02b0512", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/time" { + version = "0.11.2" + constraints = ">= 0.9.0" + hashes = [ + "h1:FVyFc0JtobHmEha0xXeT76XPkhGb62r1Mk709kcwp+w=", + "zh:02588b5b8ba5d31e86d93edc93b306bcbf47c789f576769245968cc157a9e8c5", + "zh:088a30c23796133678d1d6614da5cf5544430570408a17062288b58c0bd67ac8", + "zh:0df5faa072d67616154d38021934d8a8a316533429a3f582df3b4b48c836cf89", + "zh:12edeeaef96c47f694bd1ba7ead6ccdb96028b25df352eea4bc5e40de7a59177", + "zh:1e859504a656a6e988f07b908e6ffe946b28bfb56889417c0a07ea9605a3b7b0", + "zh:64a6ae0320d4956c4fdb05629cfcebd03bcbd2206e2d733f2f18e4a97f4d5c7c", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:924d137959193bf7aee6ebf241fbb9aec46d6eef828c5cf8d3c588770acae7b2", + "zh:b3cc76281a4faa9c2293a2460fc6962f6539e900994053f85185304887dddab8", + "zh:cbb40c791d4a1cdba56cffa43a9c0ed8e69930d49aa6bd931546b18c36e3b720", + "zh:d227d43594f8cb3d24f1fdd71382f14502cbe2a6deaddbc74242656bb5b38daf", + "zh:d4840641c46176bb9d70ba3aff09de749282136c779996b546c81e5ff701bbf6", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.5" + constraints = ">= 3.0.0" + hashes = [ + "h1:jb/Rg9inGYp4t8HtBoETESsQJgdmOHoe1bzzg2uNB3w=", + "zh:01cfb11cb74654c003f6d4e32bbef8f5969ee2856394a96d127da4949c65153e", + "zh:0472ea1574026aa1e8ca82bb6df2c40cd0478e9336b7a8a64e652119a2fa4f32", + "zh:1a8ddba2b1550c5d02003ea5d6cdda2eef6870ece86c5619f33edd699c9dc14b", + "zh:1e3bb505c000adb12cdf60af5b08f0ed68bc3955b0d4d4a126db5ca4d429eb4a", + "zh:6636401b2463c25e03e68a6b786acf91a311c78444b1dc4f97c539f9f78de22a", + "zh:76858f9d8b460e7b2a338c477671d07286b0d287fd2d2e3214030ae8f61dd56e", + "zh:a13b69fb43cb8746793b3069c4d897bb18f454290b496f19d03c3387d1c9a2dc", + "zh:a90ca81bb9bb509063b736842250ecff0f886a91baae8de65c8430168001dad9", + "zh:c4de401395936e41234f1956ebadbd2ed9f414e6908f27d578614aaa529870d4", + "zh:c657e121af8fde19964482997f0de2d5173217274f6997e16389e7707ed8ece8", + "zh:d68b07a67fbd604c38ec9733069fbf23441436fecf554de6c75c032f82e1ef19", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/eks/README.md b/eks/README.md new file mode 100644 index 0000000..aa3b628 --- /dev/null +++ b/eks/README.md @@ -0,0 +1,30 @@ +# Deploy on EKS with Terraform + +How to run Knot on AWS's EKS with [Terraform](https://www.terraform.io): +```bash +terraform apply # Create the EKS cluster +aws eks --region us-east-1 update-kubeconfig --name tf-cluster # Connect to it +``` + +You should now be able to run `kubectl get pods -A` and see the cluster's pods with no errors. + +Install Knot: +```bash +export KNOT_HOST=example.com # $env:KNOT_HOST="example.com" in Windows +helmfile -f git::https://github.com/CARV-ICS-FORTH/knot.git@helmfile.yaml sync --concurrency 1 +``` + +Now you need to go to Route53's console, create a hosted zone for your DNS name and two records that point to Knot's ingress: `example.com` and `*.example.com`. + +The screenshot below shows an example DNS entry. + +![Example Route53 DNS entry](assets/example-dns.png) + +For each record, make sure that: +- Record type is `A`. +- Alias is on. +- Type is `Alias to Network Load Balancer`. +- Area is `US East (N. Virginia)` (or your preferred region). +- You select Knot's ingress service. + +Now wait for the DNS settings to propagate. After a while you should be able to visit Knot in your browser. diff --git a/eks/assets/example-dns.png b/eks/assets/example-dns.png new file mode 100644 index 0000000..155ac9d Binary files /dev/null and b/eks/assets/example-dns.png differ diff --git a/eks/backend.tf b/eks/backend.tf new file mode 100644 index 0000000..6656fba --- /dev/null +++ b/eks/backend.tf @@ -0,0 +1,9 @@ +# terraform { +# required_version = ">=0.12.0" +# backend "s3" { +# region = "us-east-1" +# profile = "default" +# key = "terraformstatefile" +# bucket = "" +# } +# } diff --git a/eks/main.tf b/eks/main.tf new file mode 100644 index 0000000..d7cd331 --- /dev/null +++ b/eks/main.tf @@ -0,0 +1,41 @@ +################################################################################ +# VPC Module +################################################################################ + +module "vpc" { + source = "./modules/vpc" + + main-region = var.main-region + profile = var.profile +} + +################################################################################ +# EKS Cluster Module +################################################################################ + +module "eks" { + source = "./modules/eks-cluster" + + main-region = var.main-region + profile = var.profile + rolearn = var.rolearn + + vpc_id = module.vpc.vpc_id + private_subnets = module.vpc.private_subnets +} + +################################################################################ +# AWS ALB Controller +################################################################################ + +module "aws_alb_controller" { + source = "./modules/aws-alb-controller" + + main-region = var.main-region + env_name = var.env_name + cluster_name = var.cluster_name + + vpc_id = module.vpc.vpc_id + oidc_provider_arn = module.eks.oidc_provider_arn +} + diff --git a/eks/modules/aws-alb-controller/main.tf b/eks/modules/aws-alb-controller/main.tf new file mode 100644 index 0000000..06184db --- /dev/null +++ b/eks/modules/aws-alb-controller/main.tf @@ -0,0 +1,81 @@ +################################################################################ +# Load Balancer Role +################################################################################ + +module "lb_role" { + source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks" + + role_name = "${var.env_name}_eks_lb" + attach_load_balancer_controller_policy = true + + oidc_providers = { + main = { + provider_arn = var.oidc_provider_arn + namespace_service_accounts = ["kube-system:aws-load-balancer-controller"] + } + } +} + +################################################################################ +# Aws Load balancer Controller Service Account +################################################################################ + +resource "kubernetes_service_account" "service-account" { + metadata { + name = "aws-load-balancer-controller" + namespace = "kube-system" + labels = { + "app.kubernetes.io/name" = "aws-load-balancer-controller" + "app.kubernetes.io/component" = "controller" + } + annotations = { + "eks.amazonaws.com/role-arn" = module.lb_role.iam_role_arn + "eks.amazonaws.com/sts-regional-endpoints" = "true" + } + } +} + +################################################################################ +# Install Load Balancer Controler With Helm +################################################################################ + +resource "helm_release" "lb" { + name = "aws-load-balancer-controller" + repository = "https://aws.github.io/eks-charts" + chart = "aws-load-balancer-controller" + namespace = "kube-system" + depends_on = [ + kubernetes_service_account.service-account + ] + + set { + name = "region" + value = var.main-region + } + + set { + name = "vpcId" + value = var.vpc_id + } + + set { + name = "image.repository" + value = "602401143452.dkr.ecr.${var.main-region}.amazonaws.com/amazon/aws-load-balancer-controller" + } + + set { + name = "serviceAccount.create" + value = "false" + } + + set { + name = "serviceAccount.name" + value = "aws-load-balancer-controller" + } + + set { + name = "clusterName" + value = var.cluster_name + } +} + diff --git a/eks/modules/aws-alb-controller/variables.tf b/eks/modules/aws-alb-controller/variables.tf new file mode 100644 index 0000000..19e427f --- /dev/null +++ b/eks/modules/aws-alb-controller/variables.tf @@ -0,0 +1,29 @@ +################################################################################ +# General Variables from root module +################################################################################ + +variable "main-region" { + type = string +} + +variable "env_name" { + type = string +} + +variable "cluster_name" { + type = string +} + +################################################################################ +# Variables from other Modules +################################################################################ + +variable "vpc_id" { + description = "VPC ID which Load balancers will be deployed in" + type = string +} + +variable "oidc_provider_arn" { + description = "OIDC Provider ARN used for IRSA " + type = string +} diff --git a/eks/modules/eks-cluster/main.tf b/eks/modules/eks-cluster/main.tf new file mode 100644 index 0000000..0818110 --- /dev/null +++ b/eks/modules/eks-cluster/main.tf @@ -0,0 +1,82 @@ +################################################################################ +# EKS Cluster +################################################################################ + +module "eks" { + source = "terraform-aws-modules/eks/aws" + version = "~> 19.0" + + cluster_name = "tf-cluster" + cluster_version = "1.27" + + providers = { + aws = aws.us-east-1 + } + + cluster_endpoint_public_access = true + + create_kms_key = false + create_cloudwatch_log_group = false + cluster_encryption_config = {} + + cluster_addons = { + coredns = { + most_recent = true + } + kube-proxy = { + most_recent = true + } + vpc-cni = { + most_recent = true + } + aws-ebs-csi-driver = { + most_recent = true + } + } + + vpc_id = var.vpc_id + subnet_ids = var.private_subnets + control_plane_subnet_ids = var.private_subnets + + # EKS Managed Node Group(s) + eks_managed_node_group_defaults = { + instance_types = ["m5.xlarge", "m5.large", "t3.medium"] + iam_role_additional_policies = { + AmazonEBSCSIDriverPolicy = "arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy" + } + } + + eks_managed_node_groups = { + blue = { + min_size = 1 + max_size = 10 + desired_size = 3 + } + green = { + min_size = 1 + max_size = 10 + desired_size = 3 + + instance_types = ["t3.medium"] + capacity_type = "ON_DEMAND" + } + } + + # aws-auth configmap + # manage_aws_auth_configmap = true + #create_aws_auth_configmap = true + + aws_auth_roles = [ + { + rolearn = var.rolearn + username = "skanyi" + groups = ["system:masters"] + }, + ] + + tags = { + env = "dev" + terraform = "true" + } +} + diff --git a/eks/modules/eks-cluster/outputs.tf b/eks/modules/eks-cluster/outputs.tf new file mode 100644 index 0000000..ec2f17a --- /dev/null +++ b/eks/modules/eks-cluster/outputs.tf @@ -0,0 +1,68 @@ +################################################################################ +# Cluster +################################################################################ + +output "cluster_arn" { + description = "The Amazon Resource Name (ARN) of the cluster" + value = module.eks.cluster_arn +} + +output "cluster_certificate_authority_data" { + description = "Base64 encoded certificate data required to communicate with the cluster" + value = module.eks.cluster_certificate_authority_data +} + +output "cluster_endpoint" { + description = "Endpoint for your Kubernetes API server" + value = module.eks.cluster_endpoint +} + +output "cluster_id" { + description = "The ID of the EKS cluster. Note: currently a value is returned only for local EKS clusters created on Outposts" + value = module.eks.cluster_id +} + +output "cluster_name" { + description = "The name of the EKS cluster" + value = module.eks.cluster_name +} + +output "cluster_oidc_issuer_url" { + description = "The URL on the EKS cluster for the OpenID Connect identity provider" + value = module.eks.cluster_oidc_issuer_url +} + +output "cluster_platform_version" { + description = "Platform version for the cluster" + value = module.eks.cluster_platform_version +} + +output "cluster_status" { + description = "Status of the EKS cluster. One of `CREATING`, `ACTIVE`, `DELETING`, `FAILED`" + value = module.eks.cluster_status +} + +output "cluster_security_group_id" { + description = "Cluster security group that was created by Amazon EKS for the cluster. Managed node groups use this security group for control-plane-to-data-plane communication. Referred to as 'Cluster security group' in the EKS console" + value = module.eks.cluster_security_group_id +} + +################################################################################ +# IRSA +################################################################################ + +output "oidc_provider" { + description = "The OpenID Connect identity provider (issuer URL without leading `https://`)" + value = module.eks.oidc_provider +} + +output "oidc_provider_arn" { + description = "The ARN of the OIDC Provider if `enable_irsa = true`" + value = module.eks.oidc_provider_arn +} + +output "cluster_tls_certificate_sha1_fingerprint" { + description = "The SHA1 fingerprint of the public key of the cluster's certificate" + value = module.eks.cluster_tls_certificate_sha1_fingerprint +} + diff --git a/eks/modules/eks-cluster/providers.tf b/eks/modules/eks-cluster/providers.tf new file mode 100644 index 0000000..f2644de --- /dev/null +++ b/eks/modules/eks-cluster/providers.tf @@ -0,0 +1,7 @@ + +provider "aws" { + profile = var.profile + region = var.main-region + alias = "us-east-1" +} + diff --git a/eks/modules/eks-cluster/variables.tf b/eks/modules/eks-cluster/variables.tf new file mode 100644 index 0000000..2cc56aa --- /dev/null +++ b/eks/modules/eks-cluster/variables.tf @@ -0,0 +1,34 @@ +################################################################################ +# General Variables from root module +################################################################################ + +variable "profile" { + type = string +} + +variable "main-region" { + type = string +} + +################################################################################ +# Variables from other Modules +################################################################################ + +variable "vpc_id" { + description = "VPC ID which EKS cluster is deployed in" + type = string +} + +variable "private_subnets" { + description = "VPC Private Subnets which EKS cluster is deployed in" + type = list(any) +} + +################################################################################ +# Variables defined using Environment Variables +################################################################################ + +variable "rolearn" { + description = "Add admin role to the aws-auth configmap" +} + diff --git a/eks/modules/vpc/main.tf b/eks/modules/vpc/main.tf new file mode 100644 index 0000000..f918678 --- /dev/null +++ b/eks/modules/vpc/main.tf @@ -0,0 +1,44 @@ +################################################################################ +# VPC Module +################################################################################ + + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "5.0.0" + + name = "eks-vpc" + cidr = "10.0.0.0/16" + + providers = { + aws = aws.us-east-1 + } + + azs = ["us-east-1a", "us-east-1b", "us-east-1c"] + #private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)] + #public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 4)] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + enable_nat_gateway = true + + public_subnet_tags = { + "kubernetes.io/role/elb" = 1 + } + + private_subnet_tags = { + "kubernetes.io/role/internal-elb" = 1 + } + + tags = { + Terraform = "true" + Environment = "dev" + } +} + + +################################################################################ +# VPC Endpoints Module +################################################################################ + +# Implement this later diff --git a/eks/modules/vpc/output.tf b/eks/modules/vpc/output.tf new file mode 100644 index 0000000..8cb061f --- /dev/null +++ b/eks/modules/vpc/output.tf @@ -0,0 +1,25 @@ +output "vpc_id" { + description = "The ID of the VPC" + value = module.vpc.vpc_id +} + +output "vpc_arn" { + description = "The ARN of the VPC" + value = module.vpc.vpc_arn +} + +output "private_subnets" { + description = "List of IDs of private subnets" + value = module.vpc.private_subnets +} + +output "private_subnet_arns" { + description = "List of ARNs of private subnets" + value = module.vpc.private_subnet_arns +} + +output "private_subnets_cidr_blocks" { + description = "List of cidr_blocks of private subnets" + value = module.vpc.private_subnets_cidr_blocks +} + diff --git a/eks/modules/vpc/providers.tf b/eks/modules/vpc/providers.tf new file mode 100644 index 0000000..f2644de --- /dev/null +++ b/eks/modules/vpc/providers.tf @@ -0,0 +1,7 @@ + +provider "aws" { + profile = var.profile + region = var.main-region + alias = "us-east-1" +} + diff --git a/eks/modules/vpc/variables.tf b/eks/modules/vpc/variables.tf new file mode 100644 index 0000000..817070e --- /dev/null +++ b/eks/modules/vpc/variables.tf @@ -0,0 +1,12 @@ +################################################################################ +# General Variables from root module +################################################################################ +variable "profile" { + type = string + default = "knot" +} + +variable "main-region" { + type = string + default = "us-east-1" +} diff --git a/eks/output.tf b/eks/output.tf new file mode 100644 index 0000000..41aafba --- /dev/null +++ b/eks/output.tf @@ -0,0 +1,42 @@ +################################################################################ +# EKS Cluster +################################################################################ + +output "cluster_arn" { + description = "The Amazon Resource Name (ARN) of the cluster" + value = module.eks.cluster_arn +} + +output "cluster_certificate_authority_data" { + description = "Base64 encoded certificate data required to communicate with the cluster" + value = module.eks.cluster_certificate_authority_data +} + +output "cluster_endpoint" { + description = "Endpoint for your Kubernetes API server" + value = module.eks.cluster_endpoint +} + +output "oidc_provider" { + description = "The OpenID Connect identity provider (issuer URL without leading `https://`)" + value = module.eks.oidc_provider +} + +output "oidc_provider_arn" { + description = "The ARN of the OIDC Provider if `enable_irsa = true`" + value = module.eks.oidc_provider_arn +} + +################################################################################ +# VPC +################################################################################ + +output "vpc_id" { + description = "The ID of the VPC" + value = module.vpc.vpc_id +} + +output "private_subnets" { + description = "List of IDs of private subnets" + value = module.vpc.private_subnets +} diff --git a/eks/providers.tf b/eks/providers.tf new file mode 100644 index 0000000..4d8820a --- /dev/null +++ b/eks/providers.tf @@ -0,0 +1,26 @@ +provider "aws" { + region = "us-east-1" +} + +provider "kubernetes" { + host = module.eks.cluster_endpoint + cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) + exec { + api_version = "client.authentication.k8s.io/v1beta1" + command = "aws" + # This requires the awscli to be installed locally where Terraform is executed + args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name] + } +} + +provider "helm" { + kubernetes { + host = module.eks.cluster_endpoint + cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) + exec { + api_version = "client.authentication.k8s.io/v1beta1" + args = ["eks", "get-token", "--cluster-name", var.cluster_name] + command = "aws" + } + } +} diff --git a/eks/variables.tf b/eks/variables.tf new file mode 100644 index 0000000..240223c --- /dev/null +++ b/eks/variables.tf @@ -0,0 +1,38 @@ + +################################################################################ +# Default Variables +################################################################################ + +variable "profile" { + type = string + default = "default" +} + +variable "main-region" { + type = string + default = "us-east-1" +} + + +################################################################################ +# EKS Cluster Variables +################################################################################ + +variable "cluster_name" { + type = string + default = "tf-cluster" +} + +variable "rolearn" { + description = "Add admin role to the aws-auth configmap" +} + +################################################################################ +# ALB Controller Variables +################################################################################ + +variable "env_name" { + type = string + default = "dev" +} +