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

resource/aws_storagegateway_smb_file_share: Add support for admin_user_list #12196

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions aws/resource_aws_storagegateway_smb_file_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
Expand All @@ -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(),
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) != "" {
Expand Down
68 changes: 68 additions & 0 deletions aws/resource_aws_storagegateway_smb_file_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/storagegateway_smb_file_share.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down