Blog
Configuring CPU, Memory and Scaling Settings in Google Cloud Run using Terraform
, John Comber
Introduction
This example demonstrates how to configure CPU, memory and scaling settings in Google Cloud Run using Terraform.
Memory Specification
This can be defined as a number (of bytes) or a number with a unit:
- 128M = 128 Megabytes
- 128Mi = 128 Mebibytes
- 1G = 1 Gigabyte
- 1Gi = 1 Gibibyte
CPU Specification
This can be defined as a number or as a number with a unit of milli-cpus.
- 1000m = 1 CPU
Code
resource "google_cloud_run_service" "main" {
name = <NAME>
project = <PROJECT ID>
location = <LOCATION>
template {
spec {
containers {
image = <CONTAINER IMAGE>
ports {
container_port = <CONTAINER PORT>
}
resources {
limits = {
"memory" = "512Mi"
"cpu" = "1000m"
}
}
}
}
metadata {
annotations = {
"autoscaling.knative.dev/maxScale" = "1"
"run.googleapis.com/client-name" = "terraform"
}
}
}
}