/* * 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.6.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" {} locals { tenant = "aws001" # AWS account name or unique id for tenant environment = "preprod" # Environment area eg., preprod or prod zone = "dev" # Environment with in one sub_tenant or business unit kubernetes_version = "1.21" vpc_cidr = "10.1.0.0/16" vpc_name = join("-", [local.tenant, local.environment, local.zone, "vpc"]) cluster_name = join("-", [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 = ["us-east-1a", "us-east-1b", "us-east-1c"] private_subnets = ["10.1.1.0/24", "10.1.2.0/24", "10.1.3.0/24"] public_subnets = ["10.1.11.0/24", "10.1.12.0/24", "10.1.13.0/24"] enable_nat_gateway = true create_igw = true enable_dns_hostnames = 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" { source = "github.com/aws-samples/aws-eks-accelerator-for-terraform" 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 create_eks = true kubernetes_version = local.kubernetes_version # Ensure AWS VPC CNI is used enable_vpc_cni_addon = true vpc_cni_addon_version = "v1.10.1-eksbuild.1" # MANAGED NODE GROUPS managed_node_groups = { mng_spot_medium = { node_group_name = "mng-spot-med" capacity_type = "SPOT" instance_types = ["t3.medium", "t3a.medium"] subnet_ids = module.aws_vpc.private_subnets desired_size = "2" disk_size = 30 } } # SELF-MANAGED NODE GROUPS # Enable Windows support enable_windows_support = true # default false self_managed_node_groups = { ng_od_windows = { node_group_name = "ng-od-windows" create_launch_template = true launch_template_os = "windows" instance_type = "m5n.large" subnet_ids = module.aws_vpc.private_subnets desired_size = "2" } } } module "kubernetes-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 # EKS Managed Add-ons enable_amazon_eks_vpc_cni = true }