Skip to content

Instantly share code, notes, and snippets.

@harith96
Last active February 9, 2025 18:36
Show Gist options
  • Save harith96/54610412efa07b56cc54576221f8e7cb to your computer and use it in GitHub Desktop.
Save harith96/54610412efa07b56cc54576221f8e7cb to your computer and use it in GitHub Desktop.
Common Terraform module to create a cloud run service
resource "google_cloud_run_service" "service" {
name = var.service_name
location = var.region
template {
spec {
containers {
image = var.image
dynamic "env" {
for_each = var.env_vars
content {
name = env.value.name
value = env.value.value
}
}
dynamic "ports" {
for_each = var.ports
content {
container_port = ports.value
}
}
resources {
limits = var.resource_limits
}
dynamic "liveness_probe" {
for_each = var.liveness_probe
content {
http_get {
path = liveness_probe.value.path
port = liveness_probe.value.port
}
initial_delay_seconds = liveness_probe.value.initial_delay_seconds
period_seconds = liveness_probe.value.period_seconds
}
}
dynamic "startup_probe" {
for_each = var.startup_probe
content {
http_get {
path = readiness_probe.value.path
port = readiness_probe.value.port
}
initial_delay_seconds = readiness_probe.value.initial_delay_seconds
period_seconds = readiness_probe.value.period_seconds
}
}
command = var.command
args = var.args
}
}
metadata {
annotations = var.annotations
}
}
traffic {
percent = 100
latest_revision = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment