Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/storagegateway_smb_file_share - support cache attributes + case sensitivity + fix docs #14790

Merged
merged 7 commits into from
Aug 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cache attributes
  • Loading branch information
DrFaust92 committed Aug 23, 2020
commit 78eb9f7f784e72086c311137028208af60629984
28 changes: 27 additions & 1 deletion aws/resource_aws_storagegateway_smb_file_share.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,20 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource {
Default: storagegateway.ObjectACLPrivate,
ValidateFunc: validation.StringInSlice(storagegateway.ObjectACL_Values(), false),
},
"cache_attributes": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cache_stale_timeout_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(300, 2592000),
},
},
},
},
"path": {
Type: schema.TypeString,
Computed: true,
@@ -168,6 +182,10 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in
input.SMBACLEnabled = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("cache_attributes"); ok {
input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{}))
}

log.Printf("[DEBUG] Creating Storage Gateway SMB File Share: %s", input)
output, err := conn.CreateSMBFileShare(input)
if err != nil {
@@ -231,6 +249,10 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte
return fmt.Errorf("error setting invalid_user_list: %s", err)
}

if err := d.Set("cache_attributes", flattenStorageGatewayNfsFileShareCacheAttributes(fileshare.CacheAttributes)); err != nil {
return fmt.Errorf("error setting cache_attributes: %w", err)
}

d.Set("kms_encrypted", fileshare.KMSEncrypted)
d.Set("kms_key_arn", fileshare.KMSKey)
d.Set("location_arn", fileshare.LocationARN)
@@ -265,7 +287,7 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in

if d.HasChanges("default_storage_class", "guess_mime_type_enabled", "invalid_user_list",
"kms_encrypted", "object_acl", "read_only", "requester_pays", "requester_pays",
"valid_user_list", "kms_key_arn", "audit_destination_arn", "smb_acl_enabled") {
"valid_user_list", "kms_key_arn", "audit_destination_arn", "smb_acl_enabled", "cache_attributes") {
input := &storagegateway.UpdateSMBFileShareInput{
DefaultStorageClass: aws.String(d.Get("default_storage_class").(string)),
FileShareARN: aws.String(d.Id()),
@@ -287,6 +309,10 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in
input.AuditDestinationARN = aws.String(v.(string))
}

if v, ok := d.GetOk("cache_attributes"); ok {
input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{}))
}

log.Printf("[DEBUG] Updating Storage Gateway SMB File Share: %s", input)
_, err := conn.UpdateSMBFileShare(input)
if err != nil {
74 changes: 67 additions & 7 deletions aws/resource_aws_storagegateway_smb_file_share_test.go
Original file line number Diff line number Diff line change
@@ -88,6 +88,7 @@ func TestAccAWSStorageGatewaySmbFileShare_Authentication_GuestAccess(t *testing.
resource.TestCheckResourceAttr(resourceName, "requester_pays", "false"),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", iamResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "valid_user_list.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "0"),
),
},
{
@@ -537,6 +538,49 @@ func TestAccAWSStorageGatewaySmbFileShare_audit(t *testing.T) {
})
}

func TestAccAWSStorageGatewaySmbFileShare_cacheAttributes(t *testing.T) {
var smbFileShare storagegateway.SMBFileShareInfo
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_storagegateway_smb_file_share.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSStorageGatewaySmbFileShareDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSStorageGatewaySmbFileShareCacheAttributesConfig(rName, 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.0.cache_stale_timeout_in_seconds", "300"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSStorageGatewaySmbFileShareCacheAttributesConfig(rName, 500),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.0.cache_stale_timeout_in_seconds", "500"),
),
},
{
Config: testAccAWSStorageGatewaySmbFileShareCacheAttributesConfig(rName, 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cache_attributes.0.cache_stale_timeout_in_seconds", "300"),
),
},
},
})
}

func testAccCheckAWSStorageGatewaySmbFileShareDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).storagegatewayconn

