Reputation: 1860
Is it possible to create a cloud run service without specifying the container? The container will be deployed later through cloud build. But now when I create the cloud run initially, it asks for container image, and I don't have it. Without the container it doesn't work on both the gcp UI and terraform. How to do this? What is the approach for such cases?
resource "google_cloud_run_service" "default" {
provider = google-beta
name = var.service_name
location = var.region
template {
spec {
containers {
image = "us-central1-docker.pkg.dev/holabola-dev/holabolaartifacts/holabola:latest"
}
}
}
metadata {
annotations = {
"autoscaling.knative.dev/minScale" = "1"
"autoscaling.knative.dev/maxScale" = "1000"
"run.googleapis.com/launch-stage" : "BETA"
"run.googleapis.com/vpc-access-connector" = "vpc-connector"
}
}
}
Upvotes: 3
Views: 2470
Reputation: 760
You could use the ignore_changes meta-argument to tell Terraform to ignore future changes in image as explained in this other answer in StackOverflow.
Upvotes: 0
Reputation: 480
Google Cloud provides a dummy docker image for this purposes, it is called us-docker.pkg.dev/cloudrun/container/hello
and you can configure your terraform file with this image with something like this:
resource "google_cloud_run_service" "backend-service" {
name = "backend-service"
location = "europe-east1"
template {
spec {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
ports {
container_port = 1234
name = "http1"
}
}
service_account_name = "[email protected]"
}
}
traffic {
percent = 100
latest_revision = true
}
}
Upvotes: 4
Reputation: 4126
You'll have to wait until the container image is built before you can deploy it on Cloud Run. Cloud Run is for running stateless containers. Without containers, you can't "run" anything.
Or you can create an "empty" Cloud Run service by deploying a demo container (hello) and run your Terraform script when your target container is available then update the service. But from what I understand, it doesn't really solve anything because there's an option to create a service in Terraform.
Upvotes: 1