Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align variables #136

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ terraform test

| Name | Version |
|------|---------|
| google | 6.9.0 |
| google | 6.8.0 |
| random | 3.6.3 |

### Resources
Expand Down Expand Up @@ -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 |
Expand Down
12 changes: 10 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")

brettcurtis marked this conversation as resolved.
Show resolved Hide resolved
monitoring_notification_channels = {
"budget" = {
description = "Budget notification channel created by the terraform-google-project child module"
Expand All @@ -97,7 +105,7 @@ locals {
var.prefix,
var.description,
random_id.this[0].hex,
var.environment,
local.env,
) : local.base_project_id

# Concat Function
Expand Down
2 changes: 1 addition & 1 deletion tests/default.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ run "logging" {
}

variables {
environment = "mock"
environment = "sandbox"
}
8 changes: 6 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down