From cbc2b00cebfc5f58550160c3755334d936391192 Mon Sep 17 00:00:00 2001 From: Andrew Kulpa Date: Wed, 26 Feb 2020 19:33:30 -0600 Subject: [PATCH 1/3] add admin_user_list to SG GW SMB File Share --- aws/resource_aws_storagegateway_smb_file_share.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/aws/resource_aws_storagegateway_smb_file_share.go b/aws/resource_aws_storagegateway_smb_file_share.go index d4512b156fc..9347c8bff92 100644 --- a/aws/resource_aws_storagegateway_smb_file_share.go +++ b/aws/resource_aws_storagegateway_smb_file_share.go @@ -124,6 +124,11 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource { Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "admin_user_list": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "tags": tagsSchema(), }, } @@ -146,6 +151,7 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in RequesterPays: aws.Bool(d.Get("requester_pays").(bool)), Role: aws.String(d.Get("role_arn").(string)), ValidUserList: expandStringSet(d.Get("valid_user_list").(*schema.Set)), + AdminUserList: expandStringSet(d.Get("admin_user_list").(*schema.Set)), Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().StoragegatewayTags(), } @@ -228,6 +234,10 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte return fmt.Errorf("error setting valid_user_list: %s", err) } + if err := d.Set("admin_user_list", schema.NewSet(schema.HashString, flattenStringList(fileshare.AdminUserList))); err != nil { + return fmt.Errorf("error setting admin_user_list: %s", err) + } + tags, err := keyvaluetags.StoragegatewayListTags(conn, *arn) if err != nil { return fmt.Errorf("error listing tags for resource (%s): %s", *arn, err) @@ -259,6 +269,7 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in ReadOnly: aws.Bool(d.Get("read_only").(bool)), RequesterPays: aws.Bool(d.Get("requester_pays").(bool)), ValidUserList: expandStringSet(d.Get("valid_user_list").(*schema.Set)), + AdminUserList: expandStringSet(d.Get("admin_user_list").(*schema.Set)), } if v, ok := d.GetOk("kms_key_arn"); ok && v.(string) != "" { From be81ab19909975114227b4e111219972fd13cb96 Mon Sep 17 00:00:00 2001 From: Andrew Kulpa Date: Wed, 26 Feb 2020 19:33:50 -0600 Subject: [PATCH 2/3] add admin_user_list test for SG GW SMB File Share --- ..._aws_storagegateway_smb_file_share_test.go | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/aws/resource_aws_storagegateway_smb_file_share_test.go b/aws/resource_aws_storagegateway_smb_file_share_test.go index fcde2602673..65c08080a34 100644 --- a/aws/resource_aws_storagegateway_smb_file_share_test.go +++ b/aws/resource_aws_storagegateway_smb_file_share_test.go @@ -41,6 +41,7 @@ func TestAccAWSStorageGatewaySmbFileShare_Authentication_ActiveDirectory(t *test resource.TestCheckResourceAttr(resourceName, "requester_pays", "false"), resource.TestMatchResourceAttr(resourceName, "role_arn", regexp.MustCompile(`^arn:`)), resource.TestCheckResourceAttr(resourceName, "valid_user_list.#", "0"), + resource.TestCheckResourceAttr(resourceName, "admin_user_list.#", "0"), ), }, { @@ -81,6 +82,7 @@ func TestAccAWSStorageGatewaySmbFileShare_Authentication_GuestAccess(t *testing. resource.TestCheckResourceAttr(resourceName, "requester_pays", "false"), resource.TestMatchResourceAttr(resourceName, "role_arn", regexp.MustCompile(`^arn:`)), resource.TestCheckResourceAttr(resourceName, "valid_user_list.#", "0"), + resource.TestCheckResourceAttr(resourceName, "admin_user_list.#", "0"), ), }, { @@ -453,6 +455,46 @@ func TestAccAWSStorageGatewaySmbFileShare_ValidUserList(t *testing.T) { }) } +func TestAccAWSStorageGatewaySmbFileShare_AdminUserList(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_AdminUserList_Single(rName, "adminuser1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare), + resource.TestCheckResourceAttr(resourceName, "admin_user_list.#", "1"), + ), + }, + { + Config: testAccAWSStorageGatewaySmbFileShareConfig_AdminUserList_Multiple(rName, "adminuser2", "adminuser3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare), + resource.TestCheckResourceAttr(resourceName, "admin_user_list.#", "2"), + ), + }, + { + Config: testAccAWSStorageGatewaySmbFileShareConfig_AdminUserList_Single(rName, "adminuser4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewaySmbFileShareExists(resourceName, &smbFileShare), + resource.TestCheckResourceAttr(resourceName, "admin_user_list.#", "1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAWSStorageGatewaySmbFileShareDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).storagegatewayconn @@ -803,6 +845,32 @@ resource "aws_storagegateway_smb_file_share" "test" { `, validUser1, validUser2) } +func testAccAWSStorageGatewaySmbFileShareConfig_AdminUserList_Single(rName, adminUser1 string) string { + return testAccAWSStorageGateway_SmbFileShare_ActiveDirectoryBase(rName) + fmt.Sprintf(` +resource "aws_storagegateway_smb_file_share" "test" { + # Must be ActiveDirectory + authentication = "ActiveDirectory" + gateway_arn = "${aws_storagegateway_gateway.test.arn}" + location_arn = "${aws_s3_bucket.test.arn}" + role_arn = "${aws_iam_role.test.arn}" + admin_user_list = [%q] +} +`, adminUser1) +} + +func testAccAWSStorageGatewaySmbFileShareConfig_AdminUserList_Multiple(rName, adminUser1, adminUser2 string) string { + return testAccAWSStorageGateway_SmbFileShare_ActiveDirectoryBase(rName) + fmt.Sprintf(` +resource "aws_storagegateway_smb_file_share" "test" { + # Must be ActiveDirectory + authentication = "ActiveDirectory" + gateway_arn = "${aws_storagegateway_gateway.test.arn}" + location_arn = "${aws_s3_bucket.test.arn}" + role_arn = "${aws_iam_role.test.arn}" + admin_user_list = [%q, %q] +} +`, adminUser1, adminUser2) +} + func testAccAWSStorageGatewaySmbFileShareConfigTags1(rName, tagKey1, tagValue1 string) string { return testAccAWSStorageGateway_SmbFileShare_GuestAccessBase(rName) + fmt.Sprintf(` resource "aws_storagegateway_smb_file_share" "test" { From 54bc1ab3408972a837f318864d32f4f19aed4afd Mon Sep 17 00:00:00 2001 From: Andrew Kulpa Date: Wed, 26 Feb 2020 19:34:45 -0600 Subject: [PATCH 3/3] Add documentation for admin_user_list --- website/docs/r/storagegateway_smb_file_share.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/storagegateway_smb_file_share.html.markdown b/website/docs/r/storagegateway_smb_file_share.html.markdown index 7f3008ebef5..ab10f5ec214 100644 --- a/website/docs/r/storagegateway_smb_file_share.html.markdown +++ b/website/docs/r/storagegateway_smb_file_share.html.markdown @@ -56,6 +56,7 @@ The following arguments are supported: * `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`. * `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`. +* `admin_user_list` - (Optional) A list of users in the Active Directory that have admin access to the file share. Only valid if `authentication` is set to `ActiveDirectory`. * `tags` - (Optional) Key-value mapping of resource tags ### smb_file_share_defaults