Backblaze / terraform-provider-b2

Terraform Provider for Backblaze B2 Cloud Storage
Other
41 stars 11 forks source link

file_name_prefix required in lifecycle_rules #3

Closed WebSpider closed 3 years ago

WebSpider commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

mlech-reef commented 3 years ago

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

Backblaze/b2-sdk-python#188