From 5f1b45e93574c2ab0feec3b4df04326069997024 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Lopez Date: Mon, 24 Jun 2024 11:11:40 +0200 Subject: [PATCH] Addressing #152 --- .cloudbees/workflows/bp-tf-ci.yaml | 1 + blueprints/01-getting-started/main.tf | 8 +++----- blueprints/01-getting-started/providers.tf | 4 ---- blueprints/01-getting-started/variables.tf | 6 ++++++ blueprints/02-at-scale/main.tf | 9 +++------ blueprints/02-at-scale/providers.tf | 5 ----- blueprints/02-at-scale/variables.tf | 6 ++++++ 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.cloudbees/workflows/bp-tf-ci.yaml b/.cloudbees/workflows/bp-tf-ci.yaml index 60ec43ac..63c14c01 100644 --- a/.cloudbees/workflows/bp-tf-ci.yaml +++ b/.cloudbees/workflows/bp-tf-ci.yaml @@ -28,6 +28,7 @@ env: company = "CloudBees Inc." } suffix = "ci-v4" + ci = true jobs: init: diff --git a/blueprints/01-getting-started/main.tf b/blueprints/01-getting-started/main.tf index a443aed6..9b3995e2 100644 --- a/blueprints/01-getting-started/main.tf +++ b/blueprints/01-getting-started/main.tf @@ -226,13 +226,11 @@ resource "kubernetes_storage_class_v1" "gp3" { } -resource "null_resource" "create_kubeconfig" { - +# Kubeconfig +resource "terraform_data" "create_kubeconfig" { depends_on = [module.eks] - triggers = { - always_run = timestamp() - } + triggers_replace = var.ci ? [timestamp()] : [] provisioner "local-exec" { command = "aws eks update-kubeconfig --name ${module.eks.cluster_name} --region ${local.region} --kubeconfig ${local.kubeconfig_file_path}" diff --git a/blueprints/01-getting-started/providers.tf b/blueprints/01-getting-started/providers.tf index 1c5c4ecf..9af5106e 100644 --- a/blueprints/01-getting-started/providers.tf +++ b/blueprints/01-getting-started/providers.tf @@ -14,10 +14,6 @@ terraform { source = "hashicorp/helm" version = ">= 2.5.1" } - null = { - source = "hashicorp/null" - version = ">= 3.1.0" - } } } diff --git a/blueprints/01-getting-started/variables.tf b/blueprints/01-getting-started/variables.tf index 7acec7d4..c8f674c2 100644 --- a/blueprints/01-getting-started/variables.tf +++ b/blueprints/01-getting-started/variables.tf @@ -24,3 +24,9 @@ variable "suffix" { error_message = "The suffix cannot contain more than 10 characters." } } + +variable "ci" { + description = "Running in a CI Service vs locally. False when running locally, true when running in a CI service" + default = false + type = bool +} \ No newline at end of file diff --git a/blueprints/02-at-scale/main.tf b/blueprints/02-at-scale/main.tf index 6157261f..b609e21f 100644 --- a/blueprints/02-at-scale/main.tf +++ b/blueprints/02-at-scale/main.tf @@ -643,14 +643,11 @@ resource "kubernetes_storage_class_v1" "efs" { } # Kubeconfig - -resource "null_resource" "create_kubeconfig" { - +resource "terraform_data" "create_kubeconfig" { depends_on = [module.eks] - triggers = { - always_run = timestamp() - } + triggers_replace = var.ci ? [timestamp()] : [] + provisioner "local-exec" { command = "aws eks update-kubeconfig --name ${module.eks.cluster_name} --region ${local.region} --kubeconfig ${local.kubeconfig_file_path}" } diff --git a/blueprints/02-at-scale/providers.tf b/blueprints/02-at-scale/providers.tf index 49400d71..5444706a 100644 --- a/blueprints/02-at-scale/providers.tf +++ b/blueprints/02-at-scale/providers.tf @@ -24,11 +24,6 @@ terraform { version = ">= 0.7.1" } - null = { - source = "hashicorp/null" - version = ">= 3.1.0" - } - random = { source = "hashicorp/random" version = ">= 3.6.1" diff --git a/blueprints/02-at-scale/variables.tf b/blueprints/02-at-scale/variables.tf index 8d4bc3ab..e0bff121 100644 --- a/blueprints/02-at-scale/variables.tf +++ b/blueprints/02-at-scale/variables.tf @@ -36,3 +36,9 @@ variable "gh_token" { default = "ExampleToken1234" type = string } + +variable "ci" { + description = "Running in a CI Service vs locally. False when running locally, true when running in a CI service," + default = false + type = bool +} \ No newline at end of file