agones.dev/agones@v1.53.0/install/terraform/modules/eks/eks.tf (about)

     1  # Copyright 2020 Google LLC All Rights Reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  
    16  terraform {
    17    required_version = ">= 1.0.0"
    18    required_providers {
    19      aws = {
    20        source  = "hashicorp/aws"
    21        version = "~> 3.0"
    22      }
    23    }
    24  }
    25  
    26  provider "aws" {
    27    region  = var.region
    28  }
    29  
    30  data "aws_availability_zones" "available" {
    31  }
    32  
    33  data "aws_eks_cluster" "eks" {
    34    name = module.eks.cluster_id
    35  }
    36  
    37  data "aws_eks_cluster_auth" "eks" {
    38    name = module.eks.cluster_id
    39  }
    40  
    41  provider "kubernetes" {
    42    host                   = data.aws_eks_cluster.eks.endpoint
    43    cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks.certificate_authority[0].data)
    44    token                  = data.aws_eks_cluster_auth.eks.token
    45  }
    46  
    47  resource "aws_security_group" "worker_group_mgmt_one" {
    48    name_prefix = "worker_group_mgmt_one"
    49    vpc_id      = module.vpc.vpc_id
    50  
    51    ingress {
    52      from_port = 22
    53      to_port   = 22
    54      protocol  = "tcp"
    55  
    56      cidr_blocks = [
    57        "10.0.0.0/8",
    58      ]
    59    }
    60    ingress {
    61      from_port = 7000
    62      to_port   = 8000
    63      protocol  = "udp"
    64  
    65      cidr_blocks = [
    66        "0.0.0.0/0",
    67      ]
    68    }
    69  
    70    egress {
    71      from_port   = 0
    72      to_port     = 0
    73      protocol    = "-1"
    74      cidr_blocks = ["0.0.0.0/0"]
    75    }
    76  }
    77  
    78  module "vpc" {
    79    source  = "terraform-aws-modules/vpc/aws"
    80    version = "~> 3.0"
    81  
    82    name                 = "test-vpc-lt"
    83    cidr                 = "10.0.0.0/16"
    84    azs                  = data.aws_availability_zones.available.names
    85    public_subnets       = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
    86    enable_dns_hostnames = false
    87  
    88    tags = {
    89      "kubernetes.io/cluster/${var.cluster_name}" = "shared"
    90    }
    91  
    92    public_subnet_tags = {
    93      "kubernetes.io/cluster/${var.cluster_name}" = "shared"
    94      "kubernetes.io/role/elb"                    = "1"
    95    }
    96  }
    97  
    98  module "eks" {
    99    source          = "git::github.com/terraform-aws-modules/terraform-aws-eks.git?ref=v17.22.0"
   100    cluster_name    = var.cluster_name
   101    subnets         = module.vpc.public_subnets
   102    vpc_id          = module.vpc.vpc_id
   103    cluster_version = "1.33"
   104  
   105    worker_groups_launch_template = [
   106      {
   107        name                          = "default"
   108        instance_type                 = var.machine_type
   109        asg_desired_capacity          = var.node_count
   110        asg_min_size                  = var.node_count
   111        asg_max_size                  = var.node_count
   112        additional_security_group_ids = [aws_security_group.worker_group_mgmt_one.id]
   113        public_ip                     = true
   114      },
   115      // Node Pools with taints for metrics and system
   116      {
   117        name                 = "agones-system"
   118        instance_type        = var.machine_type
   119        asg_desired_capacity = 1
   120        kubelet_extra_args   = "--node-labels=agones.dev/agones-system=true --register-with-taints=agones.dev/agones-system=true:NoExecute"
   121        public_ip            = true
   122      },
   123      {
   124        name                 = "agones-metrics"
   125        instance_type        = var.machine_type
   126        asg_desired_capacity = 1
   127        kubelet_extra_args   = "--node-labels=agones.dev/agones-metrics=true --register-with-taints=agones.dev/agones-metrics=true:NoExecute"
   128        public_ip            = true
   129      }
   130    ]
   131  }