Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying 'container_port' and 'request_timeout' for google_cloud_run_service #5539

Comments

@viprerk
Copy link

viprerk commented Jan 29, 2020

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

@ghost ghost added the enhancement label Jan 29, 2020
@danawillow danawillow added this to the Goals milestone Feb 3, 2020
@FallenHoot
Copy link

FallenHoot commented Feb 13, 2020

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 the PORT environment 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.

@remorses
Copy link

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

@kristianmandrup
Copy link

@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.

@remorses
Copy link

remorses commented Mar 8, 2020

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

DominicRoyStang added a commit to DominicRoyStang/uvindex that referenced this issue Apr 10, 2020
This change was made to enable cloud functions to be setup using terraform. See issue here: hashicorp/terraform-provider-google#5539
DominicRoyStang added a commit to DominicRoyStang/uvindex that referenced this issue Apr 10, 2020
This change was made to enable cloud functions to be setup using terraform. See issue here: hashicorp/terraform-provider-google#5539
@smootherbug
Copy link

Is there any update on this issue?

@sjortiz
Copy link

sjortiz commented May 19, 2020

Waiting on this

@sjortiz
Copy link

sjortiz commented May 28, 2020

any updates?

@sherifkozman
Copy link

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!

@joshuarli
Copy link

Isn't request_timeout possible with timeout_seconds?

@joshuarli
Copy link

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

@ghost
Copy link

ghost commented Aug 28, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.