From 371fe33564f098be195e943c7f925a02983bfc78 Mon Sep 17 00:00:00 2001 From: Ujstor Date: Sun, 16 Jun 2024 00:04:10 +0200 Subject: [PATCH] eks & var condition fix --- README.md | 2 -- global/ghAction/terraform.tf | 4 +++ global/ghAction/variables.tf | 2 +- .../cluster/asg-rolling-deploy/variables.tf | 15 ++++++++ modules/modules/eks-cluster/variables.tf | 14 -------- prod/data-stores/mysql/main.tf | 3 +- prod/services/eks-cluster/.terraform.lock.hcl | 34 +++++++++---------- prod/services/eks-cluster/main.tf | 6 ++-- .../hello-world-app/.terraform.lock.hcl | 34 +++++++++---------- prod/services/hello-world-app/main.tf | 7 ++-- stage/data-stores/mysql/main.tf | 3 +- stage/services/hello-world-app/main.tf | 8 ++--- stage/services/k8s/.terraform.lock.hcl | 23 +++++++++++++ stage/services/k8s/main.tf | 3 +- 14 files changed, 94 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 58409e0..22b4048 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,6 @@ aws eks update-kubeconfig --region --name │ ├── [ 930] main.tf │ ├── [ 259] outputs.tf │ ├── [ 374] terraform.tf -│ ├── [ 0] terraform.tfstate -│ ├── [6.7K] terraform.tfstate.backup │ └── [ 330] variables.tf ├── [4.0K] modules/ │ ├── [4.0K] examples/ diff --git a/global/ghAction/terraform.tf b/global/ghAction/terraform.tf index 058b1a9..dca30d8 100644 --- a/global/ghAction/terraform.tf +++ b/global/ghAction/terraform.tf @@ -11,5 +11,9 @@ terraform { source = "hashicorp/aws" version = "5.50.0" } + tls = { + source = "hashicorp/tls" + version = "4.0.5" + } } } diff --git a/global/ghAction/variables.tf b/global/ghAction/variables.tf index 3fb9b33..6703068 100644 --- a/global/ghAction/variables.tf +++ b/global/ghAction/variables.tf @@ -8,7 +8,7 @@ variable "allowed_repos_branches" { default = [ { org = "ujstor" - repo = "aws-asg-tf" + repo = "aws-terrafrom" branch = "master" } ] diff --git a/modules/modules/cluster/asg-rolling-deploy/variables.tf b/modules/modules/cluster/asg-rolling-deploy/variables.tf index 477e33d..1c7926e 100644 --- a/modules/modules/cluster/asg-rolling-deploy/variables.tf +++ b/modules/modules/cluster/asg-rolling-deploy/variables.tf @@ -11,16 +11,31 @@ variable "image_id" { variable "instance_type" { description = "The type of instance to start" type = string + + validation { + condition = contains(["t2.micro", "t3.micro"], var.instance_type) + error_message = "Only free tier instances are supported | t2.micro, t3.micro" + } } variable "min_size" { description = "The minimum size of the Auto Scaling group" type = number + + validation { + condition = var.min_size > 0 + error_message = "ASG can be empty or we'll have an outage!" + } } variable "max_size" { description = "The maximum size of the Auto Scaling group" type = number + + validation { + condition = var.max_size <= 10 + error_message = "ASG must have 10 or less instances to keep costs down" + } } variable "custom_tags" { diff --git a/modules/modules/eks-cluster/variables.tf b/modules/modules/eks-cluster/variables.tf index 2344473..627e55d 100644 --- a/modules/modules/eks-cluster/variables.tf +++ b/modules/modules/eks-cluster/variables.tf @@ -7,15 +7,6 @@ variable "min_size" { description = "Minimum number of nodes to have in the EKS cluster" type = number - validation { - condition = var.min_size > 0 - error_message = "ASG can be empty or we'll have an outage!" - } - - validation { - condition = var.max_size <= 10 - error_message = "ASG must have 10 or less instances to keep costs down" - } } variable "max_size" { @@ -31,9 +22,4 @@ variable "desired_size" { variable "instance_types" { description = "The types of EC2 instances to run in the node group" type = list(string) - - validation { - condition = contains(["t2.micro", "t3.micro"], var.instance_types) - error_message = "Only free tier instances are supported | t2.micro, t3.micro" - } } diff --git a/prod/data-stores/mysql/main.tf b/prod/data-stores/mysql/main.tf index 19f9ea6..de45045 100644 --- a/prod/data-stores/mysql/main.tf +++ b/prod/data-stores/mysql/main.tf @@ -1,5 +1,6 @@ module "mysql_primary" { - source = "../../../modules/modules/data-stores/mysql/" + source = "github.com/ujstor/aws-terraform//modules/modules/data-stores/mysql?ref=v0.1.3" + # source = "../../../modules/modules/data-stores/mysql/" providers = { aws = aws.primary diff --git a/prod/services/eks-cluster/.terraform.lock.hcl b/prod/services/eks-cluster/.terraform.lock.hcl index 18e1167..14c43ec 100644 --- a/prod/services/eks-cluster/.terraform.lock.hcl +++ b/prod/services/eks-cluster/.terraform.lock.hcl @@ -2,25 +2,25 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "5.50.0" - constraints = "5.50.0" + version = "5.54.1" + constraints = "~> 5.0" hashes = [ - "h1:OE1Q924lUL15OytvxwkdIspPsLRe0m2044W55j3lihE=", - "zh:19be42f5a545d6712dee4bdb704b018d23bacf5d902ac3cb061eb1750dfe6a20", - "zh:1d880bdba95ce96efde37e5bcf457a57df2c1effa9b47bc67fa29c1a264ae53b", - "zh:1e9c78e324d7492be5e7744436ed71d66fe4eca3fb6af07a28efd0d1e3bf7640", - "zh:27ac672aa61b3795931561fdbe4a306ad1132af517d7711c14569429b2cc694f", - "zh:3b978423dead02f9a98d25de118adf264a2331acdc4550ea93bed01feabc12e7", - "zh:490d7eb4b922ba1b57e0ab8dec1a08df6517485febcab1e091fd6011281c3472", - "zh:64e7c84e18dac1af5778d6f516e01a46f9c91d710867c39fbc7efa3cd972dc62", - "zh:73867ac2956dcdd377121b3aa8fe2e1085e77fae9b61d018f56a863277ea4b6e", - "zh:7ed899d0d5c49f009b445d7816e4bf702d9c48205c24cf884cd2ae0247160455", + "h1:SOdZNOAcBvbrkV6V1S7UiGh9K//O66qfyXpHgyXeBeI=", + "zh:37c09b9a0a0a2f7854fe52c6adb15f71593810b458a8283ed71d68036af7ba3a", + "zh:42fe11d87723d4e43b9c6224ae6bacdcb53faee8abc58f0fc625a161d1f71cb1", + "zh:57c6dfc46f28c9c2737559bd84acbc05aeae90431e731bb72a0024028a2d2412", + "zh:5ba9665a4ca0e182effd75575b19a4d47383ec02662024b9fe26f78286c36619", "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", - "zh:9b93784b3fb13d08cf95a4131c49b56bf7e1cd35daad6156b3658a89ce6fb58f", - "zh:b29d77eb75de474e46eb47e539c48916628d85599bcf14e5cc500b14a4578e75", - "zh:bbd9cec8ca705452e4a3d21d56474eacb8cc7b1b74b7f310fdea4bdcffebab32", - "zh:c352eb3169efa0e27a29b99a2630e8298710a084453c519caa39e5972ff6d1fc", - "zh:e32f4744b43be1708b309a734e0ac10b5c0f9f92e5849298cf1a90f2b906f6f3", + "zh:b55980be0237644123a02a30b56d4cc03863ef29036c47d6e8ab5429ab45adf5", + "zh:b81e7664f10855a3a6fc234a18b4c4f1456273126a40c41516f2061696fb9870", + "zh:bd09736ffafd92af104c3c34b5add138ae8db4402eb687863ce472ca7e5ff2e2", + "zh:cc2eb1c62fba2a11d1f239e650cc2ae94bcab01c907384dcf2e213a6ee1bd5b2", + "zh:e5dc40205d9cf6f353c0ca532ae29afc6c83928bc9bcca47d74b640d3bb5a38c", + "zh:ebf1acdcd13f10db1b9c85050ddaadc70ab269c47c5a240753362446442d8371", + "zh:f2fc28a4ad94af5e6144a7309286505e3eb7a94d9dc106722b506c372ff7f591", + "zh:f49445e8435944df122aa89853260a2716ba8b73d6a6a70cae1661554926d5a2", + "zh:fc3b5046e60ae7cab20715be23de8436eb12736136fd6d0f0cc1549ebda6cc73", + "zh:fdb98a53500e245a3b5bec077b994da6959dba8fc4eb7534528658d820e06bd5", ] } diff --git a/prod/services/eks-cluster/main.tf b/prod/services/eks-cluster/main.tf index 08ae9d9..f828b1e 100644 --- a/prod/services/eks-cluster/main.tf +++ b/prod/services/eks-cluster/main.tf @@ -1,5 +1,6 @@ module "eks_cluster" { - source = "../../../modules/modules/eks-cluster/" + source = "github.com/ujstor/aws-terraform//modules/modules/eks-cluster?ref=v0.1.3" + # source = "../../../modules/modules/eks-cluster/" name = "example-eks-cluster" min_size = 3 max_size = 6 @@ -9,7 +10,8 @@ module "eks_cluster" { } module "simple_webapp" { - source = "../../../modules/services/k8s" + source = "github.com/ujstor/aws-terraform//modules/modules/k8s?ref=v0.1.3" + # source = "../../../modules/modules/k8s" name = "portfolio-webapp" image = "ujstor/portfolio-web-go:1.2.0" diff --git a/prod/services/hello-world-app/.terraform.lock.hcl b/prod/services/hello-world-app/.terraform.lock.hcl index 04d6a5b..fe5a966 100644 --- a/prod/services/hello-world-app/.terraform.lock.hcl +++ b/prod/services/hello-world-app/.terraform.lock.hcl @@ -2,24 +2,24 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "5.50.0" - constraints = "5.50.0" + version = "5.54.1" + constraints = "~> 5.0" hashes = [ - "h1:OE1Q924lUL15OytvxwkdIspPsLRe0m2044W55j3lihE=", - "zh:19be42f5a545d6712dee4bdb704b018d23bacf5d902ac3cb061eb1750dfe6a20", - "zh:1d880bdba95ce96efde37e5bcf457a57df2c1effa9b47bc67fa29c1a264ae53b", - "zh:1e9c78e324d7492be5e7744436ed71d66fe4eca3fb6af07a28efd0d1e3bf7640", - "zh:27ac672aa61b3795931561fdbe4a306ad1132af517d7711c14569429b2cc694f", - "zh:3b978423dead02f9a98d25de118adf264a2331acdc4550ea93bed01feabc12e7", - "zh:490d7eb4b922ba1b57e0ab8dec1a08df6517485febcab1e091fd6011281c3472", - "zh:64e7c84e18dac1af5778d6f516e01a46f9c91d710867c39fbc7efa3cd972dc62", - "zh:73867ac2956dcdd377121b3aa8fe2e1085e77fae9b61d018f56a863277ea4b6e", - "zh:7ed899d0d5c49f009b445d7816e4bf702d9c48205c24cf884cd2ae0247160455", + "h1:SOdZNOAcBvbrkV6V1S7UiGh9K//O66qfyXpHgyXeBeI=", + "zh:37c09b9a0a0a2f7854fe52c6adb15f71593810b458a8283ed71d68036af7ba3a", + "zh:42fe11d87723d4e43b9c6224ae6bacdcb53faee8abc58f0fc625a161d1f71cb1", + "zh:57c6dfc46f28c9c2737559bd84acbc05aeae90431e731bb72a0024028a2d2412", + "zh:5ba9665a4ca0e182effd75575b19a4d47383ec02662024b9fe26f78286c36619", "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", - "zh:9b93784b3fb13d08cf95a4131c49b56bf7e1cd35daad6156b3658a89ce6fb58f", - "zh:b29d77eb75de474e46eb47e539c48916628d85599bcf14e5cc500b14a4578e75", - "zh:bbd9cec8ca705452e4a3d21d56474eacb8cc7b1b74b7f310fdea4bdcffebab32", - "zh:c352eb3169efa0e27a29b99a2630e8298710a084453c519caa39e5972ff6d1fc", - "zh:e32f4744b43be1708b309a734e0ac10b5c0f9f92e5849298cf1a90f2b906f6f3", + "zh:b55980be0237644123a02a30b56d4cc03863ef29036c47d6e8ab5429ab45adf5", + "zh:b81e7664f10855a3a6fc234a18b4c4f1456273126a40c41516f2061696fb9870", + "zh:bd09736ffafd92af104c3c34b5add138ae8db4402eb687863ce472ca7e5ff2e2", + "zh:cc2eb1c62fba2a11d1f239e650cc2ae94bcab01c907384dcf2e213a6ee1bd5b2", + "zh:e5dc40205d9cf6f353c0ca532ae29afc6c83928bc9bcca47d74b640d3bb5a38c", + "zh:ebf1acdcd13f10db1b9c85050ddaadc70ab269c47c5a240753362446442d8371", + "zh:f2fc28a4ad94af5e6144a7309286505e3eb7a94d9dc106722b506c372ff7f591", + "zh:f49445e8435944df122aa89853260a2716ba8b73d6a6a70cae1661554926d5a2", + "zh:fc3b5046e60ae7cab20715be23de8436eb12736136fd6d0f0cc1549ebda6cc73", + "zh:fdb98a53500e245a3b5bec077b994da6959dba8fc4eb7534528658d820e06bd5", ] } diff --git a/prod/services/hello-world-app/main.tf b/prod/services/hello-world-app/main.tf index 92fb907..db9b92f 100644 --- a/prod/services/hello-world-app/main.tf +++ b/prod/services/hello-world-app/main.tf @@ -1,16 +1,15 @@ module "webserver_cluster" { - source = "../../../modules/modules/services/hello-world-app" + source = "github.com/ujstor/aws-terraform//modules/modules/services/hello-world-app?ref=v0.1.3" + # source = "../../../modules/modules/services/hello-world-app" environment = "prod" image_id = data.aws_ami.ubuntu.id db_remote_state_bucket = "tf-state-ujstor" db_remote_state_key = "prod/data-stores/mysql/terraform.tfstate" - server_text = "New server text from prod" - instance_type = "t3.micro" min_size = 2 - max_size = 10 + max_size = 11 custom_tags = { Owner = "team-foo" diff --git a/stage/data-stores/mysql/main.tf b/stage/data-stores/mysql/main.tf index d4703c0..ae33b2a 100644 --- a/stage/data-stores/mysql/main.tf +++ b/stage/data-stores/mysql/main.tf @@ -1,5 +1,6 @@ module "mysql_db_stage" { - source = "../../../modules/modules/data-stores/mysql" + source = "github.com/ujstor/aws-terraform//modules/modules/data-stores/mysql?ref=v0.1.3" + # source = "../../../modules/modules/data-stores/mysql" providers = { aws = aws.stage diff --git a/stage/services/hello-world-app/main.tf b/stage/services/hello-world-app/main.tf index 83d0874..65b0c06 100644 --- a/stage/services/hello-world-app/main.tf +++ b/stage/services/hello-world-app/main.tf @@ -1,5 +1,6 @@ module "hello-world-app" { - source = "github.com/ujstor/aws-terraform//modules/modules/services/hello-world-app?ref=v0.1.0" + source = "github.com/ujstor/aws-terraform//modules/modules/services/hello-world-app?ref=v0.1.3" + # source = "../../../modules/modules/services/hello-world-app/" providers = { aws = aws.stage @@ -12,9 +13,8 @@ module "hello-world-app" { db_remote_state_bucket = "tf-state-ujstor" db_remote_state_key = "stage/data-stores/mysql/terraform.tfstate" - server_text = "New server text from stage" - min_size = 2 - max_size = 5 + min_size = 2 + max_size = 5 custom_tags = { Owner = "team-foo" diff --git a/stage/services/k8s/.terraform.lock.hcl b/stage/services/k8s/.terraform.lock.hcl index 2d03d6e..14c43ec 100644 --- a/stage/services/k8s/.terraform.lock.hcl +++ b/stage/services/k8s/.terraform.lock.hcl @@ -1,6 +1,29 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/hashicorp/aws" { + version = "5.54.1" + constraints = "~> 5.0" + hashes = [ + "h1:SOdZNOAcBvbrkV6V1S7UiGh9K//O66qfyXpHgyXeBeI=", + "zh:37c09b9a0a0a2f7854fe52c6adb15f71593810b458a8283ed71d68036af7ba3a", + "zh:42fe11d87723d4e43b9c6224ae6bacdcb53faee8abc58f0fc625a161d1f71cb1", + "zh:57c6dfc46f28c9c2737559bd84acbc05aeae90431e731bb72a0024028a2d2412", + "zh:5ba9665a4ca0e182effd75575b19a4d47383ec02662024b9fe26f78286c36619", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b55980be0237644123a02a30b56d4cc03863ef29036c47d6e8ab5429ab45adf5", + "zh:b81e7664f10855a3a6fc234a18b4c4f1456273126a40c41516f2061696fb9870", + "zh:bd09736ffafd92af104c3c34b5add138ae8db4402eb687863ce472ca7e5ff2e2", + "zh:cc2eb1c62fba2a11d1f239e650cc2ae94bcab01c907384dcf2e213a6ee1bd5b2", + "zh:e5dc40205d9cf6f353c0ca532ae29afc6c83928bc9bcca47d74b640d3bb5a38c", + "zh:ebf1acdcd13f10db1b9c85050ddaadc70ab269c47c5a240753362446442d8371", + "zh:f2fc28a4ad94af5e6144a7309286505e3eb7a94d9dc106722b506c372ff7f591", + "zh:f49445e8435944df122aa89853260a2716ba8b73d6a6a70cae1661554926d5a2", + "zh:fc3b5046e60ae7cab20715be23de8436eb12736136fd6d0f0cc1549ebda6cc73", + "zh:fdb98a53500e245a3b5bec077b994da6959dba8fc4eb7534528658d820e06bd5", + ] +} + provider "registry.terraform.io/hashicorp/kubernetes" { version = "2.30.0" constraints = "~> 2.0, 2.30.0" diff --git a/stage/services/k8s/main.tf b/stage/services/k8s/main.tf index 9ec9277..30ce4be 100644 --- a/stage/services/k8s/main.tf +++ b/stage/services/k8s/main.tf @@ -1,5 +1,6 @@ module "simple_webapp" { - source = "../../../modules/modules/k8s/" + source = "github.com/ujstor/aws-terraform//modules/modules/k8s?ref=v0.1.3" + # source = "../../../modules/modules/k8s/" name = "portfolio-webapp" image = "ujstor/portfolio-web-go:1.2.0"