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_gateway - smb file share visibility #18076

Merged
merged 4 commits into from
Mar 17, 2021
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
3 changes: 3 additions & 0 deletions .changelog/18076.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_storagegateway_gateway: Add support for `smb_file_share_visibility`.
```
31 changes: 31 additions & 0 deletions aws/resource_aws_storagegateway_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func resourceAwsStorageGatewayGateway() *schema.Resource {
Computed: true,
ValidateFunc: validation.StringInSlice(storagegateway.SMBSecurityStrategy_Values(), false),
},
"smb_file_share_visibility": {
Type: schema.TypeBool,
Optional: true,
},
"average_download_rate_limit_in_bits_per_sec": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -391,6 +395,19 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa
}
}

if v, ok := d.GetOk("smb_file_share_visibility"); ok {
input := &storagegateway.UpdateSMBFileShareVisibilityInput{
GatewayARN: aws.String(d.Id()),
FileSharesVisible: aws.Bool(v.(bool)),
}

log.Printf("[DEBUG] Storage Gateway Gateway %q setting SMB File Share Visibility", input)
_, err := conn.UpdateSMBFileShareVisibility(input)
if err != nil {
return fmt.Errorf("error updating Storage Gateway Gateway (%s) SMB file share visibility: %w", d.Id(), err)
}
}

bandwidthInput := &storagegateway.UpdateBandwidthRateLimitInput{
GatewayARN: aws.String(d.Id()),
}
Expand Down Expand Up @@ -526,6 +543,7 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface
d.Set("tape_drive_type", d.Get("tape_drive_type").(string))
d.Set("cloudwatch_log_group_arn", output.CloudWatchLogGroupARN)
d.Set("smb_security_strategy", smbSettingsOutput.SMBSecurityStrategy)
d.Set("smb_file_share_visibility", smbSettingsOutput.FileSharesVisible)
d.Set("ec2_instance_id", output.Ec2InstanceId)
d.Set("endpoint_type", output.EndpointType)
d.Set("host_environment", output.HostEnvironment)
Expand Down Expand Up @@ -615,6 +633,19 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa
}
}

if d.HasChange("smb_file_share_visibility") {
input := &storagegateway.UpdateSMBFileShareVisibilityInput{
GatewayARN: aws.String(d.Id()),
FileSharesVisible: aws.Bool(d.Get("smb_file_share_visibility").(bool)),
}

log.Printf("[DEBUG] Storage Gateway Gateway %q updating SMB File Share Visibility", input)
_, err := conn.UpdateSMBFileShareVisibility(input)
if err != nil {
return fmt.Errorf("error updating Storage Gateway Gateway (%s) SMB file share visibility: %w", d.Id(), err)
}
}

if d.HasChanges("average_download_rate_limit_in_bits_per_sec",
"average_upload_rate_limit_in_bits_per_sec") {

Expand Down
54 changes: 54 additions & 0 deletions aws/resource_aws_storagegateway_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func TestAccAWSStorageGatewayGateway_SMBSecurityStrategy(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "smb_security_strategy", "ClientSpecified"),
resource.TestCheckResourceAttr(resourceName, "smb_file_share_visibility", "false"),
),
},
{
Expand All @@ -519,6 +520,47 @@ func TestAccAWSStorageGatewayGateway_SMBSecurityStrategy(t *testing.T) {
})
}

func TestAccAWSStorageGatewayGateway_SMBVisibility(t *testing.T) {
var gateway storagegateway.DescribeGatewayInformationOutput
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_storagegateway_gateway.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSStorageGatewayGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSStorageGatewayGatewayConfigSMBVisibility(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "smb_file_share_visibility", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"},
},
{
Config: testAccAWSStorageGatewayGatewayConfigSMBVisibility(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "smb_file_share_visibility", "false"),
),
},
{
Config: testAccAWSStorageGatewayGatewayConfigSMBVisibility(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "smb_file_share_visibility", "true"),
),
},
},
})
}

func TestAccAWSStorageGatewayGateway_disappears(t *testing.T) {
var gateway storagegateway.DescribeGatewayInformationOutput
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -1108,6 +1150,18 @@ resource "aws_storagegateway_gateway" "test" {
`, rName, strategy)
}

func testAccAWSStorageGatewayGatewayConfigSMBVisibility(rName string, visible bool) string {
return testAccAWSStorageGateway_FileGatewayBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_gateway" "test" {
gateway_ip_address = aws_instance.test.public_ip
gateway_name = %[1]q
gateway_timezone = "GMT"
gateway_type = "FILE_S3"
smb_file_share_visibility = %[2]t
}
`, rName, visible)
}

func testAccAWSStorageGatewayGatewayConfigTags1(rName, tagKey1, tagValue1 string) string {
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_gateway" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/storagegateway_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The following arguments are supported:
* `smb_active_directory_settings` - (Optional) Nested argument with Active Directory domain join information for Server Message Block (SMB) file shares. Only valid for `FILE_S3` gateway type. Must be set before creating `ActiveDirectory` authentication SMB file shares. More details below.
* `smb_guest_password` - (Optional) Guest password for Server Message Block (SMB) file shares. Only valid for `FILE_S3` gateway type. Must be set before creating `GuestAccess` authentication SMB file shares. Terraform can only detect drift of the existence of a guest password, not its actual value from the gateway. Terraform can however update the password with changing the argument.
* `smb_security_strategy` - (Optional) Specifies the type of security strategy. Valid values are: `ClientSpecified`, `MandatorySigning`, and `MandatoryEncryption`. See [Setting a Security Level for Your Gateway](https://docs.aws.amazon.com/storagegateway/latest/userguide/managing-gateway-file.html#security-strategy) for more information.
* `smb_file_share_visibility` - (Optional) Specifies whether the shares on this gateway appear when listing shares.
* `tape_drive_type` - (Optional) Type of tape drive to use for tape gateway. Terraform cannot detect drift of this argument. Valid values: `IBM-ULT3580-TD5`.
* `tags` - (Optional) Key-value map of resource tags

Expand Down