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

file_name_prefix required in lifecycle_rules #3

Closed
WebSpider opened this issue Feb 1, 2021 · 3 comments
Closed

file_name_prefix required in lifecycle_rules #3

WebSpider opened this issue Feb 1, 2021 · 3 comments
Assignees
Labels
more-information-needed wontfix This will not be worked on

Comments

@WebSpider
Copy link

WebSpider commented Feb 1, 2021

Hi!

It turns out file_name_prefix is currently required when you want to set a lifecycle_rule, however:

  1. This is currently not documented
  2. The web interface has no such requirement (maybe it does an assumption of "*" ?)

How to replicate:

resource "b2_bucket" "my-blob"{
  bucket_name = "my-name"
  bucket_type = "allPrivate"

 lifecycle_rules {
   days_from_hiding_to_deleting  = 30
   days_from_uploading_to_hiding = 0
 }
}

Try and apply it .. the error returns:

terraform apply
Releasing state lock. This may take a few moments...

Error: Missing required argument

  on my.tf line 5, in resource "b2_bucket" "my-blob":
 5:  lifecycle_rules {

The argument "file_name_prefix" is required, but no definition was found.

Used terraform version: 0.13.5

@mlech-reef mlech-reef self-assigned this Feb 2, 2021
@mlech-reef
Copy link
Collaborator

mlech-reef commented Feb 2, 2021

Hi @WebSpider!

Thank you for reporting this.

It is documented in the API description:
https://www.backblaze.com/b2/docs/lifecycle_rules.html

A bucket can have up to 100 lifecycle rules. Each rule has a fileNamePrefix that specifies which files in the bucket it applies to. Any file whose name starts with the prefix is subject to the rule. A prefix of the empty string, "", means that the rule applies to all files in the bucket.

WARNING: This means that a lifecycle rule with fileNamePrefix of the empty string could potentially delete ALL files in a bucket, so please tread carefully.

Probably because of the potentially destructive operation of "empty" fileNamePrefix, this field must be explicitly set when working with the raw API and the B2 CLI:

$ b2 create-bucket --lifecycleRules='[{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": 7}]' my-name allPublic
ERROR: required field fileNamePrefix is missing (bad_request)

The provider documentation only mentions that the parameter is required:
https://registry.terraform.io/providers/Backblaze/b2/latest/docs/resources/bucket#nested-schema-for-lifecycle_rules
We are working on improving the provider documentation as it is still in beta. Every contributions are welcome

Best regards,
Maciej Lech

@ppolewicz
Copy link
Collaborator

Will we fix it in b2-sdk-python with a client-side exception?

@mlech-reef
Copy link
Collaborator

Will we fix it in b2-sdk-python with a client-side exception?

Backblaze/b2-sdk-python#188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants