From ce557fe8f2e0688cbd1a607e811de41aaf17cca9 Mon Sep 17 00:00:00 2001 From: RouxAntoine Date: Wed, 29 May 2024 23:23:41 +0200 Subject: [PATCH] feature: variabilize replicas number for deployment --- input.tf | 6 ++++++ main.tf | 2 +- tests/main.tftest.hcl | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/input.tf b/input.tf index 19c714f..b4c3fee 100644 --- a/input.tf +++ b/input.tf @@ -53,3 +53,9 @@ variable "volumes" { ) default = {} } + +variable "replicas" { + type = number + default = 1 + description = "number of replicas for the application's pod" +} \ No newline at end of file diff --git a/main.tf b/main.tf index 98bbced..0148e58 100644 --- a/main.tf +++ b/main.tf @@ -43,7 +43,7 @@ resource "kubernetes_deployment_v1" "deployment" { } } spec { - replicas = "1" + replicas = var.replicas selector { match_labels = { "app.kubernetes.io/name" = local.label_name diff --git a/tests/main.tftest.hcl b/tests/main.tftest.hcl index 54c11ba..6c828cd 100644 --- a/tests/main.tftest.hcl +++ b/tests/main.tftest.hcl @@ -7,6 +7,7 @@ run "terraform-plan" { image = { name = "container.localdomain/test-image" } + replicas = 2 } assert { @@ -15,7 +16,7 @@ run "terraform-plan" { } assert { - condition = kubernetes_deployment_v1.deployment.spec[0].replicas == "1" + condition = kubernetes_deployment_v1.deployment.spec[0].replicas == "2" error_message = "invalid number of replicas" } }