Skip to content

google_cloud_run_v2_service always tainted and must be replaced if deployed to #17992

Open
@dv01d

Description

@dv01d

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

Teerform v1.7.0
hashicorp/google v5.27.0

Affected Resource(s)

google_cloud_run_v2_service

Terraform Configuration

resource "google_cloud_run_v2_service" "hello" {

  name     = "hello-${var.env}"
  project  = local.project_id
  location = local.default_region
  labels   = {
    application_name = "hello-${var.env}"
  }
  #Use a dummy image to initialize
  template {
    service_account = local.cloudrun_sa

    containers {
      image = "us-docker.pkg.dev/cloudrun/container/hello"

      # Testing envrionments shouldn't be running all the time so set min to 0
      # Similarly they shouldn't see much traffic so max should be 2
      ports {
        container_port = 8080
      }

      env {
        name = "SECRET"
        value_source {
          secret_key_ref {
            secret = "super-secret-${var.env}"
            version = "latest"
          }
        }
      }
    }
    scaling {
      min_instance_count = 0
      max_instance_count = 2
    }

  }

  # Prevent Terraform from managing ongoing deployments or deleting the resource
  lifecycle {
    ignore_changes = [
      client,
      client_version,
      template[0].containers[0].env[0].name,
      template[0].containers[0].env[0].value_source,
      template[0].containers[0].image, 
      template[0].labels["application_name"],
      template[0].labels["commit-sha"],
      template[0].labels["managed-by"], ]
  }

Debug Output

No response

Expected Behavior

Should have at least tried to merge in changes, ignored it, and more importantly not delete everything.

Actual Behavior

Any changes to a deployment results in taint, and rather than updating or reconciling it is destroyed and recreated.

Steps to reproduce

  1. terraform plan/apply
  2. Deploy to cloudrun service created by terraform, or even just edit and save yaml for the cloudrun service resulting in a noop (not even a new revision).
  3. `terraform plan/apply' results in deletion and recreation of cloudrun service

Important Factoids

Attempted many ignore statements as you can see, to try and prevent deletion, but at this point I can't tell what I can ignore that doesn't require tf to NOT recreate the service every time.

References

Similar behavior related to revisions here, but seems worse than originally documented as this always causes some sort of dataloss through destroy: #14569

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions