/** * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ variable "containers" { description = "Containers in name => attributes format." type = map(object({ image = string depends_on = optional(list(string)) command = optional(list(string)) args = optional(list(string)) env = optional(map(string)) env_from_key = optional(map(object({ secret = string version = string }))) liveness_probe = optional(object({ grpc = optional(object({ port = optional(number) service = optional(string) })) http_get = optional(object({ http_headers = optional(map(string)) path = optional(string) port = optional(number) })) failure_threshold = optional(number) initial_delay_seconds = optional(number) period_seconds = optional(number) timeout_seconds = optional(number) })) ports = optional(map(object({ container_port = optional(number) name = optional(string) }))) resources = optional(object({ limits = optional(map(string)) cpu_idle = optional(bool) startup_cpu_boost = optional(bool) })) startup_probe = optional(object({ grpc = optional(object({ port = optional(number) service = optional(string) })) http_get = optional(object({ http_headers = optional(map(string)) path = optional(string) port = optional(number) })) tcp_socket = optional(object({ port = optional(number) })) failure_threshold = optional(number) initial_delay_seconds = optional(number) period_seconds = optional(number) timeout_seconds = optional(number) })) volume_mounts = optional(map(string)) })) default = {} nullable = false validation { condition = alltrue([ for c in var.containers : ( c.resources == null ? true : 0 == length(setsubtract( keys(lookup(c.resources, "limits", {})), ["cpu", "memory", "nvidia.com/gpu"] )) ) ]) error_message = "Only following resource limits are available: 'cpu', 'memory' and 'nvidia.com/gpu'." } validation { condition = alltrue([ for c in var.containers : ( var.type != "WORKERPOOL" || c.depends_on == null ) ]) error_message = "depends_on is not supported when type is WORKERPOOL." } } variable "context" { description = "Context-specific interpolations." type = object({ condition_vars = optional(map(map(string)), {}) # not needed here? cidr_ranges = optional(map(string), {}) custom_roles = optional(map(string), {}) iam_principals = optional(map(string), {}) kms_keys = optional(map(string), {}) locations = optional(map(string), {}) networks = optional(map(string), {}) project_ids = optional(map(string), {}) subnets = optional(map(string), {}) tag_values = optional(map(string), {}) tag_vars = optional(object({ projects = optional(map(map(string)), {}) organization = optional(map(string), {}) }), {}) }) nullable = false default = {} } variable "deletion_protection" { description = "Deletion protection setting for this Cloud Run service." type = string default = null } variable "encryption_key" { description = "The full resource name of the Cloud KMS CryptoKey." type = string default = null } variable "iam" { description = "IAM bindings for Cloud Run service in {ROLE => [MEMBERS]} format." type = map(list(string)) default = {} } variable "job_config" { description = "Cloud Run Job specific configuration." type = object({ max_retries = optional(number) task_count = optional(number) timeout = optional(string) }) default = {} nullable = false validation { condition = var.job_config.timeout == null ? true : endswith(var.job_config.timeout, "s") error_message = "Timeout should follow format of number with up to nine fractional digits, ending with 's'. Example: '3.5s'." } } variable "labels" { description = "Resource labels." type = map(string) default = {} } variable "launch_stage" { description = "The launch stage as defined by Google Cloud Platform Launch Stages." type = string default = null validation { condition = ( var.launch_stage == null ? true : contains( ["UNIMPLEMENTED", "PRELAUNCH", "EARLY_ACCESS", "ALPHA", "BETA", "GA", "DEPRECATED"], var.launch_stage) ) error_message = < 0 && length(try(var.service_config.iap_config.iam_additive, [])) > 0) error_message = "Providing both 'iam' and 'iam_additive' in iap_config is not supported." } validation { condition = var.service_config.iap_config == null || var.launch_stage != "GA" error_message = "iap is currently not supported in GA. Set launch_stage to 'BETA' or lower." } validation { condition = ( var.service_config.ingress == null ? true : contains( ["INGRESS_TRAFFIC_ALL", "INGRESS_TRAFFIC_INTERNAL_ONLY", "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"], var.service_config.ingress) ) error_message = <