Skip to content

Commit 9b92541

Browse files
authored
resource/aws_storagegateway_gateway: Add support for bandwidth values (#13568)
Output from acceptance testing: ``` --- PASS: TestAccAWSStorageGatewayGateway_disappears (182.38s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Stored (206.84s) --- PASS: TestAccAWSStorageGatewayGateway_SmbGuestPassword (210.94s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayType_FileS3 (227.23s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayName (233.03s) --- PASS: TestAccAWSStorageGatewayGateway_CloudWatchLogs (238.19s) --- PASS: TestAccAWSStorageGatewayGateway_tags (244.80s) --- PASS: TestAccAWSStorageGatewayGateway_bandwidthUpload (244.86s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Vtl (248.04s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayType_Cached (248.57s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayTimezone (262.73s) --- PASS: TestAccAWSStorageGatewayGateway_SMBSecurityStrategy (262.76s) --- PASS: TestAccAWSStorageGatewayGateway_bandwidthDownload (281.07s) --- PASS: TestAccAWSStorageGatewayGateway_GatewayVpcEndpoint (297.35s) --- PASS: TestAccAWSStorageGatewayGateway_bandwidthAll (300.14s) --- PASS: TestAccAWSStorageGatewayGateway_SmbActiveDirectorySettings (744.76s) ```
1 parent ef00ed6 commit 9b92541

3 files changed

Lines changed: 259 additions & 0 deletions

File tree

aws/resource_aws_storagegateway_gateway.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ func resourceAwsStorageGatewayGateway() *schema.Resource {
146146
Computed: true,
147147
ValidateFunc: validation.StringInSlice(storagegateway.SMBSecurityStrategy_Values(), false),
148148
},
149+
"average_download_rate_limit_in_bits_per_sec": {
150+
Type: schema.TypeInt,
151+
Optional: true,
152+
ValidateFunc: validation.IntAtLeast(102400),
153+
},
154+
"average_upload_rate_limit_in_bits_per_sec": {
155+
Type: schema.TypeInt,
156+
Optional: true,
157+
ValidateFunc: validation.IntAtLeast(51200),
158+
},
149159
},
150160
}
151161
}
@@ -314,6 +324,26 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa
314324
}
315325
}
316326

327+
bandwidthInput := &storagegateway.UpdateBandwidthRateLimitInput{
328+
GatewayARN: aws.String(d.Id()),
329+
}
330+
331+
if v, ok := d.GetOk("average_download_rate_limit_in_bits_per_sec"); ok {
332+
bandwidthInput.AverageDownloadRateLimitInBitsPerSec = aws.Int64(int64(v.(int)))
333+
}
334+
335+
if v, ok := d.GetOk("average_upload_rate_limit_in_bits_per_sec"); ok {
336+
bandwidthInput.AverageUploadRateLimitInBitsPerSec = aws.Int64(int64(v.(int)))
337+
}
338+
339+
if bandwidthInput.AverageDownloadRateLimitInBitsPerSec != nil || bandwidthInput.AverageUploadRateLimitInBitsPerSec != nil {
340+
log.Printf("[DEBUG] Storage Gateway Gateway %q setting Bandwidth Rate Limit: %#v", d.Id(), bandwidthInput)
341+
_, err := conn.UpdateBandwidthRateLimit(bandwidthInput)
342+
if err != nil {
343+
return fmt.Errorf("error setting Bandwidth Rate Limit: %s", err)
344+
}
345+
}
346+
317347
return resourceAwsStorageGatewayGatewayRead(d, meta)
318348
}
319349

@@ -420,6 +450,20 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface
420450
d.Set("cloudwatch_log_group_arn", output.CloudWatchLogGroupARN)
421451
d.Set("smb_security_strategy", smbSettingsOutput.SMBSecurityStrategy)
422452

