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

google_storage_bucket_object is missing a generation output #14117

Comments

@mattmoor
Copy link

mattmoor commented Mar 28, 2023

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 the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.3.8
on darwin_arm64
+ provider registry.terraform.io/hashicorp/google v4.58.0
+ provider registry.terraform.io/hashicorp/random v3.4.3

Affected Resource(s)

  • google_storage_bucket_object

Terraform Configuration Files

resource "random_id" "id" {
  byte_length = 4
}

resource "google_storage_bucket" "example-bucket" {
  name          = "mattmoor-example-${random_id.id.hex}"
  location      = "US"
  force_destroy = true

  uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "example-object" {
  name   = "example-object"
  bucket = google_storage_bucket.example-bucket.name
  content = <<EOF
    This is the object content I want to appear in GCS
  EOF
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

I would expect google_storage_bucket_object to have a .generation attribute.

Downstream resources referencing this object via:

gs://${google_storage_bucket.example-bucket.name}/${google_storage_bucket_object.example-object.name}

... will have a bad time because the reference doesn't reflect potential content changes in the object made by IaC.

🚨 This is why I am filing this as a bug, not a feature. 🚨

An example of such a resource: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dataflow_job

Generally downstream resources should reference a form like this, which incorporates the generation and is immutable:

gs://my-awesome-bucket/just-a-folder/cloud-storage.logo.png#1456530077282000

Actual Behavior

The only place the generation appears to be surfaced at all is embedded in media_link, e.g.

media-link = "https://storage.googleapis.com/download/storage/v1/b/mattmoor-example-9ade25ca/o/example-object?generation=1680001044297616&alt=media"

Steps to Reproduce

Try to access generation

Important Factoids

Mutable references in declarative infrastructure are incredibly problematic. Generally you want to reference immutable identifiers which change exactly when the resource changes, so that changes cascade through the dependency graph.

Better than simple vendor-enforced immutability is content-addressability, but alas the former is the best we are likely to see from GCS.

Another great example of this is tags vs. digests in Kubernetes, which is my personal "hill to die on".

References

This feels related but different: #10488

b/276933153

@mattmoor mattmoor added the bug label Mar 28, 2023
@edwardmedia edwardmedia self-assigned this Mar 28, 2023
@edwardmedia edwardmedia removed their assignment Mar 28, 2023
@rileykarson rileykarson added this to the Goals milestone Apr 3, 2023
@benwatsonnandos
Copy link

This would be really useful. Here's a regex to extract the generation in Terraform:

generation = tonumber(regex("generation=(\\d+)", google_storage_bucket_object.archive.media_link)[0])

@jc0b
Copy link

jc0b commented Nov 14, 2023

This would be reaaally nice to be able to do, especially in conjunction with google_cloudfunctions2_function, which takes the generation of an object as an argument if you're using GCS for your storage_source.

@jakewan
Copy link

jakewan commented Nov 14, 2023

@jc0b It's funny you mention this. This issue is exactly what provided the ummmph I needed to move to Cloud Build triggers to deploy Cloud Function changes.

Copy link

github-actions bot commented Sep 2, 2024

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.