Skip to content

Commit

Permalink
Updated the base Terraform template
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismld authored and nadaahm committed Mar 13, 2023
1 parent 937c196 commit 51d3e05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ terraform {
}
}

provider "aws" {
region = local.region
}

provider "kubernetes" {
host = module.eks_blueprints.eks_cluster_endpoint
cluster_ca_certificate = base64decode(module.eks_blueprints.eks_cluster_certificate_authority_data)
Expand Down Expand Up @@ -49,9 +53,10 @@ data "aws_ami" "amazonlinux2eks" {
data "aws_availability_zones" "available" {}

locals {
name = "eksspotworkshop"
name = "eksspotworkshop"
region = "--AWS_REGION--"

cluster_version = "1.24"
cluster_version = "--EKS_VERSION--"

vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
Expand Down Expand Up @@ -109,18 +114,15 @@ module "eks_blueprints" {
managed_node_groups = {
# Managed Node groups with minimum config
mg5 = {
node_group_name = "mng-od-m5large"
node_group_name = "mg5"
instance_types = ["m5.large"]
max_size = 3
desired_size = 2
min_size = 0
create_iam_role = false
min_size = 2
create_iam_role = false # Changing `create_iam_role=false` to bring your own IAM Role
iam_role_arn = aws_iam_role.managed_ng.arn
disk_size = 100
disk_size = 100 # Disk size is used only with Managed Node Groups without Launch Templates
update_config = [{
max_unavailable_percentage = 30
}]
launch_template_os = "amazonlinux2eks"

k8s_labels = {
intent = "control-apps"
Expand All @@ -130,6 +132,8 @@ module "eks_blueprints" {
// ### -->> SPOT NODE GROUPS GO HERE <<--- ###
}

// ### -->> SPOT SELF-MANAGED NODE GROUPS GO HERE <<--- ###

tags = local.tags
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation template to create a Cloud9 environment setup with kubectl, eksctl and an EKS cluster with a managed node group. Please allow ~20min for the EKS cluster to be ready.
Metadata:
Author:
Description: Sandeep Palavalasa <palavas@amazon.com>
Description: Carlos Rueda <ruecarlo@amazon.com>
License:
Description: 'Copyright 2020 Amazon.com, Inc. and its affiliates. All Rights Reserved.
Expand All @@ -20,29 +20,30 @@ Parameters:
C9InstanceType:
Description: Example Cloud9 instance type
Type: String
Default: t2.micro
Default: t3.micro
AllowedValues:
- t2.micro
- t3.micro
- m5.large
ConstraintDescription: Must be a valid Cloud9 instance type
C9KubectlVersion:
Description: Cloud9 instance kubectl version
Type: String
Default: v1.21.2
Default: v1.23.7
ConstraintDescription: Must be a valid kubectl version
C9KubectlVersionTEST:
Description: Cloud9 instance kubectl version
Type: String
Default: v1.21.2
Default: v1.23.7
ConstraintDescription: Must be a valid kubectl version
C9EKSctlVersion:
Description: Cloud9 instance eksctl version
Type: String
Default: v0.68.0
Default: v0.110.0
ConstraintDescription: Must be a valid eksctl version
EKSClusterVersion:
Description: EKS Cluster Version
Type: String
Default: 1.21
Default: 1.24
ConstraintDescription: Must be a valid eks version
EKSClusterName:
Description: EKS Cluster Name
Expand Down Expand Up @@ -269,18 +270,18 @@ Resources:
- echo '=== Generate SSH key and import to aws ==='
- sudo -H -u ec2-user ssh-keygen -f /home/ec2-user/.ssh/id_rsa1 -P ''
- sudo -H -u ec2-user aws ec2 import-key-pair --key-name "eksworkshop" --public-key-material file:///home/ec2-user/.ssh/id_rsa1.pub
- echo '=== Install EKSCTL ==='
- !Sub 'export EKSCTL_VERSION=${C9EKSctlVersion}'
- sudo -H -u ec2-user curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/${EKSCTL_VERSION}/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
- sudo mv -v /tmp/eksctl /usr/local/bin
- sudo -H -u ec2-user /usr/local/bin/eksctl version
- echo '=== Create EKS Cluster ==='
- sudo -H -u ec2-user curl --silent --location -o /home/ec2-user/environment/eksworkshop.yaml "https://raw.githubusercontent.com/awslabs/ec2-spot-workshops/master/content/using_ec2_spot_instances_with_eks/010_prerequisites/prerequisites.files/eksworkshop.yaml"
- !Sub sed -i.bak -e 's/--AWS_REGION--/${AWS::Region}/' /home/ec2-user/environment/eksworkshop.yaml
- !Sub sed -i.bak -e 's/--AZA--/${AWS::Region}a/' /home/ec2-user/environment/eksworkshop.yaml
- !Sub sed -i.bak -e 's/--AZB--/${AWS::Region}b/' /home/ec2-user/environment/eksworkshop.yaml
- !Sub sed -i.bak -e 's/--EKS_VERSION--/"'"${EKSClusterVersion}"'"/' /home/ec2-user/environment/eksworkshop.yaml
- sudo -H -u ec2-user /usr/local/bin/eksctl create cluster -f /home/ec2-user/environment/eksworkshop.yaml
- echo '=== Install Terraform ==='
- sudo yum install -y yum-utils
- sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
- sudo yum -y install terraform-1.3.7-1
- echo '=== Create EKS Cluster ==='
- sudo -H -u ec2-user mkdir -p /home/ec2-user/environment/eksworkshop/
- sudo -H -u ec2-user curl --silent --location -o /home/ec2-user/environment/eksworkshop/main.tf "https://raw.githubusercontent.com/awslabs/ec2-spot-workshops/master/content/using_ec2_spot_instances_with_eks/010_prerequisites/prerequisites.files/eks-blueprints.tf"
- !Sub sed -i.bak -e 's/--AWS_REGION--/${AWS::Region}/' /home/ec2-user/environment/eksworkshop/main.tf
- !Sub sed -i.bak -e 's/--EKS_VERSION--/"'"${EKSClusterVersion}"'"/' /home/ec2-user/environment/eksworkshop/main.tf
- sudo -H -u ec2-user /usr/bin/terraform init
- sudo -H -u ec2-user /usr/bin/terraform apply --auto-approve
- $(sudo -H -u ec2-user /usr/bin/terraform output -raw configure_kubectl)
- sudo -H -u ec2-user /usr/local/bin/kubectl get nodes

C9BootstrapAssociation:
Expand Down

0 comments on commit 51d3e05

Please sign in to comment.