453+
bandwidthInput := &storagegateway.DescribeBandwidthRateLimitInput{
454+
GatewayARN: aws.String(d.Id()),
455+
}
456+
457+
log.Printf("[DEBUG] Reading Storage Gateway Bandwidth rate limit: %s", bandwidthInput)
458+
bandwidthOutput, err := conn.DescribeBandwidthRateLimit(bandwidthInput)
459+
if err != nil && !isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") {
460+
return fmt.Errorf("error reading Storage Gateway Bandwidth rate limit: %s", err)
461+
}
462+
if err == nil {
463+
d.Set("average_download_rate_limit_in_bits_per_sec", aws.Int64Value(bandwidthOutput.AverageDownloadRateLimitInBitsPerSec))
464+
d.Set("average_upload_rate_limit_in_bits_per_sec", aws.Int64Value(bandwidthOutput.AverageUploadRateLimitInBitsPerSec))
465+
}
466+
423467
return nil
424468
}
425469

@@ -492,6 +536,56 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa
492536
}
493537
}
494538

539+
if d.HasChanges("average_download_rate_limit_in_bits_per_sec",
540+
"average_upload_rate_limit_in_bits_per_sec") {
541+
542+
deleteInput := &storagegateway.DeleteBandwidthRateLimitInput{
543+
GatewayARN: aws.String(d.Id()),
544+
}
545+
updateInput := &storagegateway.UpdateBandwidthRateLimitInput{
546+
GatewayARN: aws.String(d.Id()),
547+
}
548+
needsDelete := false
549+
needsUpdate := false
550+
551+
if v, ok := d.GetOk("average_download_rate_limit_in_bits_per_sec"); ok {
552+
updateInput.AverageDownloadRateLimitInBitsPerSec = aws.Int64(int64(v.(int)))
553+
needsUpdate = true
554+
} else if d.HasChange("average_download_rate_limit_in_bits_per_sec") {
555+
deleteInput.BandwidthType = aws.String("DOWNLOAD")
556+
needsDelete = true
557+
}
558+
559+
if v, ok := d.GetOk("average_upload_rate_limit_in_bits_per_sec"); ok {
560+
updateInput.AverageUploadRateLimitInBitsPerSec = aws.Int64(int64(v.(int)))
561+
needsUpdate = true
562+
} else if d.HasChange("average_upload_rate_limit_in_bits_per_sec") {
563+
if needsDelete {
564+
deleteInput.BandwidthType = aws.String("ALL")
565+
} else {
566+
deleteInput.BandwidthType = aws.String("UPLOAD")
567+
needsDelete = true
568+
}
569+
}
570+
571+
if needsUpdate {
572+
log.Printf("[DEBUG] Storage Gateway Gateway (%q) updating Bandwidth Rate Limit: %#v", d.Id(), updateInput)
573+
_, err := conn.UpdateBandwidthRateLimit(updateInput)
574+
if err != nil {
575+
return fmt.Errorf("error updating Bandwidth Rate Limit: %w", err)
576+
}
577+
}
578+
579+
if needsDelete {
580+
log.Printf("[DEBUG] Storage Gateway Gateway (%q) unsetting Bandwidth Rate Limit: %#v", d.Id(), deleteInput)
581+
_, err := conn.DeleteBandwidthRateLimit(deleteInput)
582+
if err != nil {
583+
return fmt.Errorf("error unsetting Bandwidth Rate Limit: %w", err)
584+
}
585+
}
586+
587+
}
588+
495589
return resourceAwsStorageGatewayGatewayRead(d, meta)
496590
}
497591

aws/resource_aws_storagegateway_gateway_test.go

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,132 @@ func TestAccAWSStorageGatewayGateway_disappears(t *testing.T) {
492492
})
493493
}
494494

