Skip to content

Commit

Permalink
Add Tag Support to Storage Gateway Gateway Resource (#10588)
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Stored (188.56s)
--- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Cached (188.70s)
--- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Vtl (191.77s)
--- PASS: TestAccAWSStorageGatewayGateway_tags (206.41s)
--- PASS: TestAccAWSStorageGatewayGateway_SmbGuestPassword (260.26s)
--- PASS: TestAccAWSStorageGatewayGateway_GatewayType_FileS3 (260.47s)
--- PASS: TestAccAWSStorageGatewayGateway_GatewayTimezone (268.70s)
--- PASS: TestAccAWSStorageGatewayGateway_GatewayName (271.56s)
--- PASS: TestAccAWSStorageGatewayGateway_SmbActiveDirectorySettings (712.86s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Nov 2, 2019
1 parent 823d8fa commit 9944b75
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
14 changes: 14 additions & 0 deletions aws/resource_aws_storagegateway_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsStorageGatewayGateway() *schema.Resource {
Expand Down Expand Up @@ -122,6 +123,7 @@ func resourceAwsStorageGatewayGateway() *schema.Resource {
"IBM-ULT3580-TD5",
}, false),
},
"tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -196,6 +198,7 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa
GatewayName: aws.String(d.Get("gateway_name").(string)),
GatewayTimezone: aws.String(d.Get("gateway_timezone").(string)),
GatewayType: aws.String(d.Get("gateway_type").(string)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().StoragegatewayTags(),
}

if v, ok := d.GetOk("medium_changer_type"); ok {
Expand Down Expand Up @@ -290,6 +293,10 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface
return fmt.Errorf("error reading Storage Gateway Gateway: %s", err)
}

if err := d.Set("tags", keyvaluetags.StoragegatewayKeyValueTags(output.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

smbSettingsInput := &storagegateway.DescribeSMBSettingsInput{
GatewayARN: aws.String(d.Id()),
}
Expand Down Expand Up @@ -385,6 +392,13 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa
}
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if err := keyvaluetags.StoragegatewayUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
}
}

if d.HasChange("smb_active_directory_settings") {
l := d.Get("smb_active_directory_settings").([]interface{})
m := l[0].(map[string]interface{})
Expand Down
85 changes: 81 additions & 4 deletions aws/resource_aws_storagegateway_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAccAWSStorageGatewayGateway_GatewayType_Cached(t *testing.T) {
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Cached(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:storagegateway:[^:]+:[^:]+:gateway/sgw-.+$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)),
resource.TestCheckResourceAttrSet(resourceName, "gateway_id"),
resource.TestCheckResourceAttr(resourceName, "gateway_name", rName),
resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"),
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestAccAWSStorageGatewayGateway_GatewayType_FileS3(t *testing.T) {
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_FileS3(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:storagegateway:[^:]+:[^:]+:gateway/sgw-.+$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)),
resource.TestCheckResourceAttrSet(resourceName, "gateway_id"),
resource.TestCheckResourceAttr(resourceName, "gateway_name", rName),
resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"),
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestAccAWSStorageGatewayGateway_GatewayType_Stored(t *testing.T) {
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Stored(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:storagegateway:[^:]+:[^:]+:gateway/sgw-.+$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)),
resource.TestCheckResourceAttrSet(resourceName, "gateway_id"),
resource.TestCheckResourceAttr(resourceName, "gateway_name", rName),
resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"),
Expand Down Expand Up @@ -181,7 +181,7 @@ func TestAccAWSStorageGatewayGateway_GatewayType_Vtl(t *testing.T) {
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Vtl(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:storagegateway:[^:]+:[^:]+:gateway/sgw-.+$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)),
resource.TestCheckResourceAttrSet(resourceName, "gateway_id"),
resource.TestCheckResourceAttr(resourceName, "gateway_name", rName),
resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"),
Expand All @@ -202,6 +202,52 @@ func TestAccAWSStorageGatewayGateway_GatewayType_Vtl(t *testing.T) {
})
}

func TestAccAWSStorageGatewayGateway_tags(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: testAccAWSStorageGatewayGatewayConfigTags1(rName, "key1", "value1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"},
},
{
Config: testAccAWSStorageGatewayGatewayConfigTags2(rName, "key1", "value1updated", "key2", "value2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"),
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),
),
},
{
Config: testAccAWSStorageGatewayGatewayConfigTags1(rName, "key2", "value2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),
),
},
},
})
}

func TestAccAWSStorageGatewayGateway_GatewayName(t *testing.T) {
var gateway storagegateway.DescribeGatewayInformationOutput
rName1 := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -741,3 +787,34 @@ resource "aws_storagegateway_gateway" "test" {
}
`, rName, smbGuestPassword)
}

func testAccAWSStorageGatewayGatewayConfigTags1(rName, tagKey1, tagValue1 string) string {
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_gateway" "test" {
gateway_ip_address = "${aws_instance.test.public_ip}"
gateway_name = %q
gateway_timezone = "GMT"
gateway_type = "CACHED"
tags = {
%q = %q
}
}
`, rName, tagKey1, tagValue1)
}

func testAccAWSStorageGatewayGatewayConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
resource "aws_storagegateway_gateway" "test" {
gateway_ip_address = "${aws_instance.test.public_ip}"
gateway_name = %q
gateway_timezone = "GMT"
gateway_type = "CACHED"
tags = {
%q = %q
%q = %q
}
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
}
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 @@ -74,6 +74,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.
* `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 mapping of resource tags

### smb_active_directory_settings

Expand Down

0 comments on commit 9944b75

Please sign in to comment.