Skip to content

Commit

Permalink
remove validation for empty prefix (#689)
Browse files Browse the repository at this point in the history
* remove validation for empty prefix

* update change log
  • Loading branch information
digna-ionos authored Oct 10, 2024
1 parent 1bd720c commit 1efb6c2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- Remove `image_alias` sets from `ionoscloud_volume` data source and resource
### Documentation
- Remove `image_alias` from `ionocloud_volume` data source and resource docs
### Fixes
- Allow empty `prefix` for bucket lifecycle configuration rules
## 6.5.7
### Fixes
- Fix documentation rendering of `autoscaling_group` resource and data source, `dbaas_mongo_template` data source and `server_boot_device_selection` resource in Terraform registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *bucketLifecycleConfiguration) Schema(ctx context.Context, req resource.
"prefix": schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 1024),
stringvalidator.LengthBetween(0, 1024),
},
Description: "Object key prefix identifying one or more objects to which the rule applies.",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ func TestAccBucketLifecycleConfigurationResourceMultipleRules(t *testing.T) {

}

func TestAccBucketLifecycleConfigurationResourceEmptyPrefix(t *testing.T) {
ctx := context.Background()
bucketName := acctest.GenerateRandomResourceName(bucketPrefix)
name := "ionoscloud_s3_bucket_lifecycle_configuration.test"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
PreCheck: func() {
acctest.PreCheck(t)
},
CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccBucketLifecycleConfigurationConfig_emptyPrefix(bucketName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLifecycleConfigurationExists(ctx, name),
resource.TestCheckResourceAttr(name, "bucket", bucketName),
resource.TestCheckResourceAttr(name, "rule.0.id", "Logs delete"),
resource.TestCheckResourceAttr(name, "rule.0.status", "Enabled"),
resource.TestCheckResourceAttr(name, "rule.0.prefix", ""),
resource.TestCheckResourceAttr(name, "rule.0.expiration.days", "90"),
),
},
},
})
}

func testAccBucketLifecycleConfigurationConfig_base(bucketName string) string {
return fmt.Sprintf(`
resource "ionoscloud_s3_bucket" "test" {
Expand Down Expand Up @@ -163,6 +190,25 @@ resource "ionoscloud_s3_bucket_lifecycle_configuration" "test" {
`))
}

func testAccBucketLifecycleConfigurationConfig_emptyPrefix(bucketName string) string {
return utils.ConfigCompose(testAccBucketLifecycleConfigurationConfig_base(bucketName), fmt.Sprintf(`
resource "ionoscloud_s3_bucket_lifecycle_configuration" "test" {
bucket = ionoscloud_s3_bucket.test.name
rule {
id = "Logs delete"
status = "Enabled"
prefix = ""
expiration {
days = 90
}
}
}
`))
}

func testAccBucketLifecycleConfigurationConfig_noncurrent(bucketName string) string {
return utils.ConfigCompose(testAccBucketLifecycleConfigurationConfig_base(bucketName), fmt.Sprintf(`
resource "ionoscloud_s3_bucket_lifecycle_configuration" "test" {
Expand Down

0 comments on commit 1efb6c2

Please sign in to comment.