495+
func TestAccAWSStorageGatewayGateway_bandwidthUpload(t *testing.T) {
496+
var gateway storagegateway.DescribeGatewayInformationOutput
497+
rName := acctest.RandomWithPrefix("tf-acc-test")
498+
resourceName := "aws_storagegateway_gateway.test"
499+
500+
resource.ParallelTest(t, resource.TestCase{
501+
PreCheck: func() { testAccPreCheck(t) },
502+
Providers: testAccProviders,
503+
CheckDestroy: testAccCheckAWSStorageGatewayGatewayDestroy,
504+
Steps: []resource.TestStep{
505+
{
506+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigUpload(rName, 102400),
507+
Check: resource.ComposeTestCheckFunc(
508+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
509+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "102400"),
510+
),
511+
},
512+
{
513+
ResourceName: resourceName,
514+
ImportState: true,
515+
ImportStateVerify: true,
516+
ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"},
517+
},
518+
{
519+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigUpload(rName, 2*102400),
520+
Check: resource.ComposeTestCheckFunc(
521+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
522+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "204800"),
523+
),
524+
},
525+
{
526+
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Cached(rName),
527+
Check: resource.ComposeTestCheckFunc(
528+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
529+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "0"),
530+
),
531+
},
532+
},
533+
})
534+
}
535+
536+
func TestAccAWSStorageGatewayGateway_bandwidthDownload(t *testing.T) {
537+
var gateway storagegateway.DescribeGatewayInformationOutput
538+
rName := acctest.RandomWithPrefix("tf-acc-test")
539+
resourceName := "aws_storagegateway_gateway.test"
540+
541+
resource.ParallelTest(t, resource.TestCase{
542+
PreCheck: func() { testAccPreCheck(t) },
543+
Providers: testAccProviders,
544+
CheckDestroy: testAccCheckAWSStorageGatewayGatewayDestroy,
545+
Steps: []resource.TestStep{
546+
{
547+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigDownload(rName, 102400),
548+
Check: resource.ComposeTestCheckFunc(
549+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
550+
resource.TestCheckResourceAttr(resourceName, "average_download_rate_limit_in_bits_per_sec", "102400"),
551+
),
552+
},
553+
{
554+
ResourceName: resourceName,
555+
ImportState: true,
556+
ImportStateVerify: true,
557+
ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"},
558+
},
559+
{
560+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigDownload(rName, 2*102400),
561+
Check: resource.ComposeTestCheckFunc(
562+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
563+
resource.TestCheckResourceAttr(resourceName, "average_download_rate_limit_in_bits_per_sec", "204800"),
564+
),
565+
},
566+
{
567+
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Cached(rName),
568+
Check: resource.ComposeTestCheckFunc(
569+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
570+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "0"),
571+
),
572+
},
573+
},
574+
})
575+
}
576+
577+
func TestAccAWSStorageGatewayGateway_bandwidthAll(t *testing.T) {
578+
var gateway storagegateway.DescribeGatewayInformationOutput
579+
rName := acctest.RandomWithPrefix("tf-acc-test")
580+
resourceName := "aws_storagegateway_gateway.test"
581+
582+
resource.ParallelTest(t, resource.TestCase{
583+
PreCheck: func() { testAccPreCheck(t) },
584+
Providers: testAccProviders,
585+
CheckDestroy: testAccCheckAWSStorageGatewayGatewayDestroy,
586+
Steps: []resource.TestStep{
587+
{
588+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigAll(rName, 102400),
589+
Check: resource.ComposeTestCheckFunc(
590+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
591+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "102400"),
592+
resource.TestCheckResourceAttr(resourceName, "average_download_rate_limit_in_bits_per_sec", "102400"),
593+
),
594+
},
595+
{
596+
ResourceName: resourceName,
597+
ImportState: true,
598+
ImportStateVerify: true,
599+
ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"},
600+
},
601+
{
602+
Config: testAccAWSStorageGatewayGatewayBandwidthConfigAll(rName, 2*102400),
603+
Check: resource.ComposeTestCheckFunc(
604+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
605+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "204800"),
606+
resource.TestCheckResourceAttr(resourceName, "average_download_rate_limit_in_bits_per_sec", "204800"),
607+
),
608+
},
609+
{
610+
Config: testAccAWSStorageGatewayGatewayConfig_GatewayType_Cached(rName),
611+
Check: resource.ComposeTestCheckFunc(
612+
testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway),
613+
resource.TestCheckResourceAttr(resourceName, "average_upload_rate_limit_in_bits_per_sec", "0"),
614+
resource.TestCheckResourceAttr(resourceName, "average_download_rate_limit_in_bits_per_sec", "0"),
615+
),
616+
},
617+
},
618+
})
619+
}
620+
495621
func testAccCheckAWSStorageGatewayGatewayDestroy(s *terraform.State) error {
496622
conn := testAccProvider.Meta().(*AWSClient).storagegatewayconn
497623

@@ -943,3 +1069,40 @@ resource "aws_storagegateway_gateway" "test" {
9431069
}
9441070
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
9451071
}
1072+
1073+
func testAccAWSStorageGatewayGatewayBandwidthConfigUpload(rName string, rate int) string {
1074+
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
1075+
resource "aws_storagegateway_gateway" "test" {
1076+
gateway_ip_address = aws_instance.test.public_ip
1077+
gateway_name = %[1]q
1078+
gateway_timezone = "GMT"
1079+
gateway_type = "CACHED"
1080+
average_upload_rate_limit_in_bits_per_sec = %[2]d
1081+
}
1082+
`, rName, rate)
1083+
}
1084+
1085+
func testAccAWSStorageGatewayGatewayBandwidthConfigDownload(rName string, rate int) string {
1086+
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
1087+
resource "aws_storagegateway_gateway" "test" {
1088+
gateway_ip_address = aws_instance.test.public_ip
1089+
gateway_name = %[1]q
1090+
gateway_timezone = "GMT"
1091+
gateway_type = "CACHED"
1092+
average_download_rate_limit_in_bits_per_sec = %[2]d
1093+
}
1094+
`, rName, rate)
1095+
}
1096+
1097+
func testAccAWSStorageGatewayGatewayBandwidthConfigAll(rName string, rate int) string {
1098+
return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(`
1099+
resource "aws_storagegateway_gateway" "test" {
1100+
gateway_ip_address = aws_instance.test.public_ip
1101+
gateway_name = %[1]q
1102+
gateway_timezone = "GMT"
1103+
gateway_type = "CACHED"
1104+
average_upload_rate_limit_in_bits_per_sec = %[2]d
1105+
average_download_rate_limit_in_bits_per_sec = %[2]d
1106+
}
1107+
`, rName, rate)
1108+
}

