mirror of
https://github.com/imjasonh/terraform-playground
synced 2026-07-22 16:11:22 +00:00
Support multiple containers in structured format
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
parent
8ac9ed9470
commit
34662400c9
3 changed files with 50 additions and 71 deletions
|
|
@ -15,44 +15,28 @@ variable "machine_type" {
|
|||
default = "e2-medium"
|
||||
}
|
||||
|
||||
variable "container_image" {
|
||||
description = "The container image to run, must be referenced by digest (e.g., 'gcr.io/my-project/my-app@sha256:abc123...')."
|
||||
type = string
|
||||
variable "containers" {
|
||||
description = "A map of containers to run on the VM. Each key is the container name, and the value specifies the container configuration."
|
||||
type = map(object({
|
||||
image = string
|
||||
command = optional(string, "")
|
||||
args = optional(list(string), [])
|
||||
env = optional(list(object({
|
||||
name = string
|
||||
value = string
|
||||
})), [])
|
||||
restart_policy = optional(string, "always")
|
||||
}))
|
||||
|
||||
validation {
|
||||
condition = can(regex("^.+@sha256:[a-f0-9]{64}$", var.container_image))
|
||||
error_message = "The container_image must be referenced by digest (e.g., 'gcr.io/my-project/my-app@sha256:<64 hex chars>')."
|
||||
condition = length(var.containers) > 0
|
||||
error_message = "At least one container must be specified."
|
||||
}
|
||||
}
|
||||
|
||||
variable "container_name" {
|
||||
description = "The name to assign to the running Docker container."
|
||||
type = string
|
||||
default = "gce-container-app"
|
||||
}
|
||||
|
||||
variable "restart_policy" {
|
||||
description = "The systemd/Docker restart policy (e.g., 'always', 'on-failure', 'no')."
|
||||
type = string
|
||||
default = "always"
|
||||
}
|
||||
|
||||
variable "container_env" {
|
||||
description = "A map of environment variables to set in the container."
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "container_command" {
|
||||
description = "The optional command to override the ENTRYPOINT (e.g., '/bin/bash')."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "container_args" {
|
||||
description = "Optional arguments to pass to the container command."
|
||||
type = list(string)
|
||||
default = []
|
||||
validation {
|
||||
condition = alltrue([for name, c in var.containers : can(regex("^.+@sha256:[a-f0-9]{64}$", c.image))])
|
||||
error_message = "All container images must be referenced by digest (e.g., 'gcr.io/my-project/my-app@sha256:<64 hex chars>')."
|
||||
}
|
||||
}
|
||||
|
||||
variable "service_account_email" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue