diff --git a/minio/resource_minio_s3_bucket.go b/minio/resource_minio_s3_bucket.go index 4811f7b6..a52bfb0c 100644 --- a/minio/resource_minio_s3_bucket.go +++ b/minio/resource_minio_s3_bucket.go @@ -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) diff --git a/minio/resource_minio_s3_bucket_versioning_test.go b/minio/resource_minio_s3_bucket_versioning_test.go index 7014c1d9..6a3adb6d 100644 --- a/minio/resource_minio_s3_bucket_versioning_test.go +++ b/minio/resource_minio_s3_bucket_versioning_test.go @@ -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 { @@ -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]