Skip to content

Removing a label on a bucket doesn't work #1350

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

Closed
rolandkool opened this issue Apr 18, 2018 · 7 comments
Closed

Removing a label on a bucket doesn't work #1350

rolandkool opened this issue Apr 18, 2018 · 7 comments
Labels
bug forward/review In review; remove label to forward service/storage upstream

Comments

@rolandkool
Copy link
Contributor

Hi there,

When a bucket contains a label that is not part of the terraform file or state, terraform tries to remove it. However this doesn't work so with every run it tries to remove the label.

Terraform Version

Terraform 0.11.5
Google Provider 1.9.0

Affected Resource(s)

  • google_storage_bucket

Terraform Configuration Files

resource "google_storage_bucket" "testbucket" {
  name          = "myproject-testbucket"
  project       = "myproject"
  location      = "EUROPE-WEST1"
  storage_class = "REGIONAL"
  force_destroy = true

  labels = {
    opex = "teamxyz"
    application = "myapp"
  }
}

Debug Output

When adding a label to this bucket called 'remove' with value 'me', terraform shows this:

google_storage_bucket.testbucket:
Modifying... (ID: myproject-testbucket)
labels.%: "3" => "2"
labels.remove: "me" => ""

Expected Behavior

Label should be removed

Actual Behavior

Label remains on the bucket

@nat-henderson
Copy link
Contributor

Interesting - you're right. The requests seem to be getting correctly formulated... I wonder what's going on there. I'll check on that.

@rolandkool
Copy link
Contributor Author

Any news on this?

@rosbo rosbo self-assigned this May 28, 2018
@rosbo
Copy link
Contributor

rosbo commented May 28, 2018

The patch method update existing labels or add new ones when you pass a map of labels. You can also delete all labels by setting the labels field to NULL. You can set the value of a label explicitly to "null" in the JSON body. However, the golang client takes a map[string]string for the labels field. You can't pass a nil, only an empty string and empty string is a valid label value... Because of this, there is no way to delete a single label using the patch method.

There is an update method which replaces all the metadata which you can use to delete labels. You must pass all the metadata in the body of the request otherwise, you will erase the parts you omit.

I will explore the approach using the update method.

@rosbo
Copy link
Contributor

rosbo commented May 28, 2018

After digging some more, you can pass a null value using the go client for a given label key by adding labels.my-key to the NullField on the resource.

@nat-henderson
Copy link
Contributor

Thanks, @rosbo!

@rolandkool
Copy link
Contributor Author

Verified that the labels are indeed removed now (with a build from the master branch).
Thanks!

@ghost
Copy link

ghost commented Nov 18, 2018

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!

@ghost ghost unassigned rosbo Nov 18, 2018
@ghost ghost locked and limited conversation to collaborators Nov 18, 2018
@github-actions github-actions bot added service/storage forward/review In review; remove label to forward labels Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/storage upstream
Projects
None yet
Development

No branches or pull requests

4 participants