mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Add support for S3 Bucket Acceleration (#6628)
This commit is contained in:
parent
7573367444
commit
811667023b
@ -293,6 +293,13 @@ func resourceAwsS3Bucket() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"acceleration_status": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
ValidateFunc: validateS3BucketAccelerationStatus,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,6 +402,12 @@ func resourceAwsS3BucketUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("acceleration_status") {
|
||||||
|
if err := resourceAwsS3BucketAccelerationUpdate(s3conn, d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return resourceAwsS3BucketRead(d, meta)
|
return resourceAwsS3BucketRead(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,6 +538,16 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//read the acceleration status
|
||||||
|
accelerate, err := s3conn.GetBucketAccelerateConfiguration(&s3.GetBucketAccelerateConfigurationInput{
|
||||||
|
Bucket: aws.String(d.Id()),
|
||||||
|
})
|
||||||
|
log.Printf("[DEBUG] S3 bucket: %s, read Acceleration: %v", d.Id(), accelerate)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.Set("acceleration_status", accelerate.Status)
|
||||||
|
|
||||||
// Read the logging configuration
|
// Read the logging configuration
|
||||||
logging, err := s3conn.GetBucketLogging(&s3.GetBucketLoggingInput{
|
logging, err := s3conn.GetBucketLogging(&s3.GetBucketLoggingInput{
|
||||||
Bucket: aws.String(d.Id()),
|
Bucket: aws.String(d.Id()),
|
||||||
@ -1095,6 +1118,26 @@ func resourceAwsS3BucketLoggingUpdate(s3conn *s3.S3, d *schema.ResourceData) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceAwsS3BucketAccelerationUpdate(s3conn *s3.S3, d *schema.ResourceData) error {
|
||||||
|
bucket := d.Get("bucket").(string)
|
||||||
|
enableAcceleration := d.Get("acceleration_status").(string)
|
||||||
|
|
||||||
|
i := &s3.PutBucketAccelerateConfigurationInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
AccelerateConfiguration: &s3.AccelerateConfiguration{
|
||||||
|
Status: aws.String(enableAcceleration),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
log.Printf("[DEBUG] S3 put bucket acceleration: %#v", i)
|
||||||
|
|
||||||
|
_, err := s3conn.PutBucketAccelerateConfiguration(i)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error putting S3 acceleration: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func resourceAwsS3BucketLifecycleUpdate(s3conn *s3.S3, d *schema.ResourceData) error {
|
func resourceAwsS3BucketLifecycleUpdate(s3conn *s3.S3, d *schema.ResourceData) error {
|
||||||
bucket := d.Get("bucket").(string)
|
bucket := d.Get("bucket").(string)
|
||||||
|
|
||||||
@ -1290,6 +1333,18 @@ func normalizeRegion(region string) string {
|
|||||||
return region
|
return region
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateS3BucketAccelerationStatus(v interface{}, k string) (ws []string, errors []error) {
|
||||||
|
validTypes := map[string]struct{}{
|
||||||
|
"Enabled": struct{}{},
|
||||||
|
"Suspended": struct{}{},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := validTypes[v.(string)]; !ok {
|
||||||
|
errors = append(errors, fmt.Errorf("S3 Bucket Acceleration Status %q is invalid, must be %q or %q", v.(string), "Enabled", "Suspended"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func expirationHash(v interface{}) int {
|
func expirationHash(v interface{}) int {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
|
@ -49,6 +49,34 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSS3Bucket_acceleration(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSS3BucketConfigWithAcceleration(rInt),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_s3_bucket.bucket", "acceleration_status", "Enabled"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSS3BucketConfigWithoutAcceleration(rInt),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_s3_bucket.bucket", "acceleration_status", "Suspended"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
||||||
rInt := acctest.RandInt()
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
@ -796,6 +824,26 @@ EOF
|
|||||||
`, randInt)
|
`, randInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccAWSS3BucketConfigWithAcceleration(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_s3_bucket" "bucket" {
|
||||||
|
bucket = "tf-test-bucket-%d"
|
||||||
|
acl = "public-read"
|
||||||
|
acceleration_status = "Enabled"
|
||||||
|
}
|
||||||
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccAWSS3BucketConfigWithoutAcceleration(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_s3_bucket" "bucket" {
|
||||||
|
bucket = "tf-test-bucket-%d"
|
||||||
|
acl = "public-read"
|
||||||
|
acceleration_status = "Suspended"
|
||||||
|
}
|
||||||
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAWSS3BucketConfigWithPolicy(randInt int) string {
|
func testAccAWSS3BucketConfigWithPolicy(randInt int) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
|
@ -172,6 +172,7 @@ The following arguments are supported:
|
|||||||
* `versioning` - (Optional) A state of [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) (documented below)
|
* `versioning` - (Optional) A state of [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) (documented below)
|
||||||
* `logging` - (Optional) A settings of [bucket logging](https://docs.aws.amazon.com/AmazonS3/latest/UG/ManagingBucketLogging.html) (documented below).
|
* `logging` - (Optional) A settings of [bucket logging](https://docs.aws.amazon.com/AmazonS3/latest/UG/ManagingBucketLogging.html) (documented below).
|
||||||
* `lifecycle_rule` - (Optional) A configuration of [object lifecycle management](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html) (documented below).
|
* `lifecycle_rule` - (Optional) A configuration of [object lifecycle management](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html) (documented below).
|
||||||
|
* `acceleration_status` - (Optional) Sets the accelerate configuration of an existing bucket. Can be `Enabled` or `Suspended`.
|
||||||
|
|
||||||
The `website` object supports the following:
|
The `website` object supports the following:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user