hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.73k forks source link

google_container_registry.container_registry must be replaced #16272

Open shpml opened 11 months ago

shpml commented 11 months ago

Community Note

Terraform Version

terraform -v                                                        
Terraform v1.6.1
on darwin_amd64
+ provider registry.terraform.io/hashicorp/google v5.2.0
+ provider registry.terraform.io/hashicorp/google-beta v5.2.0
+ provider registry.terraform.io/hashicorp/kubernetes v2.23.0

Affected Resource(s)

Terraform Configuration Files

resource "google_container_registry" "container_registry" {
  location = "ASIA"
}

Debug Output

Expected Behavior

The resources should not be replaced.

Actual Behavior

   # google_container_registry.container_registry must be replaced
-/+ resource "google_container_registry" "container_registry" {
      ~ bucket_self_link = "https://www.googleapis.com/storage/v1/b/asia.artifacts.my_project.appspot.com" -> (known after apply)
      ~ id               = "asia.artifacts.my_project.appspot.com" -> (known after apply)
      + project          = "my-project" # forces replacement
        # (1 unchanged attribute hidden)
    }

# google_storage_bucket_iam_member.bitbucket_pipelines_gcr_admin must be replaced
-/+ resource "google_storage_bucket_iam_member" "pipelines_gcr_admin" {
      ~ bucket = "b/asia.artifacts.my-project.appspot.com" # forces replacement -> (known after apply) # forces replacement
      ~ etag   = "CEI=" -> (known after apply)
      ~ id     = "b/asia.artifacts.my-project.appspot.com/roles/storage.admin/serviceaccount:pipelines@my-project.iam.gserviceaccount.com" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

  # google_storage_bucket_iam_member.container_registry_pull must be replaced
-/+ resource "google_storage_bucket_iam_member" "container_registry_pull" {
      ~ bucket = "b/asia.artifacts.my-project.appspot.com" # forces replacement -> (known after apply) # forces replacement
      ~ etag   = "CEI=" -> (known after apply)
      ~ id     = "b/asia.artifacts.my-project.appspot.com/roles/storage.objectViewer/serviceAccount:devops-k8s-default-svc@my-project.iam.gserviceaccount.com" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

  # google_storage_bucket_iam_member.gcr_read_only_binding must be replaced
-/+ resource "google_storage_bucket_iam_member" "gcr_read_only_binding" {
      ~ bucket = "b/asia.artifacts.my-project.appspot.com" # forces replacement -> (known after apply) # forces replacement
      ~ etag   = "CEI=" -> (known after apply)
      ~ id     = "b/asia.artifacts.my-project.appspot.com/roles/storage.objectViewer/serviceaccount:registry-reader@my-project.iam.gserviceaccount.com" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Steps to Reproduce

  1. terraform apply

Important Factoids

References

b/306360857

aleks-m commented 10 months ago

I slso encountered this. As a workaround you can manually edit the TF state and add project to a list of google_container_registry resource attributes. Like this:

"attributes": {
  "location": "some_location",
  "project": "project_foobar"   # <== added this one
shpml commented 10 months ago

I slso encountered this. As a workaround you can manually edit the TF state and add project to a list of google_container_registry resource attributes. Like this:

"attributes": {
  "location": "some_location",
  "project": "project_foobar"   # <== added this one

Thanks for the workaround @aleks-m

For those working with remote state:

roaks3 commented 1 week ago

Note that Container Registry is now deprecated in favor of Artifact Registry https://github.com/hashicorp/terraform-provider-google/issues/19661. FWIW, this looks like a bug in how the project field is handled by google_container_registry specifically, but moving forward, I don't think this type of bucket management is needed at all.

Per https://cloud.google.com/artifact-registry/docs/transition/transition-from-gcr:

In Artifact Registry, there are no Cloud Storage buckets to manage in your Google Cloud projects. You perform image management actions directly on a repository.