Skip to content

Commit

Permalink
Enforce Resource Tagging in Terraform Deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
velotioaastha committed Nov 13, 2024
1 parent 6b86b4a commit 619c007
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module "kms" {
source = "./modules/kms"
namespace = var.namespace
deletion_protection = var.deletion_protection
labels = var.labels
}

module "kms_default_bucket" {
Expand All @@ -67,6 +68,7 @@ module "kms_default_bucket" {
deletion_protection = var.deletion_protection
key_location = lower(var.bucket_location)
bind_pubsub_service_to_kms_key = false
labels = var.labels
}

module "kms_default_sql" {
Expand All @@ -76,6 +78,7 @@ module "kms_default_sql" {
deletion_protection = var.deletion_protection
key_location = data.google_client_config.current.region
bind_pubsub_service_to_kms_key = false
labels = var.labels
}
locals {
default_bucket_key = length(module.kms_default_bucket) > 0 ? module.kms_default_bucket[0].crypto_key.id : var.bucket_kms_key_id
Expand All @@ -99,10 +102,10 @@ module "storage" {
}

module "networking" {
count = local.create_network ? 1 : 0

count = local.create_network ? 1 : 0
source = "./modules/networking"
namespace = var.namespace
labels = var.labels
depends_on = [module.project_factory_project_services]
}

Expand All @@ -124,6 +127,7 @@ module "app_gke" {
depends_on = [module.project_factory_project_services]
max_node_count = local.max_node_count
min_node_count = local.min_node_count
labels = var.labels
}

module "app_lb" {
Expand Down
1 change: 1 addition & 0 deletions modules/app_gke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ resource "google_container_node_pool" "default" {
metadata = {
disable-legacy-endpoints = "true"
}
labels = var.labels
}

management {
Expand Down
6 changes: 6 additions & 0 deletions modules/app_gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ variable "deletion_protection" {
description = "If the GKE Cluster should have deletion protection enabled. The GKE Cluster can't be deleted when this value is set to `true`."
type = bool
default = true
}

variable "labels" {
description = "Labels which will be applied to all applicable resources."
type = map(string)
default = {}
}
2 changes: 1 addition & 1 deletion modules/kms/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "google_kms_crypto_key" "default" {
name = "${var.namespace}-key"
key_ring = google_kms_key_ring.default.id
rotation_period = "100000s"

labels = var.labels
# lifecycle {
# prevent_destroy = var.deletion_protection
# }
Expand Down
6 changes: 6 additions & 0 deletions modules/kms/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ variable "bind_pubsub_service_to_kms_key" {
type = bool
description = "Whether to bind the Pub/Sub service account to the KMS key for encrypter/decrypter access."
default = true
}

variable "labels" {
description = "Labels which will be applied to all applicable resources."
type = map(string)
default = {}
}
1 change: 1 addition & 0 deletions modules/networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ resource "google_compute_global_address" "private_ip_address" {
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.vpc.id
labels = var.labels
}

resource "google_service_networking_connection" "default" {
Expand Down
6 changes: 6 additions & 0 deletions modules/networking/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ variable "namespace" {
type = string
description = "The name prefix for all resources created."
}

variable "labels" {
description = "Labels which will be applied to all applicable resources."
type = map(string)
default = {}
}

0 comments on commit 619c007

Please sign in to comment.