From dd912fad8ea07191a71e95a7111cbbd8061920a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= <32740567+jrmanes@users.noreply.github.com> Date: Thu, 25 May 2023 13:56:01 +0200 Subject: [PATCH] feat: load variables from script and cleanup vars (#94) * feat: add values.sh - rename vars * feat: load vars from delete.sh --- k8s/kops/delete_kops.sh | 12 ++++++++++++ k8s/kops/install_k8s.sh | 10 ++++++++++ k8s/kops/values.sh | 27 +++++++++++++++++++++++++++ terraform/README.md | 2 +- terraform/backend.tf | 2 +- terraform/kops-resources/.gitignore | 2 ++ terraform/kops-resources/backend.tf | 2 +- terraform/kops-resources/main.tf | 3 +-- 8 files changed, 55 insertions(+), 5 deletions(-) create mode 100755 k8s/kops/values.sh create mode 100644 terraform/kops-resources/.gitignore diff --git a/k8s/kops/delete_kops.sh b/k8s/kops/delete_kops.sh index 29a1c83b..73653ae7 100755 --- a/k8s/kops/delete_kops.sh +++ b/k8s/kops/delete_kops.sh @@ -5,7 +5,9 @@ set -o pipefail set -x set -e +# ======================================================= TF_RESOURCES="../../terraform/kops-resources/" +# ======================================================= err_report() { echo "Error on line $1" @@ -13,6 +15,16 @@ err_report() { trap 'err_report $LINENO' ERR +# ======================================================= + +# Load values form the file +if [ -f ./values.sh ];then + source ./values.sh +else + echo "[ERROR] Please, you need to fill the values in the script [values.sh]" + exit 1 +fi + # ======================================================= echo "Create EFS resources & storageclasses..." cd ${TF_RESOURCES} diff --git a/k8s/kops/install_k8s.sh b/k8s/kops/install_k8s.sh index 224ed61f..371d1bd1 100755 --- a/k8s/kops/install_k8s.sh +++ b/k8s/kops/install_k8s.sh @@ -38,6 +38,16 @@ err_report() { trap 'err_report $LINENO' ERR # ======================================================= START_TIME=`date +%s` +# ======================================================= + +# Load values form the file +if [ -f ./values.sh ];then + source ./values.sh +else + echo "[ERROR] Please, you need to fill the values in the script [values.sh]" + exit 1 +fi + # ======================================================= echo "Creating cluster for Testground..." echo diff --git a/k8s/kops/values.sh b/k8s/kops/values.sh new file mode 100755 index 00000000..58f930e7 --- /dev/null +++ b/k8s/kops/values.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# ======================================================= +# Description: +# This script is used to load the values. +# ======================================================= + +export CLUSTER_NAME= +export DEPLOYMENT_NAME= +export WORKER_NODE_TYPE= +export MASTER_NODE_TYPE= +export MIN_WORKER_NODES= +export MAX_WORKER_NODES= +export TEAM= +export PROJECT= +export AWS_REGION= +export KOPS_STATE_STORE=s3:// +export ZONE_A= +export ZONE_B= +export PUBKEY= +export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id) +export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key) + +# Node types -> https://aws.amazon.com/es/ec2/instance-types/ +# c5.2xlarge # 8CPU/16RAM +# c5.4xlarge # 16CPU/32RAM +# c5.9xlarge # 36CPU/72RAM +# c5a.24xlarge # 96CPU/192RAM diff --git a/terraform/README.md b/terraform/README.md index 0bc20241..5daa3db6 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -1,3 +1,3 @@ -# tf-testground +# Terraform TestGround We are deploying the resources in the region `eu-west-1` because is the one that has more resources available. diff --git a/terraform/backend.tf b/terraform/backend.tf index 6c585b66..ea13680b 100644 --- a/terraform/backend.tf +++ b/terraform/backend.tf @@ -1,7 +1,7 @@ terraform { backend "s3" { bucket = "testground-terraform-state" - key = "devops-2-tg" + key = "testground.k8s.local" region = "eu-west-1" } } diff --git a/terraform/kops-resources/.gitignore b/terraform/kops-resources/.gitignore new file mode 100644 index 00000000..c035e729 --- /dev/null +++ b/terraform/kops-resources/.gitignore @@ -0,0 +1,2 @@ +.terraform +.terraform.lock.hcl diff --git a/terraform/kops-resources/backend.tf b/terraform/kops-resources/backend.tf index 48a12d72..ea13680b 100644 --- a/terraform/kops-resources/backend.tf +++ b/terraform/kops-resources/backend.tf @@ -1,7 +1,7 @@ terraform { backend "s3" { bucket = "testground-terraform-state" - key = "jose.k8s.local-tf-state-devops-tg" + key = "testground.k8s.local" region = "eu-west-1" } } diff --git a/terraform/kops-resources/main.tf b/terraform/kops-resources/main.tf index 77bb9e9d..3ecd5c22 100644 --- a/terraform/kops-resources/main.tf +++ b/terraform/kops-resources/main.tf @@ -3,8 +3,7 @@ //################################################################################ locals { region = "eu-west-1" - //project_name = "testground-devops-k8s-local" - project_name = "tgdevops-k8s-local" + project_name = "testground-k8s-local" azs = ["${local.region}a", "${local.region}b"] vpc_id = data.aws_vpc.selected.id