@@ -932,9 +976,9 @@ func testAccAWSStorageGatewaySmbFileShareSMBACLConfig(rName string, enabled bool
return testAccAWSStorageGateway_SmbFileShare_ActiveDirectoryBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_smb_file_share" "test" {
authentication = "ActiveDirectory"
gateway_arn = "${aws_storagegateway_gateway.test.arn}"
location_arn = "${aws_s3_bucket.test.arn}"
role_arn = "${aws_iam_role.test.arn}"
gateway_arn = aws_storagegateway_gateway.test.arn
location_arn = aws_s3_bucket.test.arn
role_arn = aws_iam_role.test.arn
smb_acl_enabled = %[1]t
}
`, enabled)
@@ -949,10 +993,10 @@ resource "aws_cloudwatch_log_group" "test" {
resource "aws_storagegateway_smb_file_share" "test" {
# Use GuestAccess to simplify testing
authentication = "GuestAccess"
gateway_arn = "${aws_storagegateway_gateway.test.arn}"
location_arn = "${aws_s3_bucket.test.arn}"
role_arn = "${aws_iam_role.test.arn}"
audit_destination_arn = "${aws_cloudwatch_log_group.test.arn}"
gateway_arn = aws_storagegateway_gateway.test.arn
location_arn = aws_s3_bucket.test.arn
role_arn = aws_iam_role.test.arn
audit_destination_arn = aws_cloudwatch_log_group.test.arn
}
`, rName)
}
@@ -977,3 +1021,19 @@ resource "aws_storagegateway_smb_file_share" "test" {
}
`, rName)
}

func testAccAWSStorageGatewaySmbFileShareCacheAttributesConfig(rName string, timeout int) string {
return testAccAWSStorageGateway_SmbFileShare_GuestAccessBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_smb_file_share" "test" {
# Use GuestAccess to simplify testing
authentication = "GuestAccess"
gateway_arn = aws_storagegateway_gateway.test.arn
location_arn = aws_s3_bucket.test.arn
role_arn = aws_iam_role.test.arn

cache_attributes {
cache_stale_timeout_in_seconds = %[1]d
}
}
`, timeout)
}
8 changes: 8 additions & 0 deletions website/docs/r/storagegateway_smb_file_share.html.markdown
Original file line number Diff line number Diff line change
@@ -53,12 +53,20 @@ The following arguments are supported:
* `kms_encrypted` - (Optional) Boolean value if `true` to use Amazon S3 server side encryption with your own AWS KMS key, or `false` to use a key managed by Amazon S3. Defaults to `false`.
* `kms_key_arn` - (Optional) Amazon Resource Name (ARN) for KMS key used for Amazon S3 server side encryption. This value can only be set when `kms_encrypted` is true.
* `object_acl` - (Optional) Access Control List permission for S3 bucket objects. Defaults to `private`.
* `cache_attributes` - (Optional) Refresh cache information. see [Cache Attributes](#cache_attributes) for more details.
* `read_only` - (Optional) Boolean to indicate write status of file share. File share does not accept writes if `true`. Defaults to `false`.
* `requester_pays` - (Optional) Boolean who pays the cost of the request and the data download from the Amazon S3 bucket. Set this value to `true` if you want the requester to pay instead of the bucket owner. Defaults to `false`.
* `smb_acl_enabled` - (Optional) Set this value to `true` to enable ACL (access control list) on the SMB fileshare. Set it to `false` to map file and directory permissions to the POSIX permissions. This setting applies only to `ActiveDirectory` authentication type.
* `valid_user_list` - (Optional) A list of users in the Active Directory that are allowed to access the file share. Only valid if `authentication` is set to `ActiveDirectory`.
* `tags` - (Optional) Key-value map of resource tags

### cache_attributes

* `cache_stale_timeout_in_seconds` - (Optional) Refreshes a file share's cache by using Time To Live (TTL).
TTL is the length of time since the last refresh after which access to the directory would cause the file gateway
to first refresh that directory's contents from the Amazon S3 bucket. Valid Values: 300 to 2,592,000 seconds (5 minutes to 30 days)


## Attribute Reference

In addition to all arguments above, the following attributes are exported: