From c8840634cd1fe4ec22fa69bc36e5ebf3b14090e7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 23 Feb 2024 21:43:59 +0500 Subject: [PATCH] address PR comments --- .sample/main.tf | 2 +- jetbrains-gateway/main.tf | 17 ++++++----------- terraform_validate.sh | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.sample/main.tf b/.sample/main.tf index 733f121..9cbb464 100644 --- a/.sample/main.tf +++ b/.sample/main.tf @@ -69,7 +69,7 @@ resource "coder_app" "MODULE_NAME" { slug = "MODULE_NAME" display_name = "MODULE_NAME" url = "http://localhost:${var.port}" - icon = loocal.icon_url + icon = local.icon_url subdomain = false share = "owner" diff --git a/jetbrains-gateway/main.tf b/jetbrains-gateway/main.tf index af2a0ea..32764e3 100644 --- a/jetbrains-gateway/main.tf +++ b/jetbrains-gateway/main.tf @@ -30,10 +30,6 @@ variable "default" { description = "Default IDE" } -locals { - supported_ides = ["IU", "PS", "WS", "PY", "CL", "GO", "RM"] -} - variable "jetbrains_ide_versions" { type = map(object({ build_number = string @@ -69,29 +65,28 @@ variable "jetbrains_ide_versions" { build_number = "232.10203.15" version = "2023.2.4" } - } validation { condition = ( alltrue([ - for code in var.jetbrains_ide_versions : contains(local.supported_ides, code) + for code in var.jetbrains_ide_versions : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM"], code) ]) ) - error_message = "The jetbrains_ide_versions must contain a map of valid product codes. Valid product codes are ${join(",", local.supported_ides)}." + error_message = "The jetbrains_ide_versions must contain a map of valid product codes. Valid product codes are ${join(",", ["IU", "PS", "WS", "PY", "CL", "GO", "RM"])}." } } variable "jetbrains_ides" { type = list(string) description = "The list of IDE product codes." - default = local.supported_ides + default = ["IU", "PS", "WS", "PY", "CL", "GO", "RM"] validation { condition = ( alltrue([ - for code in var.jetbrains_ides : contains(local.supported_ides, code) + for code in var.jetbrains_ides : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM"], code) ]) ) - error_message = "The jetbrains_ides must be a list of valid product codes. Valid product codes are ${join(",", local.supported_ides)}." + error_message = "The jetbrains_ides must be a list of valid product codes. Valid product codes are ${join(",", ["IU", "PS", "WS", "PY", "CL", "GO", "RM"])}." } # check if the list is empty validation { @@ -152,7 +147,7 @@ data "coder_parameter" "jetbrains_ide" { icon = "/icon/gateway.svg" mutable = true # check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null - default = var.default != null && var.default != "" && contains(var.jetbrains_ides, var.default) ? local.jetbrains_ides[var.default].value : local.jetbrains_ides[var.jetbrains_ides[0]].value + default = contains(var.jetbrains_ides, var.default) ? var.default : null dynamic "option" { for_each = { for key, value in local.jetbrains_ides : key => value if contains(var.jetbrains_ides, key) } diff --git a/terraform_validate.sh b/terraform_validate.sh index 359b5ce..d5389ea 100755 --- a/terraform_validate.sh +++ b/terraform_validate.sh @@ -1,27 +1,27 @@ #!/bin/bash +set -euo pipefail + # Function to run terraform init and validate in a directory run_terraform() { - local dir="$1" - echo "Running terraform init and validate in $dir" - cd "$dir" || exit - terraform init - terraform validate - cd - || exit + local dir="$1" + echo "Running terraform init and validate in $dir" + cd "$dir" || exit + terraform init -upgrade && terraform validate + cd - || exit } # Main script main() { - # Get the current directory - current_dir=$(pwd) + # Get the directory of the script + script_dir=$(dirname "$(readlink -f "$0")") - # Find all subdirectories containing a main.tf file - subdirs=$(find "$current_dir" -type f -name "main.tf" -exec dirname {} \;) + # Get all subdirectories in the repository + subdirs=$(find "$script_dir" -mindepth 1 -maxdepth 1 -type d -not -name ".*" | sort) - # Run terraform init and validate in each subdirectory - for dir in $subdirs; do - run_terraform "$dir" - done + for dir in $subdirs; do + run_terraform "$dir" + done } # Run the main script