Terraform-provider-google: Allow specifying 'container_port' and 'request_timeout' for google_cloud_run_service

Created on 29 Jan 2020  ·  11Comments  ·  Source: hashicorp/terraform-provider-google

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment. If the issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If the issue is assigned to a user, that user is claiming responsibility for the issue. If the issue is assigned to "hashibot", a community member has claimed the issue already.

Description

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.

New or Affected Resource(s)

google_cloud_run_service

Potential Terraform Configuration

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
  }
}

References

https://www.terraform.io/docs/providers/google/r/cloud_run_service.html
https://console.cloud.google.com/run

enhancement sizS

Most helpful comment

any updates?

All 11 comments

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!

Was this page helpful?
0 / 5 - 0 ratings