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

Destroy object versions on bucket force_destroy #524

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion minio/resource_minio_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func minioDeleteBucket(ctx context.Context, d *schema.ResourceData, meta interfa

// List all objects from a bucket-name with a matching prefix.
for object := range bucketConfig.MinioClient.ListObjects(ctx, d.Id(), minio.ListObjectsOptions{
Recursive: true,
Recursive: true,
WithVersions: true,
}) {
if object.Err != nil {
log.Fatalln(object.Err)
Expand Down
40 changes: 40 additions & 0 deletions minio/resource_minio_s3_bucket_versioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ func TestAccS3BucketVersioning_update(t *testing.T) {
})
}

func TestAccS3BucketVersioning_forceDestroy(t *testing.T) {
name := acctest.RandomWithPrefix("tf-version-force-destroy")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckMinioS3BucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccBucketVersioningObjectConfig(name, "Enabled"),
Check: resource.ComposeTestCheckFunc(
testAccCheckMinioS3BucketExists("minio_s3_bucket.bucket"),
testAccCheckBucketHasVersioning(
"minio_s3_bucket_versioning.bucket",
S3MinioBucketVersioningConfiguration{
Status: "Enabled",
},
),
),
},
},
})
}

func testAccBucketVersioningConfig(bucketName string, status string, prefixes []string, excludeFolders bool) string {
prefixSlice := []string{}
for _, v := range prefixes {
Expand All @@ -111,6 +135,22 @@ resource "minio_s3_bucket_versioning" "bucket" {
`, bucketName, status, strings.Join(prefixSlice, ", "), excludeFolders)
}

func testAccBucketVersioningObjectConfig(bucketName string, status string) string {
return fmt.Sprintf(`
resource "minio_s3_bucket" "bucket" {
bucket = "%s"
force_destroy = true
}

resource "minio_s3_bucket_versioning" "bucket" {
bucket = minio_s3_bucket.bucket.bucket
versioning_configuration {
status = "%s"
}
}
`, bucketName, status)
}

func testAccCheckBucketHasVersioning(n string, config S3MinioBucketVersioningConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down