Skip to content

Commit

Permalink
F/resource aws datasync location s3 storage class (#19190)
Browse files Browse the repository at this point in the history
* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/aws_securityhub_member: email is optional variable

* f/resource_aws_datasync_location_s3

* f/resource_aws_datasync_location_s3

* f/resource_aws_datasync_location_s3

* f/resource_aws_datasync_location_s3

* resource/aws_elasticache_global_replication_group: Remove deprecated parameter actual_engine_version

* resource/aws_elasticache_global_replication_group: Remove deprecated parameter actual_engine_version

* resource/aws_elasticache_global_replication_group: Remove deprecated parameter actual_engine_version

* Update website/docs/r/datasync_location_s3.html.markdown

* Add CHANGELOG entry.

Co-authored-by: Kit Ewbank <[email protected]>
  • Loading branch information
nikhil-goenka and ewbankkit authored May 4, 2021
1 parent f3eb686 commit e97a6cd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/19190.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_datasync_location_s3: Add `s3_storage_class` argument
```
12 changes: 12 additions & 0 deletions aws/resource_aws_datasync_location_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func resourceAwsDataSyncLocationS3() *schema.Resource {
},
},
},
"s3_storage_class": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(datasync.S3StorageClass_Values(), false),
},
"subdirectory": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -90,6 +97,10 @@ func resourceAwsDataSyncLocationS3Create(d *schema.ResourceData, meta interface{
Tags: tags.IgnoreAws().DatasyncTags(),
}

if v, ok := d.GetOk("s3_storage_class"); ok {
input.S3StorageClass = aws.String(v.(string))
}

log.Printf("[DEBUG] Creating DataSync Location S3: %s", input)

var output *datasync.CreateLocationS3Output
Expand Down Expand Up @@ -165,6 +176,7 @@ func resourceAwsDataSyncLocationS3Read(d *schema.ResourceData, meta interface{})

d.Set("subdirectory", subdirectory)
d.Set("uri", output.LocationUri)
d.Set("s3_storage_class", output.S3StorageClass)

tags, err := keyvaluetags.DatasyncListTags(conn, d.Id())

Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_datasync_location_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,42 @@ func TestAccAWSDataSyncLocationS3_basic(t *testing.T) {
})
}

func TestAccAWSDataSyncLocationS3_storageclass(t *testing.T) {
var locationS31 datasync.DescribeLocationS3Output
rName := acctest.RandomWithPrefix("tf-acc-test")
iamRoleResourceName := "aws_iam_role.test"
resourceName := "aws_datasync_location_s3.test"
s3BucketResourceName := "aws_s3_bucket.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) },
ErrorCheck: testAccErrorCheck(t, datasync.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDataSyncLocationS3Destroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDataSyncLocationS3ConfigStorageClass(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDataSyncLocationS3Exists(resourceName, &locationS31),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`location/loc-.+`)),
resource.TestCheckResourceAttrPair(resourceName, "s3_bucket_arn", s3BucketResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "s3_config.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "s3_config.0.bucket_access_role_arn", iamRoleResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "subdirectory", "/test/"),
resource.TestCheckResourceAttr(resourceName, "s3_storage_class", "STANDARD_IA"),
resource.TestMatchResourceAttr(resourceName, "uri", regexp.MustCompile(`^s3://.+/`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"s3_bucket_arn"},
},
},
})
}

func TestAccAWSDataSyncLocationS3_disappears(t *testing.T) {
var locationS31 datasync.DescribeLocationS3Output
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -326,6 +362,22 @@ resource "aws_datasync_location_s3" "test" {
`
}

func testAccAWSDataSyncLocationS3ConfigStorageClass(rName string) string {
return testAccAWSDataSyncLocationS3ConfigBase(rName) + `
resource "aws_datasync_location_s3" "test" {
s3_bucket_arn = aws_s3_bucket.test.arn
subdirectory = "/test"
s3_storage_class = "STANDARD_IA"
s3_config {
bucket_access_role_arn = aws_iam_role.test.arn
}
depends_on = [aws_iam_role_policy.test]
}
`
}

func testAccAWSDataSyncLocationS3ConfigTags1(rName, key1, value1 string) string {
return testAccAWSDataSyncLocationS3ConfigBase(rName) + fmt.Sprintf(`
resource "aws_datasync_location_s3" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/datasync_location_s3.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:

* `s3_bucket_arn` - (Required) Amazon Resource Name (ARN) of the S3 Bucket.
* `s3_config` - (Required) Configuration block containing information for connecting to S3.
* `s3_storage_class` - (Optional) The Amazon S3 storage class that you want to store your files in when this location is used as a task destination. [Valid values](https://docs.aws.amazon.com/datasync/latest/userguide/create-s3-location.html#using-storage-classes)
* `subdirectory` - (Required) Prefix to perform actions as source or destination.
* `tags` - (Optional) Key-value pairs of resource tags to assign to the DataSync Location. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

Expand Down

0 comments on commit e97a6cd

Please sign in to comment.