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

Removing ports declaration from google_cloud_run_v2_service does not remove the port from the service #20753

Open
AndreaGiardini opened this issue Dec 19, 2024 · 0 comments
Labels
bug forward/review In review; remove label to forward service/run

Comments

@AndreaGiardini
Copy link

AndreaGiardini commented Dec 19, 2024

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 an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v1.7.5 (same thing happens on latest)
on darwin_arm64

  • provider registry.terraform.io/hashicorp/google v6.14.1
  • provider registry.terraform.io/hashicorp/google-beta v6.14.1

Affected Resource(s)

google_cloud_run_v2_service

Terraform Configuration

Before:

resource "google_cloud_run_v2_service" "app" {
  [...]
  template {
    containers {
      name  = "main"
      image = var.app_image
      ports {
        container_port = 8080
      }
    }
  }
}

After:

resource "google_cloud_run_v2_service" "app" {
  [...]
  template {
    containers {
      name  = "main"
      image = var.app_image

      env {
          name  = "PORT"
          value = "9090"
      }
    }

    containers {
      name  = "reverse-proxy"
      image = var.reverse_proxy_image

      ports {
        container_port = 8080
      }

      depends_on = ["main"]
    }
  }
}

Debug Output

No response

Expected Behavior

No response

Actual Behavior

No response

Steps to reproduce

  • Create a cloud run v2 service with a ports declaration: terraform apply
  • Modify configuration to remove the ports config and add a sidecar container
  • Re-run terraform plan/apply and you'll notice terraform erroring out

The removal of the port from the main container is not shown in the plan and when applying terraform errors out with:

│ Error: Error updating Service "projects/xxx/locations/xxx/services/xxx": googleapi: Error 400: template.containers: Revision template should contain exactly one container with an exposed port.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.BadRequest",
│     "fieldViolations": [
│       {
│         "description": "Revision template should contain exactly one container with an exposed port.",
│         "field": "template.containers"
│       }
│     ]
│   }
│ ]

From the debug output, it's clear that the ports section is still there:

   21 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:     "name": "main",
   20 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:     "ports": [
   19 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:      {
   18 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:       "containerPort": 8080,
   17 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:       "name": "http1"
   16 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:      }
   15 2024-12-19T14:46:27.250+0100 [DEBUG] provider.terraform-provider-google_v6.14.1_x5:     ],

Important Factoids

No response

References

I was following this tutorial: https://cloud.google.com/run/docs/internet-proxy-nginx-sidecar

I am confident that the issue is the same as #17468

I think we can fix this by removing this line https://github.com/GoogleCloudPlatform/magic-modules/blob/37e4abb059553f92e3eb4960ec0a2188a3cef77a/mmv1/products/cloudrunv2/Service.yaml#L524, but I would like somebody to double check my assumptions. Happy to open a PR if that's the solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug forward/review In review; remove label to forward service/run
Projects
None yet
Development

No branches or pull requests

1 participant