From 905d57a2d1927388ef8ad86b92490767cb00d5c0 Mon Sep 17 00:00:00 2001 From: Gareth Oakley Date: Tue, 3 Nov 2020 22:49:33 +0000 Subject: [PATCH] r/aws_storagegateway_smb_file_share: Add `file_share_name` argument --- ...ource_aws_storagegateway_smb_file_share.go | 16 ++++++- ..._aws_storagegateway_smb_file_share_test.go | 48 +++++++++++++++++++ ...toragegateway_smb_file_share.html.markdown | 1 + 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_storagegateway_smb_file_share.go b/aws/resource_aws_storagegateway_smb_file_share.go index 8c7c5bfd2a4..f0ad62aa40f 100644 --- a/aws/resource_aws_storagegateway_smb_file_share.go +++ b/aws/resource_aws_storagegateway_smb_file_share.go @@ -63,6 +63,11 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "file_share_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, "gateway_arn": { Type: schema.TypeString, Required: true, @@ -191,6 +196,10 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in input.AuditDestinationARN = aws.String(v.(string)) } + if v, ok := d.GetOk("file_share_name"); ok { + input.FileShareName = aws.String(v.(string)) + } + if v, ok := d.GetOk("smb_acl_enabled"); ok { input.SMBACLEnabled = aws.Bool(v.(bool)) } @@ -255,6 +264,7 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte d.Set("authentication", fileshare.Authentication) d.Set("default_storage_class", fileshare.DefaultStorageClass) d.Set("fileshare_id", fileshare.FileShareId) + d.Set("file_share_name", fileshare.FileShareName) d.Set("gateway_arn", fileshare.GatewayARN) d.Set("guess_mime_type_enabled", fileshare.GuessMIMETypeEnabled) d.Set("case_sensitivity", fileshare.CaseSensitivity) @@ -306,7 +316,7 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in if d.HasChanges("admin_user_list", "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", "cache_attributes", - "case_sensitivity") { + "case_sensitivity", "file_share_name") { input := &storagegateway.UpdateSMBFileShareInput{ DefaultStorageClass: aws.String(d.Get("default_storage_class").(string)), FileShareARN: aws.String(d.Id()), @@ -330,6 +340,10 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in input.AuditDestinationARN = aws.String(v.(string)) } + if v, ok := d.GetOk("file_share_name"); ok { + input.FileShareName = aws.String(v.(string)) + } + if v, ok := d.GetOk("cache_attributes"); ok { input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) } diff --git a/aws/resource_aws_storagegateway_smb_file_share_test.go b/aws/resource_aws_storagegateway_smb_file_share_test.go index a6f3394e0eb..c900d2528d0 100644 --- a/aws/resource_aws_storagegateway_smb_file_share_test.go +++ b/aws/resource_aws_storagegateway_smb_file_share_test.go @@ -33,6 +33,7 @@ func TestAccAWSStorageGatewaySmbFileShare_Authentication_ActiveDirectory(t *test resource.TestCheckResourceAttr(resourceName, "authentication", "ActiveDirectory"), resource.TestCheckResourceAttr(resourceName, "default_storage_class", "S3_STANDARD"), resource.TestMatchResourceAttr(resourceName, "fileshare_id", regexp.MustCompile(`^share-`)), + resource.TestMatchResourceAttr(resourceName, "file_share_name", regexp.MustCompile(`^tf-acc-test-`)), resource.TestCheckResourceAttrPair(resourceName, "gateway_arn", gatewayResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "guess_mime_type_enabled", "true"), resource.TestCheckResourceAttr(resourceName, "invalid_user_list.#", "0"), @@ -81,6 +82,7 @@ func TestAccAWSStorageGatewaySmbFileShare_Authentication_GuestAccess(t *testing. resource.TestCheckResourceAttr(resourceName, "case_sensitivity", "ClientSpecified"), resource.TestCheckResourceAttr(resourceName, "default_storage_class", "S3_STANDARD"), resource.TestMatchResourceAttr(resourceName, "fileshare_id", regexp.MustCompile(`^share-`)), + resource.TestMatchResourceAttr(resourceName, "file_share_name", regexp.MustCompile(`^tf-acc-test-`)), resource.TestCheckResourceAttrPair(resourceName, "gateway_arn", gatewayResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "guess_mime_type_enabled", "true"), resource.TestCheckResourceAttr(resourceName, "invalid_user_list.#", "0"), @@ -136,6 +138,39 @@ func TestAccAWSStorageGatewaySmbFileShare_DefaultStorageClass(t *testing.T) { }) } +func TestAccAWSStorageGatewaySmbFileShare_FileShareName(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: testAccAWSStorageGatewaySmbFileShareConfig_FileShareName(rName, "foo_share"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare), + resource.TestCheckResourceAttr(resourceName, "file_share_name", "foo_share"), + ), + }, + { + Config: testAccAWSStorageGatewaySmbFileShareConfig_FileShareName(rName, "bar_share"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare), + resource.TestCheckResourceAttr(resourceName, "file_share_name", "bar_share"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSStorageGatewaySmbFileShare_Tags(t *testing.T) { var smbFileShare storagegateway.SMBFileShareInfo rName := acctest.RandomWithPrefix("tf-acc-test") @@ -881,6 +916,19 @@ resource "aws_storagegateway_smb_file_share" "test" { `, defaultStorageClass) } +func testAccAWSStorageGatewaySmbFileShareConfig_FileShareName(rName, fileShareName string) string { + return testAccAWSStorageGateway_SmbFileShare_GuestAccessBase(rName) + fmt.Sprintf(` +resource "aws_storagegateway_smb_file_share" "test" { + # Use GuestAccess to simplify testing + authentication = "GuestAccess" + file_share_name = %q + gateway_arn = aws_storagegateway_gateway.test.arn + location_arn = aws_s3_bucket.test.arn + role_arn = aws_iam_role.test.arn +} +`, fileShareName) +} + func testAccAWSStorageGatewaySmbFileShareConfig_GuessMIMETypeEnabled(rName string, guessMimeTypeEnabled bool) string { return testAccAWSStorageGateway_SmbFileShare_GuestAccessBase(rName) + fmt.Sprintf(` resource "aws_storagegateway_smb_file_share" "test" { diff --git a/website/docs/r/storagegateway_smb_file_share.html.markdown b/website/docs/r/storagegateway_smb_file_share.html.markdown index 4fdb45ddab8..9594ba33569 100644 --- a/website/docs/r/storagegateway_smb_file_share.html.markdown +++ b/website/docs/r/storagegateway_smb_file_share.html.markdown @@ -49,6 +49,7 @@ The following arguments are supported: * `authentication` - (Optional) The authentication method that users use to access the file share. Defaults to `ActiveDirectory`. Valid values: `ActiveDirectory`, `GuestAccess`. * `audit_destination_arn` - (Optional) The Amazon Resource Name (ARN) of the CloudWatch Log Group used for the audit logs. * `default_storage_class` - (Optional) The default storage class for objects put into an Amazon S3 bucket by the file gateway. Defaults to `S3_STANDARD`. Valid values: `S3_STANDARD`, `S3_STANDARD_IA`, `S3_ONEZONE_IA`. +* `file_share_name` - (Optional) The name of the file share. Must be set if an S3 prefix name is set in `location_arn`. * `guess_mime_type_enabled` - (Optional) Boolean value that enables guessing of the MIME type for uploaded objects based on file extensions. Defaults to `true`. * `invalid_user_list` - (Optional) A list of users in the Active Directory that are not allowed to access the file share. Only valid if `authentication` is set to `ActiveDirectory`. * `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`.