When deploying a Managed Cloud Run service in the GCP Web UI, the 'Container Port' and 'Request Timeout' options can be changed.
When deploying a Managed Cloud Run service with Terraform, there is no configuration available to change the 'Container Port' and 'Request Timeout' options away from default values.
I would like to be able to set these options when deploying Managed Cloud Run services with Terraform, instead of using the default values.
google_cloud_run_service
resource "google_cloud_run_service" "example-service" {
name = "example-service"
location = var.cloud_run_region
template {
spec {
containers {
image = "us.gcr.io/${var.gcp_project}/${var.cloud_run_container}"
resources {
limits = {
cpu = "2000m"
memory = "2048Mi"
}
}
}
container_concurrency = 0
request_timeout = 900
container_port = 9999
}
}
traffic {
percent = 100
latest_revision = true
}
}
https://www.terraform.io/docs/providers/google/r/cloud_run_service.html
https://console.cloud.google.com/run
I just stumbled on this issue as well. To provide more context to the issue:
Error: HealthCheckContainerError - Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by thePORTenvironment variable. Logs for this revision might contain more information.
In Cloud Run container instances, the PORT environment variable is always set to 8080, but for portability reasons, your code should not hardcode this value.
https://cloud.google.com/run/docs/reference/container-contract#port
The current way to deploy Cloud Run with Terraform makes us hardcode this and is currently not the best practice.
You can add the env option:
env {
name = "PORT"
value = "1234"
}
This will come up as:
Terraform Debug
"ports": [
{
"containerPort": 1234
}
]
I checked the GCP Logging and it states:
```
status: {
code: 3
message: "INVALID_ARGUMENT"
}
Terraform will give:
`Error: Error updating Service "locations/europe-north1/namespaces/test/services/backend": googleapi: Error 400: The request has errors
`
_____
I tried with a fresh project and now get the following:
Terraform Error
`Error: Error creating Service: googleapi: Error 400: The request has errors`
Terraform Debug
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "spec.template.spec.containers[0].env",
"description": "The following reserved env names were provided: PORT. These values are automatically set by the system
}
]
}
]
}
}
```
Looks like Env option is broken as well.
When I comment the ENV option out, it works as it should, but with the default 8080 port. I had to change the listing port on the container back to 8080 for this to work.
I would like to have this feature too, this change was made in the January 7 release together with the option to deploy from a knative yaml file
@remorses Do you know how to customise the container port? The release notes say it is now possible, but not how. Any idea where I can find the docs for this? Thanks.
Someone should update the terraform provider to do so, unfortunately the provider is not updated by the google devs themselves so you just need to wait
Is there any update on this issue?
Waiting on this
any updates?
Has there been any updates on this issue, its breaking pretty much all of our deployments on the first run or we have to accomodate to the default port 8080!
Isn't request_timeout possible with timeout_seconds?
Also reproduced the fact that adding a PORT env results in:
Error: Error creating Service: googleapi: Error 400: The request has errors
Details:
[
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "The following reserved env names were provided: PORT. These values are automatically set by the system.",
"field": "spec.template.spec.containers[0].env"
}
]
}
]
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
any updates?