website/docs/r/storagegateway_gateway.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ The following arguments are supported:
6969
* `gateway_name` - (Required) Name of the gateway.
7070
* `gateway_timezone` - (Required) Time zone for the gateway. The time zone is of the format "GMT", "GMT-hr:mm", or "GMT+hr:mm". For example, `GMT-4:00` indicates the time is 4 hours behind GMT. The time zone is used, for example, for scheduling snapshots and your gateway's maintenance schedule.
7171
* `activation_key` - (Optional) Gateway activation key during resource creation. Conflicts with `gateway_ip_address`. Additional information is available in the [Storage Gateway User Guide](https://docs.aws.amazon.com/storagegateway/latest/userguide/get-activation-key.html).
72+
* `average_download_rate_limit_in_bits_per_sec` - (Optional) The average download bandwidth rate limit in bits per second. This is supported for the `CACHED`, `STORED`, and `VTL` gateway types.
73+
* `average_upload_rate_limit_in_bits_per_sec` - (Optional) The average upload bandwidth rate limit in bits per second. This is supported for the `CACHED`, `STORED`, and `VTL` gateway types.
7274
* `gateway_ip_address` - (Optional) Gateway IP address to retrieve activation key during resource creation. Conflicts with `activation_key`. Gateway must be accessible on port 80 from where Terraform is running. Additional information is available in the [Storage Gateway User Guide](https://docs.aws.amazon.com/storagegateway/latest/userguide/get-activation-key.html).
7375
* `gateway_type` - (Optional) Type of the gateway. The default value is `STORED`. Valid values: `CACHED`, `FILE_S3`, `STORED`, `VTL`.
7476
* `gateway_vpc_endpoint` - (Optional) VPC endpoint address to be used when activating your gateway. This should be used when your instance is in a private subnet. Requires HTTP access from client computer running terraform. More info on what ports are required by your VPC Endpoint Security group in [Activating a Gateway in a Virtual Private Cloud](https://docs.aws.amazon.com/storagegateway/latest/userguide/gateway-private-link.html).

0 commit comments

Comments
 (0)