Skip to content

Commit

Permalink
Fix bucket import always defaulting to object_locking = false (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilyre authored May 8, 2023
1 parent 3feb548 commit 3f09156
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions minio/import_minio_s3_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ func resourceMinioS3BucketImportState(
bucketConfig := BucketConfig(d, meta)

conn := meta.(*S3MinioClient).S3Client

bucketObjectLocking, _, _, _, err := conn.GetObjectLockConfig(ctx, d.Id())
object_locking := err == nil && bucketObjectLocking == "Enabled"
_ = d.Set("object_locking", object_locking)

pol, err := conn.GetBucketPolicy(ctx, d.Id())
if err != nil {
return nil, fmt.Errorf("error importing Minio S3 bucket policy: %s", err)
}

if pol == "" {
_ = d.Set("acl", "private")
return []*schema.ResourceData{d}, nil
Expand Down
1 change: 0 additions & 1 deletion minio/resource_minio_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func minioReadBucket(ctx context.Context, d *schema.ResourceData, meta interface

_ = d.Set("arn", bucketArn(d.Id()))
_ = d.Set("bucket_domain_name", bucketDomainName(d.Id(), bucketURL))
_ = d.Set("object_locking", bucketConfig.ObjectLockingEnabled)

return nil
}
Expand Down
47 changes: 47 additions & 0 deletions minio/resource_minio_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ func TestAccMinioS3Bucket_basic(t *testing.T) {
})
}

func TestAccMinioS3Bucket_objectLocking(t *testing.T) {
rInt := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
acl := "public-read"
resourceName := "minio_s3_bucket.bucket"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckMinioS3BucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccMinioS3BucketConfigObjectLockingEnabled(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckMinioS3BucketExists(resourceName),
resource.TestCheckResourceAttr(
resourceName, "bucket", testAccBucketName(rInt)),
resource.TestCheckResourceAttr(
resourceName, "arn", testAccBucketArn(rInt)),
resource.TestCheckResourceAttr(
resourceName, "bucket_domain_name", testAccBucketDomainName(rInt)),
resource.TestCheckResourceAttr(
resourceName, "acl", testAccBucketACL(acl)),
resource.TestCheckResourceAttr(
resourceName, "object_locking", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"force_destroy"},
},
},
})
}

func TestAccMinioS3Bucket_Bucket_EmptyString(t *testing.T) {
resourceName := "minio_s3_bucket.test"

Expand Down Expand Up @@ -401,6 +438,16 @@ resource "minio_s3_bucket" "bucket" {
`, randInt)
}

func testAccMinioS3BucketConfigObjectLockingEnabled(randInt string) string {
return fmt.Sprintf(`
resource "minio_s3_bucket" "bucket" {
bucket = "%s"
acl = "public-read"
object_locking = true
}
`, randInt)
}

func testAccMinioS3BucketDestroyedConfig(randInt string) string {
return fmt.Sprintf(`
resource "minio_s3_bucket" "bucket" {
Expand Down

0 comments on commit 3f09156

Please sign in to comment.