From 023ad9cea145069402a7180d675671e10179b92e Mon Sep 17 00:00:00 2001 From: Brett Curtis Date: Sat, 2 Nov 2024 19:00:38 -0400 Subject: [PATCH] Align variables (#136) --- .pre-commit-config.yaml | 4 ++-- README.md | 4 ++-- locals.tf | 12 ++++++++++-- tests/default.tftest.hcl | 2 +- variables.tf | 8 ++++++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d25cd2..9d5833c 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: check-symlinks - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.96.1 + rev: v1.96.2 hooks: - id: terraform_fmt @@ -29,7 +29,7 @@ repos: - id: terraform_docs - repo: https://github.com/bridgecrewio/checkov.git - rev: 3.2.256 + rev: 3.2.276 hooks: - id: checkov verbose: true diff --git a/README.md b/README.md index 1e81980..5ac8cf4 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ terraform test | Name | Version | |------|---------| -| google | 6.9.0 | +| google | 6.8.0 | | random | 3.6.3 | ### Resources @@ -118,7 +118,7 @@ terraform test | cis\_2\_2\_logging\_sink\_project\_id | The CIS 2.2 logging sink project ID | `string` | `""` | no | | deletion\_policy | The deletion policy for the project | `string` | `"PREVENT"` | no | | description | A short description representing the system, or service you're building in the project for example: `tools` (for a tooling project), `logging` (for a logging project), `services` (for a services project) | `string` | n/a | yes | -| environment | The environment suffix for example: `sb` (Sandbox), `nonprod` (Non-Production), `prod` (Production) | `string` | `"sb"` | no | +| environment | The environment for example: `sandbox`, `non-production`, `production` | `string` | n/a | yes | | folder\_id | The numeric ID of the folder this project should be created under. Only one of `org_id` or `folder_id` may be specified | `string` | n/a | yes | | key\_ring\_location | The location of the key ring to create | `string` | `"us"` | no | | labels | A map of key/value pairs to assign to the resources being created | `map(string)` | `{}` | no | diff --git a/locals.tf b/locals.tf index bc1aa99..85c4d7c 100644 --- a/locals.tf +++ b/locals.tf @@ -2,7 +2,7 @@ # https://www.terraform.io/language/values/locals locals { - base_project_id = "${var.prefix}-${var.description}-${var.environment}" + base_project_id = "${var.prefix}-${var.description}-${local.env}" # This map is used to create the GCP-CIS v1.3.0 logging metrics and alarms (2.4 - 2.11). It is recommended that metric filters and alarms be established for # the following resources. @@ -76,6 +76,14 @@ locals { cis_2_2_logging_sink_project_id = var.cis_2_2_logging_sink_project_id == "" ? google_project.this.project_id : var.cis_2_2_logging_sink_project_id cis_2_2_logging_sink_storage_bucket = var.cis_2_2_logging_sink_project_id == "" ? "logging.googleapis.com/${google_logging_project_bucket_config.cis_2_2_logging_sink[0].name}" : "logging.googleapis.com/projects/${var.cis_2_2_logging_sink_project_id}/locations/${var.key_ring_location}/buckets/cis-2-2-logging-sink" + env_map = { + "sandbox" = "sb" + "non-production" = "nonprod" + "production" = "prod" + } + + env = lookup(local.env_map, var.environment, "none") + monitoring_notification_channels = { "budget" = { description = "Budget notification channel created by the terraform-google-project child module" @@ -97,7 +105,7 @@ locals { var.prefix, var.description, random_id.this[0].hex, - var.environment, + local.env, ) : local.base_project_id # Concat Function diff --git a/tests/default.tftest.hcl b/tests/default.tftest.hcl index 09d5ae4..3d4434f 100644 --- a/tests/default.tftest.hcl +++ b/tests/default.tftest.hcl @@ -27,5 +27,5 @@ run "logging" { } variables { - environment = "mock" + environment = "sandbox" } diff --git a/variables.tf b/variables.tf index a200e00..6960e76 100644 --- a/variables.tf +++ b/variables.tf @@ -37,9 +37,13 @@ variable "description" { } variable "environment" { - description = "The environment suffix for example: `sb` (Sandbox), `nonprod` (Non-Production), `prod` (Production)" + description = "The environment for example: `sandbox`, `non-production`, `production`" type = string - default = "sb" + + validation { + condition = contains(["sandbox", "non-production", "production"], var.environment) + error_message = "Environment must be one of: sandbox, non-production, production." + } } variable "folder_id" {