Skip to content
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
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ module "kms" {
source = "./modules/kms"

deployment_name = var.deployment_name
custom_labels = var.custom_labels
}

module "database" {
source = "./modules/database"

deployment_name = var.deployment_name
custom_labels = var.custom_labels
postgres_network = var.create_vpc ? module.vpc[0].network_self_link : var.existing_network_self_link
postgres_kms_cmek_id = module.kms.kms_key_id
postgres_version = var.postgres_version
Expand All @@ -33,6 +35,7 @@ module "redis" {
source = "./modules/redis"

deployment_name = var.deployment_name
custom_labels = var.custom_labels
redis_network = var.create_vpc ? module.vpc[0].network_self_link : var.existing_network_self_link
redis_kms_cmek_id = module.kms.kms_key_id
redis_version = var.redis_version
Expand All @@ -43,6 +46,7 @@ module "storage" {
source = "./modules/storage"

deployment_name = var.deployment_name
custom_labels = var.custom_labels
gcs_kms_cmek_id = module.kms.kms_key_id
gcs_additional_allowed_origins = var.gcs_additional_allowed_origins
gcs_bucket_retention_days = var.gcs_bucket_retention_days
Expand All @@ -60,6 +64,7 @@ module "gke-cluster" {
count = var.deploy_gke_cluster ? 1 : 0

deployment_name = var.deployment_name
custom_labels = var.custom_labels
gke_network = var.create_vpc ? module.vpc[0].network_self_link : var.existing_network_self_link
gke_subnetwork = var.create_vpc ? module.vpc[0].subnet_self_link : var.existing_subnet_self_link
gke_control_plane_cidr = var.gke_control_plane_cidr
Expand Down
4 changes: 2 additions & 2 deletions modules/database/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
common_labels = {
common_labels = merge(var.custom_labels, {
braintrustdeploymentname = var.deployment_name
}
})
postgres_username = "postgres"
postgres_password = random_password.postgres_password.result
}
Expand Down
6 changes: 6 additions & 0 deletions modules/database/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ variable "deployment_name" {
type = string
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}
}

#----------------------------------------------------------------------------------------------
# Cloud SQL for PostgreSQL
#----------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions modules/gke-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#----------------------------------------------------------------------------------------------
# Common
#----------------------------------------------------------------------------------------------
locals {
common_labels = merge(var.custom_labels, {
braintrustdeploymentname = var.deployment_name
})
}

data "google_client_config" "current" {}

data "google_project" "current" {}
Expand All @@ -25,6 +31,8 @@ resource "google_container_cluster" "braintrust_autopilot" {

deletion_protection = var.gke_deletion_protection

resource_labels = local.common_labels

# Private cluster configuration
dynamic "private_cluster_config" {
for_each = var.gke_cluster_is_private ? [1] : []
Expand Down
6 changes: 6 additions & 0 deletions modules/gke-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ variable "deployment_name" {
type = string
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}
}

#----------------------------------------------------------------------------------------------
# GKE Cluster
#----------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions modules/kms/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Common
#----------------------------------------------------------------------------------------------
locals {
common_labels = {
common_labels = merge(var.custom_labels, {
braintrustdeploymentname = var.deployment_name
}
})
}

data "google_client_config" "current" {}
Expand Down
6 changes: 6 additions & 0 deletions modules/kms/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ variable "deployment_name" {
description = "Name of the deployment. Used to prefix resource names."
type = string
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}
}
4 changes: 2 additions & 2 deletions modules/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Common
#----------------------------------------------------------------------------------------------
locals {
common_labels = {
common_labels = merge(var.custom_labels, {
braintrustdeploymentname = var.deployment_name
}
})
}

data "google_project" "current" {}
Expand Down
6 changes: 6 additions & 0 deletions modules/redis/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ variable "deployment_name" {
type = string
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}
}

#----------------------------------------------------------------------------------------------
# Redis
#----------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions modules/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ locals {

all_origins = concat(local.default_origins, var.gcs_additional_allowed_origins)

common_labels = {
common_labels = merge(var.custom_labels, {
braintrustdeploymentname = var.deployment_name
}
})
}

data "google_project" "current" {}
Expand Down
6 changes: 6 additions & 0 deletions modules/storage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ variable "deployment_name" {
type = string
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}
}

#----------------------------------------------------------------------------------------------
# GCS
#----------------------------------------------------------------------------------------------
Expand Down
21 changes: 20 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ variable "deployment_name" {
}
}

variable "custom_labels" {
type = map(string)
description = "Optional labels to apply to all resources that support labels."
default = {}

validation {
condition = alltrue([
for k, v in var.custom_labels :
can(regex("^[a-z][a-z0-9_-]{0,62}$", k)) && can(regex("^[a-z0-9_-]{0,63}$", v))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex always breaks my brain. Did you test various combos of allowed vs not allowed?

])
error_message = "Label keys must start with a lowercase letter and contain only lowercase letters, numbers, underscores, and dashes (max 63 chars). Values must contain only lowercase letters, numbers, underscores, and dashes (max 63 chars)."
}

validation {
condition = length(var.custom_labels) <= 63
error_message = "A maximum of 63 custom labels are allowed."
}
}

#----------------------------------------------------------------------------------------------
# VPC
#----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -342,6 +361,6 @@ variable "braintrust_hmac_key_enabled" {

variable "brainstore_impersonation_targets" {
type = list(string)
description = "Full resource names of service accounts (same or other projects) that the brainstore service account can impersonate via roles/iam.serviceAccountTokenCreator. Format: projects/{project_id}/serviceAccounts/{email}"
description = "Full resource names of service accounts (same or other projects) that the brainstore service account can impersonate via roles/iam.serviceAccountTokenCreator. Format: projects/{project_id}/serviceAccounts/{email}. Only required if you are not granting IAM access to the brainstore service account yourself. Note: the principal running this Terraform deployment must have permission to manage IAM policies on the target service accounts (e.g. roles/iam.serviceAccountAdmin or roles/resourcemanager.projectIamAdmin)."
default = []
}
Loading