Skip to content

Commit

Permalink
Add support for object locking in minio_s3_bucket resource. (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilyre authored May 6, 2023
1 parent c92304a commit 9e948d5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/resources/s3_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ output "minio_url" {
- **force_destroy** (Boolean)
- **id** (String) The ID of this resource.
- **quota** (Number) The limit of the amount of data in the bucket (bytes).
- **object_locking** (Boolean) - Whether object locking should be enabled for the bucket.

### Read-Only

Expand Down
17 changes: 9 additions & 8 deletions minio/check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ func BucketConfig(d *schema.ResourceData, meta interface{}) *S3MinioBucket {
m := meta.(*S3MinioClient)

return &S3MinioBucket{
MinioClient: m.S3Client,
MinioAdmin: m.S3Admin,
MinioRegion: m.S3Region,
MinioAccess: m.S3UserAccess,
MinioBucket: d.Get("bucket").(string),
MinioBucketPrefix: d.Get("bucket_prefix").(string),
MinioACL: d.Get("acl").(string),
MinioForceDestroy: d.Get("force_destroy").(bool),
MinioClient: m.S3Client,
MinioAdmin: m.S3Admin,
MinioRegion: m.S3Region,
MinioAccess: m.S3UserAccess,
MinioBucket: d.Get("bucket").(string),
MinioBucketPrefix: d.Get("bucket_prefix").(string),
MinioACL: d.Get("acl").(string),
MinioForceDestroy: d.Get("force_destroy").(bool),
ObjectLockingEnabled: d.Get("object_locking").(bool),
}
}

Expand Down
17 changes: 9 additions & 8 deletions minio/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ type S3MinioClient struct {

// S3MinioBucket defines minio config
type S3MinioBucket struct {
MinioClient *minio.Client
MinioAdmin *madmin.AdminClient
MinioRegion string
MinioBucket string
MinioBucketPrefix string
MinioACL string
MinioAccess string
MinioForceDestroy bool
MinioClient *minio.Client
MinioAdmin *madmin.AdminClient
MinioRegion string
MinioBucket string
MinioBucketPrefix string
MinioACL string
MinioAccess string
MinioForceDestroy bool
ObjectLockingEnabled bool
}

// S3MinioBucketPolicy defines bucket policy config
Expand Down
11 changes: 10 additions & 1 deletion minio/resource_minio_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func resourceMinioBucket() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"object_locking": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -109,8 +115,10 @@ func minioCreateBucket(ctx context.Context, d *schema.ResourceData, meta interfa
}

err := bucketConfig.MinioClient.MakeBucket(ctx, bucket, minio.MakeBucketOptions{
Region: region,
Region: region,
ObjectLocking: bucketConfig.ObjectLockingEnabled,
})

if err != nil {
log.Printf("%s", NewResourceErrorStr("unable to create bucket", bucket, err))
return NewResourceError("unable to create bucket", bucket, err)
Expand Down Expand Up @@ -153,6 +161,7 @@ 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
2 changes: 2 additions & 0 deletions minio/resource_minio_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestAccMinioS3Bucket_basic(t *testing.T) {
resourceName, "bucket_domain_name", testAccBucketDomainName(rInt)),
resource.TestCheckResourceAttr(
resourceName, "acl", testAccBucketACL(acl)),
resource.TestCheckResourceAttr(
resourceName, "object_locking", "false"),
),
},
{
Expand Down

0 comments on commit 9e948d5

Please sign in to comment.