/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT-0 * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ terraform { required_version = ">= 1.0.1" required_providers { aws = { source = "hashicorp/aws" version = ">= 3.66.0" } kubernetes = { source = "hashicorp/kubernetes" version = ">= 2.7.1" } helm = { source = "hashicorp/helm" version = ">= 2.4.1" } } } provider "aws" { region = data.aws_region.current.id alias = "default" } terraform { backend "local" { path = "local_tf_state/terraform-main.tfstate" } } data "aws_region" "current" {} data "aws_availability_zones" "available" {} locals { tenant = "aws001" # AWS account name or unique id for tenant environment = "preprod" # Environment area eg., preprod or prod zone = "test" # Environment with in one sub_tenant or business unit kubernetes_version = "1.21" vpc_cidr = "10.0.0.0/16" vpc_name = join("-", [local.tenant, local.environment, local.zone, "vpc"]) cluster_name = join("-", [local.tenant, local.environment, local.zone, "eks"]) amazon_prometheus_workspace_alias = join("-", ["amp-workspace", local.tenant, local.environment, local.zone, "eks"]) terraform_version = "Terraform v1.0.1" } module "aws_vpc" { source = "terraform-aws-modules/vpc/aws" version = "v3.2.0" name = local.vpc_name cidr = local.vpc_cidr azs = data.aws_availability_zones.available.names public_subnets = [for k, v in slice(data.aws_availability_zones.available.names, 0, 3) : cidrsubnet(local.vpc_cidr, 8, k)] private_subnets = [for k, v in slice(data.aws_availability_zones.available.names, 0, 3) : cidrsubnet(local.vpc_cidr, 8, k + 10)] enable_nat_gateway = true create_igw = true enable_dns_hostnames = true single_nat_gateway = true public_subnet_tags = { "kubernetes.io/cluster/${local.cluster_name}" = "shared" "kubernetes.io/role/elb" = "1" } private_subnet_tags = { "kubernetes.io/cluster/${local.cluster_name}" = "shared" "kubernetes.io/role/internal-elb" = "1" } } #--------------------------------------------------------------- # Example to consume aws-eks-accelerator-for-terraform module #--------------------------------------------------------------- module "aws-eks-accelerator-for-terraform" { source = "github.com/aws-samples/aws-eks-accelerator-for-terraform" create_eks = true tenant = local.tenant environment = local.environment zone = local.zone terraform_version = local.terraform_version # EKS Cluster VPC and Subnet mandatory config vpc_id = module.aws_vpc.vpc_id private_subnet_ids = module.aws_vpc.private_subnets # EKS CONTROL PLANE VARIABLES kubernetes_version = local.kubernetes_version # EKS MANAGED NODE GROUPS managed_node_groups = { mg_4 = { node_group_name = "managed-ondemand" instance_types = ["m5.xlarge"] min_size = "3" subnet_ids = module.aws_vpc.private_subnets } } # Enable Amazon Managed Prometheus enable_amazon_prometheus = true #--------------------------------------- # ENABLE EMR ON EKS # 1. Creates namespace # 2. k8s role and role binding(emr-containers user) for the above namespace # 3. IAM role for the team execution role # 4. Update AWS_AUTH config map with emr-containers user and AWSServiceRoleForAmazonEMRContainers role # 5. Create a trust relationship between the job execution role and the identity of the EMR managed service account #--------------------------------------- enable_emr_on_eks = true emr_on_eks_teams = { data_team_a = { emr_on_eks_namespace = "emr-data-team-a" emr_on_eks_iam_role_name = "emr-eks-data-team-a" } data_team_b = { emr_on_eks_namespace = "emr-data-team-b" emr_on_eks_iam_role_name = "emr-eks-data-team-b" } } } module "addons" { source = "github.com/aws-samples/aws-eks-accelerator-for-terraform//modules/kubernetes-addons" eks_cluster_id = module.aws-eks-accelerator-for-terraform.eks_cluster_id #K8s Add-ons enable_metrics_server = true enable_cluster_autoscaler = true #--------------------------------------- # PROMETHEUS CONFIG #--------------------------------------- amazon_prometheus_workspace_id = module.aws-eks-accelerator-for-terraform.amazon_prometheus_workspace_id amazon_prometheus_ingest_iam_role_arn = module.aws-eks-accelerator-for-terraform.amazon_prometheus_ingest_iam_role_arn amazon_prometheus_ingest_service_account = module.aws-eks-accelerator-for-terraform.amazon_prometheus_ingest_service_account enable_prometheus = true # Optional Map value prometheus_helm_config = { name = "prometheus" # (Required) Release name. repository = "https://prometheus-community.github.io/helm-charts" # (Optional) Repository URL where to locate the requested chart. chart = "prometheus" # (Required) Chart name to be installed. version = "14.4.0" # (Optional) Specify the exact chart version to install. If this is not specified, the latest version is installed. namespace = "prometheus" # (Optional) The namespace to install the release into. Defaults to default values = [templatefile("${path.module}/helm_values/prometheus-values.yaml", { operating_system = "linux" })] } #--------------------------------------- # Vertical Pod Autoscaling #--------------------------------------- enable_vpa = true vpa_helm_config = { name = "vpa" # (Required) Release name. repository = "https://charts.fairwinds.com/stable" # (Optional) Repository URL where to locate the requested chart. chart = "vpa" # (Required) Chart name to be installed. version = "0.5.0" # (Optional) Specify the exact chart version to install. If this is not specified, the latest version is installed. namespace = "vpa-ns" # (Optional) The namespace to install the release into. Defaults to default values = [templatefile("${path.module}/helm_values/vpa-values.yaml", {})] } }