From 598099aa2bbe72ed1851e94fd664dfb140d10e68 Mon Sep 17 00:00:00 2001 From: Alexey Wasilyev Date: Fri, 25 Sep 2020 10:30:15 +0200 Subject: [PATCH 01/29] support for maintenance start time (15331) --- aws/resource_aws_storagegateway_gateway.go | 74 +++++++++++++++++++ ...esource_aws_storagegateway_gateway_test.go | 55 ++++++++++++++ 2 files changed, 129 insertions(+) diff --git a/aws/resource_aws_storagegateway_gateway.go b/aws/resource_aws_storagegateway_gateway.go index 54094ae29cb..b57856585a7 100644 --- a/aws/resource_aws_storagegateway_gateway.go +++ b/aws/resource_aws_storagegateway_gateway.go @@ -223,6 +223,28 @@ func resourceAwsStorageGatewayGateway() *schema.Resource { "ipv4_address": { Type: schema.TypeString, Computed: true, + "maintenance_start_time": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "hour": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 23), + }, + "minute": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 59), + Default: 0, + }, + "day_of_week": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 6), + Default: 0, }, }, }, @@ -378,6 +400,23 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa } } + if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 { + m := v.([]interface{})[0].(map[string]interface{}) + + input := &storagegateway.UpdateMaintenanceStartTimeInput{ + DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + GatewayARN: aws.String(d.Id()), + HourOfDay: aws.Int64(int64(m["hour"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + } + + log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) + _, err := conn.UpdateMaintenanceStartTime(input) + if err != nil { + return fmt.Errorf("error updating maintenance start time: %w", err) + } + } + if v, ok := d.GetOk("smb_security_strategy"); ok { input := &storagegateway.UpdateSMBSecurityStrategyInput{ GatewayARN: aws.String(d.Id()), @@ -534,6 +573,24 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface return fmt.Errorf("error setting gateway_network_interface: %w", err) } + maintenanceStartTimeInput := &storagegateway.DescribeMaintenanceStartTimeInput{ + GatewayARN: aws.String(d.Id()), + } + maintenanceStartTimeOutput, err := conn.DescribeMaintenanceStartTime(maintenanceStartTimeInput) + if err != nil && !isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") { + return fmt.Errorf("error reading Storage Gateway Maintenance time start: %s", err) + } + if err == nil { + m := map[string]interface{}{ + "hour": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), + "minute": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), + "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + } + if err := d.Set("maintenance_start_time", []map[string]interface{}{m}); err != nil { + return fmt.Errorf("error setting maintenance_start_time: %w", err) + } + } + bandwidthInput := &storagegateway.DescribeBandwidthRateLimitInput{ GatewayARN: aws.String(d.Id()), } @@ -662,7 +719,24 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa return fmt.Errorf("error unsetting Bandwidth Rate Limit: %w", err) } } + } + + if d.HasChange("maintenance_start_time") { + l := d.Get("maintenance_start_time").([]interface{}) + m := l[0].(map[string]interface{}) + + input := &storagegateway.UpdateMaintenanceStartTimeInput{ + DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + GatewayARN: aws.String(d.Id()), + HourOfDay: aws.Int64(int64(m["hour"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + } + log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) + _, err := conn.UpdateMaintenanceStartTime(input) + if err != nil { + return fmt.Errorf("error updating maintenance start time: %w", err) + } } return resourceAwsStorageGatewayGatewayRead(d, meta) diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 2cd33b782a5..20e87d65434 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -667,6 +667,45 @@ func TestAccAWSStorageGatewayGateway_bandwidthAll(t *testing.T) { }) } +func TestAccAWSStorageGatewayGateway_maintenanceStartTime(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: testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName, 22, 0, 3), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour", "22"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute", "0"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "3"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"}, + }, + { + Config: testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName, 21, 10, 0), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour", "21"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute", "10"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "0"), + ), + }, + }, + }) +} + func testAccCheckAWSStorageGatewayGatewayDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).storagegatewayconn @@ -1175,3 +1214,19 @@ resource "aws_storagegateway_gateway" "test" { } `, rName, rate) } + +func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour int, minute int, day_of_week int) string { + return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(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 = "CACHED" + maintenance_start_time { + hour = %[2]d + minute = %[3]d + day_of_week = %[4]d + } +} +`, rName, hour, minute, day_of_week) +} From c24907e91bf20bcc1f15f97f5685a7e0e4e81d1b Mon Sep 17 00:00:00 2001 From: Alexey Wasilyev Date: Fri, 26 Mar 2021 15:09:46 +0100 Subject: [PATCH 02/29] fix for support for maintenance start time (15331) --- aws/resource_aws_storagegateway_gateway.go | 36 ++++++++++++++----- ...esource_aws_storagegateway_gateway_test.go | 19 +++++----- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_storagegateway_gateway.go b/aws/resource_aws_storagegateway_gateway.go index b57856585a7..521e4ae8134 100644 --- a/aws/resource_aws_storagegateway_gateway.go +++ b/aws/resource_aws_storagegateway_gateway.go @@ -223,28 +223,43 @@ func resourceAwsStorageGatewayGateway() *schema.Resource { "ipv4_address": { Type: schema.TypeString, Computed: true, + }, + }, + }, + }, "maintenance_start_time": { Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "hour": { + "hour_of_day": { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntBetween(0, 23), + Default: 0, + Computed: true, }, - "minute": { + "minute_of_hour": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 59), Default: 0, + Computed: true, }, "day_of_week": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 6), Default: 0, + Computed: true, + }, + "day_of_month": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 28), + Default: 0, + Computed: true, }, }, }, @@ -405,9 +420,10 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute_of_hour"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) @@ -582,9 +598,10 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface } if err == nil { m := map[string]interface{}{ - "hour": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), - "minute": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), - "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + "hour_of_day": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), + "minute_of_hour": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), + "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + "day_of_month": aws.Int64Value(maintenanceStartTimeOutput.DayOfMonth), } if err := d.Set("maintenance_start_time", []map[string]interface{}{m}); err != nil { return fmt.Errorf("error setting maintenance_start_time: %w", err) @@ -727,9 +744,10 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), + DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), + HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute_of_month"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 20e87d65434..255ba0d1d76 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -1215,18 +1215,19 @@ resource "aws_storagegateway_gateway" "test" { `, rName, rate) } -func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour int, minute int, day_of_week int) string { +func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour_of_day int, minute_of_hour int, day_of_week int, day_of_month int) string { return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(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 = "CACHED" + gateway_ip_address = aws_instance.test.public_ip + gateway_name = %[1]q + gateway_timezone = "GMT" + gateway_type = "CACHED" maintenance_start_time { - hour = %[2]d - minute = %[3]d - day_of_week = %[4]d + hour_of_day = %[2]d + minute_of_hour = %[3]d + day_of_week = %[4]d + day_of_month = %[5]d } } -`, rName, hour, minute, day_of_week) +`, rName, hour_of_day, minute_of_hour, day_of_week, day_of_month) } From 48a4a55e53bc58d97c78887360ebd82d73b120c1 Mon Sep 17 00:00:00 2001 From: kliu47 <88392374+kliu47@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:03:24 -0500 Subject: [PATCH 03/29] Update nfs_file_share.go --- internal/service/storagegateway/nfs_file_share.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index 0fb7711a4ab..b21b49e7171 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -200,6 +200,11 @@ func ResourceNFSFileShare() *schema.Resource { }, "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), + "vpc_endpoint_dns_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, CustomizeDiff: verify.SetTagsDiff, @@ -248,6 +253,10 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("file_share_name"); ok { input.FileShareName = aws.String(v.(string)) } + + if v, ok := d.GetOk("vpc_endpoint_dns_name"); ok { + input.VPCEndpointDNSName = aws.String(v.(string)) + } if v, ok := d.GetOk("cache_attributes"); ok { input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) @@ -312,6 +321,7 @@ func resourceNFSFileShareRead(d *schema.ResourceData, meta interface{}) error { d.Set("kms_key_arn", fileshare.KMSKey) d.Set("location_arn", fileshare.LocationARN) d.Set("file_share_name", fileshare.FileShareName) + d.Set("vpc_endpoint_dns_name", fileshare.VPCEndpointDNSName) if err := d.Set("nfs_file_share_defaults", flattenStorageGatewayNfsFileShareDefaults(fileshare.NFSFileShareDefaults)); err != nil { return fmt.Errorf("error setting nfs_file_share_defaults: %w", err) From 55040ceb2b1962abbb51e78c004b5885845fbec3 Mon Sep 17 00:00:00 2001 From: kliu47 <88392374+kliu47@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:09:55 -0500 Subject: [PATCH 04/29] Update nfs_file_share.go --- internal/service/storagegateway/nfs_file_share.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index b21b49e7171..d8a0aa59173 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -45,6 +45,12 @@ func ResourceNFSFileShare() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "bucket_region": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + RequiredWith: []string{"vpc_endpoint_dns_name"}, + }, "client_list": { Type: schema.TypeSet, Required: true, @@ -241,6 +247,10 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("audit_destination_arn"); ok { input.AuditDestinationARN = aws.String(v.(string)) } + + if v, ok := d.GetOk("bucket_region"); ok { + input.BucketRegion = aws.String(v.(string)) + } if v, ok := d.GetOk("kms_key_arn"); ok { input.KMSKey = aws.String(v.(string)) @@ -313,6 +323,7 @@ func resourceNFSFileShareRead(d *schema.ResourceData, meta interface{}) error { } d.Set("audit_destination_arn", fileshare.AuditDestinationARN) + d.Set("bucket_region", fileshare.BucketRegion) d.Set("default_storage_class", fileshare.DefaultStorageClass) d.Set("fileshare_id", fileshare.FileShareId) d.Set("gateway_arn", fileshare.GatewayARN) From ef69a7ee2beecd22950cb0075edd8bba64ca3542 Mon Sep 17 00:00:00 2001 From: kliu47 <88392374+kliu47@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:22:06 -0500 Subject: [PATCH 05/29] Create 24038.txt --- .changelog/24038.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/24038.txt diff --git a/.changelog/24038.txt b/.changelog/24038.txt new file mode 100644 index 00000000000..47e318bec93 --- /dev/null +++ b/.changelog/24038.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/nfs_file_share: Add `bucket_region` and `vpc_endpoint_dns_name` attributes to support privatelink endpoints +``` From a5a72128c2eabf2976a1bc86b6d9cf4127c51df7 Mon Sep 17 00:00:00 2001 From: kliu47 <88392374+kliu47@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:46:10 -0500 Subject: [PATCH 06/29] Update storagegateway_nfs_file_share.html.markdown --- website/docs/r/storagegateway_nfs_file_share.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/storagegateway_nfs_file_share.html.markdown b/website/docs/r/storagegateway_nfs_file_share.html.markdown index 5e9cb2d474f..3252f32c522 100644 --- a/website/docs/r/storagegateway_nfs_file_share.html.markdown +++ b/website/docs/r/storagegateway_nfs_file_share.html.markdown @@ -28,6 +28,8 @@ The following arguments are supported: * `client_list` - (Required) The list of clients that are allowed to access the file gateway. The list must contain either valid IP addresses or valid CIDR blocks. Set to `["0.0.0.0/0"]` to not limit access. Minimum 1 item. Maximum 100 items. * `gateway_arn` - (Required) Amazon Resource Name (ARN) of the file gateway. * `location_arn` - (Required) The ARN of the backed storage used for storing file data. +* `vpc_endpoint_dns_name` - (Optional) The DNS name of the VPC endpoint for S3 private link. +* `bucket_regio`n - (Optional) The region of the S3 bucket used by the file share. Required when specifying a vpc_endpoint_dns_name. * `role_arn` - (Required) The ARN of the AWS Identity and Access Management (IAM) role that a file gateway assumes when it accesses the underlying storage. * `audit_destination_arn` - (Optional) The Amazon Resource Name (ARN) of the storage used for audit logs. * `default_storage_class` - (Optional) The default [storage class](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_CreateNFSFileShare.html#StorageGateway-CreateNFSFileShare-request-DefaultStorageClass) for objects put into an Amazon S3 bucket by the file gateway. Defaults to `S3_STANDARD`. From b59c3fcbdd7e087288b52234675965c8c44dbb05 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:03:04 -0400 Subject: [PATCH 07/29] Update 24038.txt --- .changelog/24038.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/24038.txt b/.changelog/24038.txt index 47e318bec93..0a3e6218a7c 100644 --- a/.changelog/24038.txt +++ b/.changelog/24038.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/nfs_file_share: Add `bucket_region` and `vpc_endpoint_dns_name` attributes to support privatelink endpoints +resource/aws_storagegateway_nfs_file_share: Add `bucket_region` and `vpc_endpoint_dns_name` arguments to support PrivateLink endpoints ``` From 71aae4557f5a4736c347480341abb44cb87814bb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:04:35 -0400 Subject: [PATCH 08/29] Update storagegateway_nfs_file_share.html.markdown --- website/docs/r/storagegateway_nfs_file_share.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/storagegateway_nfs_file_share.html.markdown b/website/docs/r/storagegateway_nfs_file_share.html.markdown index 3252f32c522..5e075f08da3 100644 --- a/website/docs/r/storagegateway_nfs_file_share.html.markdown +++ b/website/docs/r/storagegateway_nfs_file_share.html.markdown @@ -28,8 +28,8 @@ The following arguments are supported: * `client_list` - (Required) The list of clients that are allowed to access the file gateway. The list must contain either valid IP addresses or valid CIDR blocks. Set to `["0.0.0.0/0"]` to not limit access. Minimum 1 item. Maximum 100 items. * `gateway_arn` - (Required) Amazon Resource Name (ARN) of the file gateway. * `location_arn` - (Required) The ARN of the backed storage used for storing file data. -* `vpc_endpoint_dns_name` - (Optional) The DNS name of the VPC endpoint for S3 private link. -* `bucket_regio`n - (Optional) The region of the S3 bucket used by the file share. Required when specifying a vpc_endpoint_dns_name. +* `vpc_endpoint_dns_name` - (Optional) The DNS name of the VPC endpoint for S3 PrivateLink. +* `bucket_region` - (Optional) The region of the S3 bucket used by the file share. Required when specifying `vpc_endpoint_dns_name`. * `role_arn` - (Required) The ARN of the AWS Identity and Access Management (IAM) role that a file gateway assumes when it accesses the underlying storage. * `audit_destination_arn` - (Optional) The Amazon Resource Name (ARN) of the storage used for audit logs. * `default_storage_class` - (Optional) The default [storage class](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_CreateNFSFileShare.html#StorageGateway-CreateNFSFileShare-request-DefaultStorageClass) for objects put into an Amazon S3 bucket by the file gateway. Defaults to `S3_STANDARD`. From 5a9cd1028d2079b252a17fdfd0189cb8cb0ea843 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:11:40 -0400 Subject: [PATCH 09/29] Revert "fix for support for maintenance start time (15331)" This reverts commit c24907e91bf20bcc1f15f97f5685a7e0e4e81d1b. --- aws/resource_aws_storagegateway_gateway.go | 36 +++++-------------- ...esource_aws_storagegateway_gateway_test.go | 19 +++++----- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/aws/resource_aws_storagegateway_gateway.go b/aws/resource_aws_storagegateway_gateway.go index 521e4ae8134..b57856585a7 100644 --- a/aws/resource_aws_storagegateway_gateway.go +++ b/aws/resource_aws_storagegateway_gateway.go @@ -223,43 +223,28 @@ func resourceAwsStorageGatewayGateway() *schema.Resource { "ipv4_address": { Type: schema.TypeString, Computed: true, - }, - }, - }, - }, "maintenance_start_time": { Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "hour_of_day": { + "hour": { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntBetween(0, 23), - Default: 0, - Computed: true, }, - "minute_of_hour": { + "minute": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 59), Default: 0, - Computed: true, }, "day_of_week": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 6), Default: 0, - Computed: true, - }, - "day_of_month": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 28), - Default: 0, - Computed: true, }, }, }, @@ -420,10 +405,9 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), - DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute_of_hour"].(int))), + HourOfDay: aws.Int64(int64(m["hour"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) @@ -598,10 +582,9 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface } if err == nil { m := map[string]interface{}{ - "hour_of_day": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), - "minute_of_hour": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), - "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), - "day_of_month": aws.Int64Value(maintenanceStartTimeOutput.DayOfMonth), + "hour": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), + "minute": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), + "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), } if err := d.Set("maintenance_start_time", []map[string]interface{}{m}); err != nil { return fmt.Errorf("error setting maintenance_start_time: %w", err) @@ -744,10 +727,9 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa input := &storagegateway.UpdateMaintenanceStartTimeInput{ DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), - DayOfMonth: aws.Int64(int64(m["day_of_month"].(int))), GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour_of_day"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute_of_month"].(int))), + HourOfDay: aws.Int64(int64(m["hour"].(int))), + MinuteOfHour: aws.Int64(int64(m["minute"].(int))), } log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 255ba0d1d76..20e87d65434 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -1215,19 +1215,18 @@ resource "aws_storagegateway_gateway" "test" { `, rName, rate) } -func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour_of_day int, minute_of_hour int, day_of_week int, day_of_month int) string { +func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour int, minute int, day_of_week int) string { return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(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 = "CACHED" + gateway_ip_address = aws_instance.test.public_ip + gateway_name = %[1]q + gateway_timezone = "GMT" + gateway_type = "CACHED" maintenance_start_time { - hour_of_day = %[2]d - minute_of_hour = %[3]d - day_of_week = %[4]d - day_of_month = %[5]d + hour = %[2]d + minute = %[3]d + day_of_week = %[4]d } } -`, rName, hour_of_day, minute_of_hour, day_of_week, day_of_month) +`, rName, hour, minute, day_of_week) } From c465474c0fcddcd2a32dbc83bd0a5c259ccd4dd2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:11:51 -0400 Subject: [PATCH 10/29] Revert "support for maintenance start time (15331)" This reverts commit 598099aa2bbe72ed1851e94fd664dfb140d10e68. --- aws/resource_aws_storagegateway_gateway.go | 74 ------------------- ...esource_aws_storagegateway_gateway_test.go | 55 -------------- 2 files changed, 129 deletions(-) diff --git a/aws/resource_aws_storagegateway_gateway.go b/aws/resource_aws_storagegateway_gateway.go index b57856585a7..54094ae29cb 100644 --- a/aws/resource_aws_storagegateway_gateway.go +++ b/aws/resource_aws_storagegateway_gateway.go @@ -223,28 +223,6 @@ func resourceAwsStorageGatewayGateway() *schema.Resource { "ipv4_address": { Type: schema.TypeString, Computed: true, - "maintenance_start_time": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "hour": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(0, 23), - }, - "minute": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(0, 59), - Default: 0, - }, - "day_of_week": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(0, 6), - Default: 0, }, }, }, @@ -400,23 +378,6 @@ func resourceAwsStorageGatewayGatewayCreate(d *schema.ResourceData, meta interfa } } - if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 { - m := v.([]interface{})[0].(map[string]interface{}) - - input := &storagegateway.UpdateMaintenanceStartTimeInput{ - DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), - GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), - } - - log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) - _, err := conn.UpdateMaintenanceStartTime(input) - if err != nil { - return fmt.Errorf("error updating maintenance start time: %w", err) - } - } - if v, ok := d.GetOk("smb_security_strategy"); ok { input := &storagegateway.UpdateSMBSecurityStrategyInput{ GatewayARN: aws.String(d.Id()), @@ -573,24 +534,6 @@ func resourceAwsStorageGatewayGatewayRead(d *schema.ResourceData, meta interface return fmt.Errorf("error setting gateway_network_interface: %w", err) } - maintenanceStartTimeInput := &storagegateway.DescribeMaintenanceStartTimeInput{ - GatewayARN: aws.String(d.Id()), - } - maintenanceStartTimeOutput, err := conn.DescribeMaintenanceStartTime(maintenanceStartTimeInput) - if err != nil && !isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") { - return fmt.Errorf("error reading Storage Gateway Maintenance time start: %s", err) - } - if err == nil { - m := map[string]interface{}{ - "hour": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), - "minute": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), - "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), - } - if err := d.Set("maintenance_start_time", []map[string]interface{}{m}); err != nil { - return fmt.Errorf("error setting maintenance_start_time: %w", err) - } - } - bandwidthInput := &storagegateway.DescribeBandwidthRateLimitInput{ GatewayARN: aws.String(d.Id()), } @@ -719,24 +662,7 @@ func resourceAwsStorageGatewayGatewayUpdate(d *schema.ResourceData, meta interfa return fmt.Errorf("error unsetting Bandwidth Rate Limit: %w", err) } } - } - - if d.HasChange("maintenance_start_time") { - l := d.Get("maintenance_start_time").([]interface{}) - m := l[0].(map[string]interface{}) - - input := &storagegateway.UpdateMaintenanceStartTimeInput{ - DayOfWeek: aws.Int64(int64(m["day_of_week"].(int))), - GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(m["hour"].(int))), - MinuteOfHour: aws.Int64(int64(m["minute"].(int))), - } - log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) - _, err := conn.UpdateMaintenanceStartTime(input) - if err != nil { - return fmt.Errorf("error updating maintenance start time: %w", err) - } } return resourceAwsStorageGatewayGatewayRead(d, meta) diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 20e87d65434..2cd33b782a5 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -667,45 +667,6 @@ func TestAccAWSStorageGatewayGateway_bandwidthAll(t *testing.T) { }) } -func TestAccAWSStorageGatewayGateway_maintenanceStartTime(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: testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName, 22, 0, 3), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour", "22"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute", "0"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "3"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"}, - }, - { - Config: testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName, 21, 10, 0), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSStorageGatewayGatewayExists(resourceName, &gateway), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour", "21"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute", "10"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "0"), - ), - }, - }, - }) -} - func testAccCheckAWSStorageGatewayGatewayDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).storagegatewayconn @@ -1214,19 +1175,3 @@ resource "aws_storagegateway_gateway" "test" { } `, rName, rate) } - -func testAccAWSStorageGatewayGatewayMaintenanceStartTimeConfig(rName string, hour int, minute int, day_of_week int) string { - return testAccAWSStorageGateway_TapeAndVolumeGatewayBase(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 = "CACHED" - maintenance_start_time { - hour = %[2]d - minute = %[3]d - day_of_week = %[4]d - } -} -`, rName, hour, minute, day_of_week) -} From 853affe338d56b6c41b26f595c714fbde4fc3045 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:21:15 -0400 Subject: [PATCH 11/29] r/aws_storagegateway_nfs_file_share: Alphabetize attributes. --- .../service/storagegateway/nfs_file_share.go | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index d8a0aa59173..96080c25059 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -36,21 +36,35 @@ func ResourceNFSFileShare() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, "audit_destination_arn": { Type: schema.TypeString, Optional: true, ValidateFunc: verify.ValidARN, }, - "arn": { - Type: schema.TypeString, - Computed: true, - }, "bucket_region": { Type: schema.TypeString, Optional: true, ForceNew: true, RequiredWith: []string{"vpc_endpoint_dns_name"}, }, + "cache_attributes": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cache_stale_timeout_in_seconds": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(300, 2592000), + }, + }, + }, + }, "client_list": { Type: schema.TypeSet, Required: true, @@ -79,6 +93,12 @@ func ResourceNFSFileShare() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "file_share_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(1, 255), + }, "gateway_arn": { Type: schema.TypeString, Required: true, @@ -139,19 +159,14 @@ func ResourceNFSFileShare() *schema.Resource { }, }, }, - "cache_attributes": { - Type: schema.TypeList, + "notification_policy": { + Type: schema.TypeString, Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "cache_stale_timeout_in_seconds": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(300, 2592000), - }, - }, - }, + Default: "{}", + ValidateFunc: validation.All( + validation.StringMatch(regexp.MustCompile(`^\{[\w\s:\{\}\[\]"]*}$`), ""), + validation.StringLenBetween(2, 100), + ), }, "object_acl": { Type: schema.TypeString, @@ -189,21 +204,6 @@ func ResourceNFSFileShare() *schema.Resource { "RootSquash", }, false), }, - "file_share_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(1, 255), - }, - "notification_policy": { - Type: schema.TypeString, - Optional: true, - Default: "{}", - ValidateFunc: validation.All( - validation.StringMatch(regexp.MustCompile(`^\{[\w\s:\{\}\[\]"]*}$`), ""), - validation.StringLenBetween(2, 100), - ), - }, "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), "vpc_endpoint_dns_name": { From 3e2b2d917049c6b8f4e1096a3aa77d4db1b170b5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:31:21 -0400 Subject: [PATCH 12/29] r/aws_storagegateway_nfs_file_share: Add and use '_Values()' (#14601). --- internal/service/storagegateway/enum.go | 14 +++++++++ .../service/storagegateway/nfs_file_share.go | 29 +++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/internal/service/storagegateway/enum.go b/internal/service/storagegateway/enum.go index fe332c00bc5..9ea69ba0379 100644 --- a/internal/service/storagegateway/enum.go +++ b/internal/service/storagegateway/enum.go @@ -30,6 +30,20 @@ func defaultStorageClass_Values() []string { } } +const ( + squashAllSquash = "AllSquash" + squashNoSquash = "NoSquash" + squashRootSquash = "RootSquash" +) + +func squash_Values() []string { + return []string{ + squashAllSquash, + squashNoSquash, + squashRootSquash, + } +} + const ( fileShareStatusAvailable = "AVAILABLE" fileShareStatusCreating = "CREATING" diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index 96080c25059..90ccb2d7979 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -79,15 +79,10 @@ func ResourceNFSFileShare() *schema.Resource { }, }, "default_storage_class": { - Type: schema.TypeString, - Optional: true, - Default: "S3_STANDARD", - ValidateFunc: validation.StringInSlice([]string{ - "S3_ONEZONE_IA", - "S3_STANDARD_IA", - "S3_STANDARD", - "S3_INTELLIGENT_TIERING", - }, false), + Type: schema.TypeString, + Optional: true, + Default: defaultStorageClassS3Standard, + ValidateFunc: validation.StringInSlice(defaultStorageClass_Values(), false), }, "fileshare_id": { Type: schema.TypeString, @@ -195,14 +190,10 @@ func ResourceNFSFileShare() *schema.Resource { ValidateFunc: verify.ValidARN, }, "squash": { - Type: schema.TypeString, - Optional: true, - Default: "RootSquash", - ValidateFunc: validation.StringInSlice([]string{ - "AllSquash", - "NoSquash", - "RootSquash", - }, false), + Type: schema.TypeString, + Optional: true, + Default: squashRootSquash, + ValidateFunc: validation.StringInSlice(squash_Values(), false), }, "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), @@ -247,7 +238,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("audit_destination_arn"); ok { input.AuditDestinationARN = aws.String(v.(string)) } - + if v, ok := d.GetOk("bucket_region"); ok { input.BucketRegion = aws.String(v.(string)) } @@ -263,7 +254,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("file_share_name"); ok { input.FileShareName = aws.String(v.(string)) } - + if v, ok := d.GetOk("vpc_endpoint_dns_name"); ok { input.VPCEndpointDNSName = aws.String(v.(string)) } From ff4ff5cb5e16548ded353dc4ff28da24b784dd1d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 08:46:17 -0400 Subject: [PATCH 13/29] r/aws_storagegateway_nfs_file_share: Cosmetics. --- .../service/storagegateway/nfs_file_share.go | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index 90ccb2d7979..ade5a4fcd9d 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -214,6 +214,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) fileShareDefaults, err := expandStorageGatewayNfsFileShareDefaults(d.Get("nfs_file_share_defaults").([]interface{})) + if err != nil { return err } @@ -243,6 +244,14 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error input.BucketRegion = aws.String(v.(string)) } + if v, ok := d.GetOk("cache_attributes"); ok { + input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) + } + + if v, ok := d.GetOk("file_share_name"); ok { + input.FileShareName = aws.String(v.(string)) + } + if v, ok := d.GetOk("kms_key_arn"); ok { input.KMSKey = aws.String(v.(string)) } @@ -251,20 +260,13 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error input.NotificationPolicy = aws.String(v.(string)) } - if v, ok := d.GetOk("file_share_name"); ok { - input.FileShareName = aws.String(v.(string)) - } - if v, ok := d.GetOk("vpc_endpoint_dns_name"); ok { input.VPCEndpointDNSName = aws.String(v.(string)) } - if v, ok := d.GetOk("cache_attributes"); ok { - input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) - } - log.Printf("[DEBUG] Creating Storage Gateway NFS File Share: %s", input) output, err := conn.CreateNFSFileShare(input) + if err != nil { return fmt.Errorf("error creating Storage Gateway NFS File Share: %w", err) } @@ -272,7 +274,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error d.SetId(aws.StringValue(output.FileShareARN)) if _, err = waitNFSFileShareAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%q) to be Available: %w", d.Id(), err) + return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) to be Available: %w", d.Id(), err) } return resourceNFSFileShareRead(d, meta) @@ -358,15 +360,9 @@ func resourceNFSFileShareRead(d *schema.ResourceData, meta interface{}) error { func resourceNFSFileShareUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).StorageGatewayConn - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { - return fmt.Errorf("error updating tags: %w", err) - } - } - if d.HasChangesExcept("tags_all", "tags") { fileShareDefaults, err := expandStorageGatewayNfsFileShareDefaults(d.Get("nfs_file_share_defaults").([]interface{})) + if err != nil { return err } @@ -388,30 +384,39 @@ func resourceNFSFileShareUpdate(d *schema.ResourceData, meta interface{}) error input.AuditDestinationARN = aws.String(v.(string)) } - if v, ok := d.GetOk("kms_key_arn"); ok { - input.KMSKey = aws.String(v.(string)) - } - - if v, ok := d.GetOk("notification_policy"); ok { - input.NotificationPolicy = aws.String(v.(string)) + if v, ok := d.GetOk("cache_attributes"); ok { + input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) } if v, ok := d.GetOk("file_share_name"); ok { input.FileShareName = aws.String(v.(string)) } - if v, ok := d.GetOk("cache_attributes"); ok { - input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{})) + if v, ok := d.GetOk("kms_key_arn"); ok { + input.KMSKey = aws.String(v.(string)) + } + + if v, ok := d.GetOk("notification_policy"); ok { + input.NotificationPolicy = aws.String(v.(string)) } log.Printf("[DEBUG] Updating Storage Gateway NFS File Share: %s", input) _, err = conn.UpdateNFSFileShare(input) + if err != nil { - return fmt.Errorf("error updating Storage Gateway NFS File Share: %w", err) + return fmt.Errorf("error updating Storage Gateway NFS File Share (%s): %w", d.Id(), err) } if _, err = waitNFSFileShareAvailable(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%q) to be Available: %w", d.Id(), err) + return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) to be Available: %w", d.Id(), err) + } + } + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + + if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { + return fmt.Errorf("error updating tags: %w", err) } } @@ -421,17 +426,17 @@ func resourceNFSFileShareUpdate(d *schema.ResourceData, meta interface{}) error func resourceNFSFileShareDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).StorageGatewayConn - input := &storagegateway.DeleteFileShareInput{ + log.Printf("[DEBUG] Deleting Storage Gateway NFS File Share: %s", d.Id()) + _, err := conn.DeleteFileShare(&storagegateway.DeleteFileShareInput{ FileShareARN: aws.String(d.Id()), + }) + + if operationErrorCode(err) == operationErrCodeFileShareNotFound { + return nil } - log.Printf("[DEBUG] Deleting Storage Gateway NFS File Share: %s", input) - _, err := conn.DeleteFileShare(input) if err != nil { - if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") { - return nil - } - return fmt.Errorf("error deleting Storage Gateway NFS File Share: %w", err) + return fmt.Errorf("error deleting Storage Gateway NFS File Share (%s): %w", d.Id(), err) } if _, err = waitNFSFileShareDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { From 2301d98c535ca5b95049b2a4bd0d6dae52bea0d2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:03:02 -0400 Subject: [PATCH 14/29] Add and use 'FindNFSFileShareByARN'. --- internal/service/storagegateway/find.go | 29 ++++++++ .../service/storagegateway/nfs_file_share.go | 71 +++++++------------ .../storagegateway/nfs_file_share_test.go | 29 +++----- internal/service/storagegateway/status.go | 26 ++----- internal/service/storagegateway/wait.go | 33 ++++++--- 5 files changed, 95 insertions(+), 93 deletions(-) diff --git a/internal/service/storagegateway/find.go b/internal/service/storagegateway/find.go index 37eb9bdf19b..e8421a0ec65 100644 --- a/internal/service/storagegateway/find.go +++ b/internal/service/storagegateway/find.go @@ -82,6 +82,35 @@ func FindUploadBufferDisk(conn *storagegateway.StorageGateway, gatewayARN string return result, err } +func FindNFSFileShareByARN(conn *storagegateway.StorageGateway, arn string) (*storagegateway.NFSFileShareInfo, error) { + input := &storagegateway.DescribeNFSFileSharesInput{ + FileShareARNList: aws.StringSlice([]string{arn}), + } + + output, err := conn.DescribeNFSFileShares(input) + + if operationErrorCode(err) == operationErrCodeFileShareNotFound { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || len(output.NFSFileShareInfoList) == 0 || output.NFSFileShareInfoList[0] == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + if count := len(output.NFSFileShareInfoList); count > 1 { + return nil, tfresource.NewTooManyResultsError(count, input) + } + + return output.NFSFileShareInfoList[0], nil +} + func FindSMBFileShareByARN(conn *storagegateway.StorageGateway, arn string) (*storagegateway.SMBFileShareInfo, error) { input := &storagegateway.DescribeSMBFileSharesInput{ FileShareARNList: aws.StringSlice([]string{arn}), diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index ade5a4fcd9d..2477e915b93 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/storagegateway" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -26,9 +25,11 @@ func ResourceNFSFileShare() *schema.Resource { Read: resourceNFSFileShareRead, Update: resourceNFSFileShareUpdate, Delete: resourceNFSFileShareDelete, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), @@ -84,16 +85,16 @@ func ResourceNFSFileShare() *schema.Resource { Default: defaultStorageClassS3Standard, ValidateFunc: validation.StringInSlice(defaultStorageClass_Values(), false), }, - "fileshare_id": { - Type: schema.TypeString, - Computed: true, - }, "file_share_name": { Type: schema.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringLenBetween(1, 255), }, + "fileshare_id": { + Type: schema.TypeString, + Computed: true, + }, "gateway_arn": { Type: schema.TypeString, Required: true, @@ -273,8 +274,8 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error d.SetId(aws.StringValue(output.FileShareARN)) - if _, err = waitNFSFileShareAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) to be Available: %w", d.Id(), err) + if _, err = waitNFSFileShareCreated(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) create: %w", d.Id(), err) } return resourceNFSFileShareRead(d, meta) @@ -285,63 +286,46 @@ func resourceNFSFileShareRead(d *schema.ResourceData, meta interface{}) error { defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - input := &storagegateway.DescribeNFSFileSharesInput{ - FileShareARNList: []*string{aws.String(d.Id())}, - } - - log.Printf("[DEBUG] Reading Storage Gateway NFS File Share: %s", input) - output, err := conn.DescribeNFSFileShares(input) - if err != nil { - if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") { - log.Printf("[WARN] Storage Gateway NFS File Share %q not found, removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("error reading Storage Gateway NFS File Share: %w", err) - } + fileshare, err := FindNFSFileShareByARN(conn, d.Id()) - if output == nil || len(output.NFSFileShareInfoList) == 0 || output.NFSFileShareInfoList[0] == nil { - log.Printf("[WARN] Storage Gateway NFS File Share %q not found, removing from state", d.Id()) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] Storage Gateway NFS File Share (%s) not found, removing from state", d.Id()) d.SetId("") return nil } - fileshare := output.NFSFileShareInfoList[0] - - arn := fileshare.FileShareARN - d.Set("arn", arn) - - if err := d.Set("client_list", flex.FlattenStringSet(fileshare.ClientList)); err != nil { - return fmt.Errorf("error setting client_list: %w", err) + if err != nil { + return fmt.Errorf("error reading Storage Gateway NFS File Share (%s): %w", d.Id(), err) } + d.Set("arn", fileshare.FileShareARN) d.Set("audit_destination_arn", fileshare.AuditDestinationARN) d.Set("bucket_region", fileshare.BucketRegion) + if err := d.Set("cache_attributes", flattenStorageGatewayNfsFileShareCacheAttributes(fileshare.CacheAttributes)); err != nil { + return fmt.Errorf("error setting cache_attributes: %w", err) + } + if err := d.Set("client_list", flex.FlattenStringSet(fileshare.ClientList)); err != nil { + return fmt.Errorf("error setting client_list: %w", err) + } d.Set("default_storage_class", fileshare.DefaultStorageClass) + d.Set("file_share_name", fileshare.FileShareName) d.Set("fileshare_id", fileshare.FileShareId) d.Set("gateway_arn", fileshare.GatewayARN) d.Set("guess_mime_type_enabled", fileshare.GuessMIMETypeEnabled) d.Set("kms_encrypted", fileshare.KMSEncrypted) d.Set("kms_key_arn", fileshare.KMSKey) d.Set("location_arn", fileshare.LocationARN) - d.Set("file_share_name", fileshare.FileShareName) - d.Set("vpc_endpoint_dns_name", fileshare.VPCEndpointDNSName) - if err := d.Set("nfs_file_share_defaults", flattenStorageGatewayNfsFileShareDefaults(fileshare.NFSFileShareDefaults)); err != nil { return fmt.Errorf("error setting nfs_file_share_defaults: %w", err) } - - if err := d.Set("cache_attributes", flattenStorageGatewayNfsFileShareCacheAttributes(fileshare.CacheAttributes)); err != nil { - return fmt.Errorf("error setting cache_attributes: %w", err) - } - + d.Set("notification_policy", fileshare.NotificationPolicy) d.Set("object_acl", fileshare.ObjectACL) d.Set("path", fileshare.Path) d.Set("read_only", fileshare.ReadOnly) d.Set("requester_pays", fileshare.RequesterPays) d.Set("role_arn", fileshare.Role) d.Set("squash", fileshare.Squash) - d.Set("notification_policy", fileshare.NotificationPolicy) + d.Set("vpc_endpoint_dns_name", fileshare.VPCEndpointDNSName) tags := KeyValueTags(fileshare.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) @@ -407,8 +391,8 @@ func resourceNFSFileShareUpdate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("error updating Storage Gateway NFS File Share (%s): %w", d.Id(), err) } - if _, err = waitNFSFileShareAvailable(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) to be Available: %w", d.Id(), err) + if _, err = waitNFSFileShareUpdated(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) update: %w", d.Id(), err) } } @@ -440,10 +424,7 @@ func resourceNFSFileShareDelete(d *schema.ResourceData, meta interface{}) error } if _, err = waitNFSFileShareDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - if tfresource.NotFound(err) { - return nil - } - return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%q) to be deleted: %w", d.Id(), err) + return fmt.Errorf("error waiting for Storage Gateway NFS File Share (%s) delete: %w", d.Id(), err) } return nil diff --git a/internal/service/storagegateway/nfs_file_share_test.go b/internal/service/storagegateway/nfs_file_share_test.go index 558425fdabf..897c78bae16 100644 --- a/internal/service/storagegateway/nfs_file_share_test.go +++ b/internal/service/storagegateway/nfs_file_share_test.go @@ -5,15 +5,14 @@ import ( "regexp" "testing" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/storagegateway" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfstoragegateway "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccStorageGatewayNFSFileShare_basic(t *testing.T) { @@ -668,22 +667,17 @@ func testAccCheckNFSFileShareDestroy(s *terraform.State) error { continue } - input := &storagegateway.DescribeNFSFileSharesInput{ - FileShareARNList: []*string{aws.String(rs.Primary.ID)}, - } + _, err := tfstoragegateway.FindNFSFileShareByARN(conn, rs.Primary.ID) - output, err := conn.DescribeNFSFileShares(input) + if tfresource.NotFound(err) { + continue + } if err != nil { - if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") { - continue - } return err } - if output != nil && len(output.NFSFileShareInfoList) > 0 && output.NFSFileShareInfoList[0] != nil { - return fmt.Errorf("Storage Gateway NFS File Share %q still exists", rs.Primary.ID) - } + return fmt.Errorf("Storage Gateway NFS File Share %s still exists", rs.Primary.ID) } return nil @@ -698,21 +692,14 @@ func testAccCheckNFSFileShareExists(resourceName string, nfsFileShare *storagega } conn := acctest.Provider.Meta().(*conns.AWSClient).StorageGatewayConn - input := &storagegateway.DescribeNFSFileSharesInput{ - FileShareARNList: []*string{aws.String(rs.Primary.ID)}, - } - output, err := conn.DescribeNFSFileShares(input) + output, err := tfstoragegateway.FindNFSFileShareByARN(conn, rs.Primary.ID) if err != nil { return err } - if output == nil || len(output.NFSFileShareInfoList) == 0 || output.NFSFileShareInfoList[0] == nil { - return fmt.Errorf("Storage Gateway NFS File Share %q does not exist", rs.Primary.ID) - } - - *nfsFileShare = *output.NFSFileShareInfoList[0] + *nfsFileShare = *output return nil } diff --git a/internal/service/storagegateway/status.go b/internal/service/storagegateway/status.go index 7dda02c0563..54110e669f6 100644 --- a/internal/service/storagegateway/status.go +++ b/internal/service/storagegateway/status.go @@ -1,9 +1,6 @@ package storagegateway import ( - "fmt" - "log" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/storagegateway" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" @@ -83,28 +80,19 @@ func statusStorediSCSIVolume(conn *storagegateway.StorageGateway, volumeARN stri } } -func statusNFSFileShare(conn *storagegateway.StorageGateway, fileShareArn string) resource.StateRefreshFunc { +func statusNFSFileShare(conn *storagegateway.StorageGateway, arn string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - input := &storagegateway.DescribeNFSFileSharesInput{ - FileShareARNList: []*string{aws.String(fileShareArn)}, - } + output, err := FindNFSFileShareByARN(conn, arn) - log.Printf("[DEBUG] Reading Storage Gateway NFS File Share: %s", input) - output, err := conn.DescribeNFSFileShares(input) - if err != nil { - if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") { - return nil, nfsFileShareStatusNotFound, nil - } - return nil, "", fmt.Errorf("error reading Storage Gateway NFS File Share: %w", err) + if tfresource.NotFound(err) { + return nil, "", nil } - if output == nil || len(output.NFSFileShareInfoList) == 0 || output.NFSFileShareInfoList[0] == nil { - return nil, nfsFileShareStatusNotFound, nil + if err != nil { + return nil, "", err } - fileshare := output.NFSFileShareInfoList[0] - - return fileshare, aws.StringValue(fileshare.FileShareStatus), nil + return output, aws.StringValue(output.FileShareStatus), nil } } diff --git a/internal/service/storagegateway/wait.go b/internal/service/storagegateway/wait.go index a3304b2acc8..8f4a3de8ddd 100644 --- a/internal/service/storagegateway/wait.go +++ b/internal/service/storagegateway/wait.go @@ -75,12 +75,11 @@ func waitStorediSCSIVolumeAvailable(conn *storagegateway.StorageGateway, volumeA return nil, err } -// waitNFSFileShareAvailable waits for a NFS File Share to return Available -func waitNFSFileShareAvailable(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { //nolint:unparam +func waitNFSFileShareCreated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { //nolint:unparam stateConf := &resource.StateChangeConf{ - Pending: []string{"BOOTSTRAPPING", "CREATING", "RESTORING", "UPDATING"}, - Target: []string{"AVAILABLE"}, - Refresh: statusNFSFileShare(conn, fileShareArn), + Pending: []string{fileShareStatusCreating}, + Target: []string{fileShareStatusAvailable}, + Refresh: statusNFSFileShare(conn, arn), Timeout: timeout, Delay: nfsFileShareAvailableDelay, } @@ -94,11 +93,11 @@ func waitNFSFileShareAvailable(conn *storagegateway.StorageGateway, fileShareArn return nil, err } -func waitNFSFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { +func waitNFSFileShareDeleted(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{"AVAILABLE", "DELETING", "FORCE_DELETING"}, + Pending: []string{fileShareStatusAvailable, fileShareStatusDeleting, fileShareStatusForceDeleting}, Target: []string{}, - Refresh: statusNFSFileShare(conn, fileShareArn), + Refresh: statusNFSFileShare(conn, arn), Timeout: timeout, Delay: nfsFileShareDeletedDelay, NotFoundChecks: 1, @@ -113,6 +112,24 @@ func waitNFSFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn s return nil, err } +func waitNFSFileShareUpdated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { //nolint:unparam + stateConf := &resource.StateChangeConf{ + Pending: []string{fileShareStatusUpdating}, + Target: []string{fileShareStatusAvailable}, + Refresh: statusNFSFileShare(conn, arn), + Timeout: timeout, + Delay: nfsFileShareAvailableDelay, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*storagegateway.NFSFileShareInfo); ok { + return output, err + } + + return nil, err +} + func waitSMBFileShareCreated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) { stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusCreating}, From 5bc9eafaf57cafe82b65293f1a6f17421cccdfd3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:04:26 -0400 Subject: [PATCH 15/29] 'statussmBFileShare' -> 'statusSMBFileShare'. --- internal/service/storagegateway/status.go | 2 +- internal/service/storagegateway/wait.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/storagegateway/status.go b/internal/service/storagegateway/status.go index 54110e669f6..72a51f641e5 100644 --- a/internal/service/storagegateway/status.go +++ b/internal/service/storagegateway/status.go @@ -96,7 +96,7 @@ func statusNFSFileShare(conn *storagegateway.StorageGateway, arn string) resourc } } -func statussmBFileShare(conn *storagegateway.StorageGateway, arn string) resource.StateRefreshFunc { +func statusSMBFileShare(conn *storagegateway.StorageGateway, arn string) resource.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindSMBFileShareByARN(conn, arn) diff --git a/internal/service/storagegateway/wait.go b/internal/service/storagegateway/wait.go index 8f4a3de8ddd..7e9b2dd586e 100644 --- a/internal/service/storagegateway/wait.go +++ b/internal/service/storagegateway/wait.go @@ -134,7 +134,7 @@ func waitSMBFileShareCreated(conn *storagegateway.StorageGateway, arn string, ti stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusCreating}, Target: []string{fileShareStatusAvailable}, - Refresh: statussmBFileShare(conn, arn), + Refresh: statusSMBFileShare(conn, arn), Timeout: timeout, Delay: smbFileShareAvailableDelay, } @@ -152,7 +152,7 @@ func waitSMBFileShareDeleted(conn *storagegateway.StorageGateway, arn string, ti stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusAvailable, fileShareStatusDeleting, fileShareStatusForceDeleting}, Target: []string{}, - Refresh: statussmBFileShare(conn, arn), + Refresh: statusSMBFileShare(conn, arn), Timeout: timeout, Delay: smbFileShareDeletedDelay, NotFoundChecks: 1, @@ -171,7 +171,7 @@ func waitSMBFileShareUpdated(conn *storagegateway.StorageGateway, arn string, ti stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusUpdating}, Target: []string{fileShareStatusAvailable}, - Refresh: statussmBFileShare(conn, arn), + Refresh: statusSMBFileShare(conn, arn), Timeout: timeout, Delay: smbFileShareAvailableDelay, } From 4438ce15e2d5374473a071866aacd4b0407bdf15 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:17:23 -0400 Subject: [PATCH 16/29] r/aws_storagegateway_nfs_file_share: Test 'bucket_region' and 'vpc_endpoint_dns_name'. Acceptance test output: % make testacc TESTS=TestAccStorageGatewayNFSFileShare_basic PKG=storagegateway ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/storagegateway/... -v -count 1 -parallel 20 -run='TestAccStorageGatewayNFSFileShare_basic' -timeout 180m === RUN TestAccStorageGatewayNFSFileShare_basic === PAUSE TestAccStorageGatewayNFSFileShare_basic === CONT TestAccStorageGatewayNFSFileShare_basic --- PASS: TestAccStorageGatewayNFSFileShare_basic (325.55s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway 330.882s --- internal/service/storagegateway/nfs_file_share_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/service/storagegateway/nfs_file_share_test.go b/internal/service/storagegateway/nfs_file_share_test.go index 897c78bae16..30608519b41 100644 --- a/internal/service/storagegateway/nfs_file_share_test.go +++ b/internal/service/storagegateway/nfs_file_share_test.go @@ -31,12 +31,15 @@ func TestAccStorageGatewayNFSFileShare_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccNFSFileShareConfig_Required(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckNFSFileShareExists(resourceName, &nfsFileShare), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`share/share-.+`)), + resource.TestCheckResourceAttr(resourceName, "bucket_region", ""), + resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "0"), resource.TestCheckResourceAttr(resourceName, "client_list.#", "1"), resource.TestCheckTypeSetElemAttr(resourceName, "client_list.*", "0.0.0.0/0"), resource.TestCheckResourceAttr(resourceName, "default_storage_class", "S3_STANDARD"), + resource.TestCheckResourceAttr(resourceName, "file_share_name", rName), resource.TestMatchResourceAttr(resourceName, "fileshare_id", regexp.MustCompile(`^share-`)), resource.TestCheckResourceAttrPair(resourceName, "gateway_arn", gatewayResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "guess_mime_type_enabled", "true"), @@ -44,16 +47,15 @@ func TestAccStorageGatewayNFSFileShare_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "kms_key_arn", ""), resource.TestCheckResourceAttrPair(resourceName, "location_arn", bucketResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "nfs_file_share_defaults.#", "0"), + resource.TestCheckResourceAttr(resourceName, "notification_policy", "{}"), resource.TestCheckResourceAttr(resourceName, "object_acl", storagegateway.ObjectACLPrivate), resource.TestMatchResourceAttr(resourceName, "path", regexp.MustCompile(`^/.+`)), resource.TestCheckResourceAttr(resourceName, "read_only", "false"), resource.TestCheckResourceAttr(resourceName, "requester_pays", "false"), resource.TestCheckResourceAttrPair(resourceName, "role_arn", iamResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "squash", "RootSquash"), - resource.TestCheckResourceAttr(resourceName, "cache_attributes.#", "0"), - resource.TestCheckResourceAttr(resourceName, "file_share_name", rName), - resource.TestCheckResourceAttr(resourceName, "notification_policy", "{}"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(resourceName, "vpc_endpoint_dns_name", ""), ), }, { From 59f90929dc11b094d56a139733e5a85f845bd907 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:29:50 -0400 Subject: [PATCH 17/29] r/aws_storagegateway_gateway: Alphabetize attributes. --- internal/service/storagegateway/gateway.go | 179 +++++++++++---------- 1 file changed, 91 insertions(+), 88 deletions(-) diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index e4f4c1439b1..46e83b72466 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -29,24 +29,16 @@ func ResourceGateway() *schema.Resource { Read: resourceGatewayRead, Update: resourceGatewayUpdate, Delete: resourceGatewayDelete, - CustomizeDiff: customdiff.Sequence( - customdiff.ForceNewIfChange("smb_active_directory_settings", func(_ context.Context, old, new, meta interface{}) bool { - return len(old.([]interface{})) == 1 && len(new.([]interface{})) == 0 - }), - verify.SetTagsDiff, - ), + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(15 * time.Minute), }, Schema: map[string]*schema.Schema{ - "arn": { - Type: schema.TypeString, - Computed: true, - }, "activation_key": { Type: schema.TypeString, Optional: true, @@ -54,10 +46,32 @@ func ResourceGateway() *schema.Resource { ForceNew: true, ConflictsWith: []string{"gateway_ip_address"}, }, - "gateway_vpc_endpoint": { + "arn": { Type: schema.TypeString, - Optional: true, - ForceNew: true, + Computed: true, + }, + "average_download_rate_limit_in_bits_per_sec": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntAtLeast(102400), + }, + "average_upload_rate_limit_in_bits_per_sec": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntAtLeast(51200), + }, + "cloudwatch_log_group_arn": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidARN, + }, + "ec2_instance_id": { + Type: schema.TypeString, + Computed: true, + }, + "endpoint_type": { + Type: schema.TypeString, + Computed: true, }, "gateway_id": { Type: schema.TypeString, @@ -79,6 +93,18 @@ func ResourceGateway() *schema.Resource { validation.StringLenBetween(2, 255), ), }, + "gateway_network_interface": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ipv4_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, "gateway_timezone": { Type: schema.TypeString, Required: true, @@ -100,6 +126,15 @@ func ResourceGateway() *schema.Resource { "VTL", }, false), }, + "gateway_vpc_endpoint": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "host_environment": { + Type: schema.TypeString, + Computed: true, + }, "medium_changer_type": { Type: schema.TypeString, Optional: true, @@ -116,6 +151,21 @@ func ResourceGateway() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "active_directory_status": { + Type: schema.TypeString, + Computed: true, + }, + "domain_controllers": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.All( + validation.StringMatch(regexp.MustCompile(`^(([a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9\-]*[A-Za-z0-9])(:(\d+))?$`), ""), + validation.StringLenBetween(6, 1024), + ), + }, + }, "domain_name": { Type: schema.TypeString, Required: true, @@ -124,11 +174,10 @@ func ResourceGateway() *schema.Resource { validation.StringLenBetween(1, 1024), ), }, - "timeout_in_seconds": { - Type: schema.TypeInt, + "organizational_unit": { + Type: schema.TypeString, Optional: true, - Default: 20, - ValidateFunc: validation.IntBetween(0, 3600), + ValidateFunc: validation.StringLenBetween(1, 1024), }, "password": { Type: schema.TypeString, @@ -139,6 +188,12 @@ func ResourceGateway() *schema.Resource { validation.StringLenBetween(1, 1024), ), }, + "timeout_in_seconds": { + Type: schema.TypeInt, + Optional: true, + Default: 20, + ValidateFunc: validation.IntBetween(0, 3600), + }, "username": { Type: schema.TypeString, Required: true, @@ -147,29 +202,13 @@ func ResourceGateway() *schema.Resource { validation.StringLenBetween(1, 1024), ), }, - "organizational_unit": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 1024), - }, - "domain_controllers": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.All( - validation.StringMatch(regexp.MustCompile(`^(([a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9\-]*[A-Za-z0-9])(:(\d+))?$`), ""), - validation.StringLenBetween(6, 1024), - ), - }, - }, - "active_directory_status": { - Type: schema.TypeString, - Computed: true, - }, }, }, }, + "smb_file_share_visibility": { + Type: schema.TypeBool, + Optional: true, + }, "smb_guest_password": { Type: schema.TypeString, Optional: true, @@ -179,66 +218,30 @@ func ResourceGateway() *schema.Resource { validation.StringLenBetween(6, 512), ), }, - "tape_drive_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "IBM-ULT3580-TD5", - }, false), - }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), - "cloudwatch_log_group_arn": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: verify.ValidARN, - }, "smb_security_strategy": { Type: schema.TypeString, Optional: true, 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, - ValidateFunc: validation.IntAtLeast(102400), - }, - "average_upload_rate_limit_in_bits_per_sec": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntAtLeast(51200), - }, - "ec2_instance_id": { - Type: schema.TypeString, - Computed: true, - }, - "endpoint_type": { - Type: schema.TypeString, - Computed: true, - }, - "host_environment": { + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + "tape_drive_type": { Type: schema.TypeString, - Computed: true, - }, - "gateway_network_interface": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ipv4_address": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "IBM-ULT3580-TD5", + }, false), }, }, + + CustomizeDiff: customdiff.Sequence( + customdiff.ForceNewIfChange("smb_active_directory_settings", func(_ context.Context, old, new, meta interface{}) bool { + return len(old.([]interface{})) == 1 && len(new.([]interface{})) == 0 + }), + verify.SetTagsDiff, + ), } } From 9af967f0d38832c3a9290d1f219f4c559f772002 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:39:56 -0400 Subject: [PATCH 18/29] r/aws_storagegateway_gateway: Add and use '_Values()' (#14601). --- internal/service/storagegateway/enum.go | 44 ++++++++++++++++++++++ internal/service/storagegateway/gateway.go | 38 +++++++------------ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/internal/service/storagegateway/enum.go b/internal/service/storagegateway/enum.go index 9ea69ba0379..3165ddff45c 100644 --- a/internal/service/storagegateway/enum.go +++ b/internal/service/storagegateway/enum.go @@ -30,6 +30,40 @@ func defaultStorageClass_Values() []string { } } +const ( + gatewayTypeCached = "CACHED" + gatewayTypeFileFSXSMB = "FILE_FSX_SMB" + gatewayTypeFileS3 = "FILE_S3" + gatewayTypeStored = "STORED" + gatewayTypeVTL = "VTL" + gatewayTypeVTLSnow = "VTL_SNOW" +) + +func gatewayType_Values() []string { + return []string{ + gatewayTypeCached, + gatewayTypeFileFSXSMB, + gatewayTypeFileS3, + gatewayTypeStored, + gatewayTypeVTL, + gatewayTypeVTLSnow, + } +} + +const ( + mediumChangerTypeAWS_Gateway_VTL = "AWS-Gateway-VTL" + mediumChangerTypeIBM_03584L32_0402 = "IBM-03584L32-0402" + mediumChangerTypeSTK_L700 = "STK-L700" +) + +func mediumChangerType_Values() []string { + return []string{ + mediumChangerTypeAWS_Gateway_VTL, + mediumChangerTypeIBM_03584L32_0402, + mediumChangerTypeSTK_L700, + } +} + const ( squashAllSquash = "AllSquash" squashNoSquash = "NoSquash" @@ -44,6 +78,16 @@ func squash_Values() []string { } } +const ( + tapeDriveTypeIBM_ULT3580_TD5 = "IBM-ULT3580-TD5" +) + +func tapeDriveType_Values() []string { + return []string{ + tapeDriveTypeIBM_ULT3580_TD5, + } +} + const ( fileShareStatusAvailable = "AVAILABLE" fileShareStatusCreating = "CREATING" diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index 46e83b72466..d255df70e45 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -114,17 +114,11 @@ func ResourceGateway() *schema.Resource { ), }, "gateway_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "STORED", - ValidateFunc: validation.StringInSlice([]string{ - "CACHED", - "FILE_FSX_SMB", - "FILE_S3", - "STORED", - "VTL", - }, false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: gatewayTypeStored, + ValidateFunc: validation.StringInSlice(gatewayType_Values(), false), }, "gateway_vpc_endpoint": { Type: schema.TypeString, @@ -136,14 +130,10 @@ func ResourceGateway() *schema.Resource { Computed: true, }, "medium_changer_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "AWS-Gateway-VTL", - "STK-L700", - "IBM-03584L32-0402", - }, false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(mediumChangerType_Values(), false), }, "smb_active_directory_settings": { Type: schema.TypeList, @@ -227,12 +217,10 @@ func ResourceGateway() *schema.Resource { "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), "tape_drive_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "IBM-ULT3580-TD5", - }, false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(tapeDriveType_Values(), false), }, }, From a9be9aa59aecdcb1739225aa498b56cf2d8c91b0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:46:32 -0400 Subject: [PATCH 19/29] r/aws_storagegateway_gateway: Tidy up resource Delete. --- internal/service/storagegateway/gateway.go | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index d255df70e45..93d74d8f636 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -40,11 +40,11 @@ func ResourceGateway() *schema.Resource { Schema: map[string]*schema.Schema{ "activation_key": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"gateway_ip_address"}, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ExactlyOneOf: []string{"activation_key", "gateway_ip_address"}, }, "arn": { Type: schema.TypeString, @@ -78,12 +78,12 @@ func ResourceGateway() *schema.Resource { Computed: true, }, "gateway_ip_address": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.IsIPv4Address, - ConflictsWith: []string{"activation_key"}, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.IsIPv4Address, + ExactlyOneOf: []string{"activation_key", "gateway_ip_address"}, }, "gateway_name": { Type: schema.TypeString, @@ -714,17 +714,17 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { func resourceGatewayDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).StorageGatewayConn - input := &storagegateway.DeleteGatewayInput{ + log.Printf("[DEBUG] Deleting Storage Gateway Gateway: %s", d.Id()) + _, err := conn.DeleteGateway(&storagegateway.DeleteGatewayInput{ GatewayARN: aws.String(d.Id()), + }) + + if operationErrorCode(err) == storagegateway.ErrorCodeGatewayNotFound { + return nil } - log.Printf("[DEBUG] Deleting Storage Gateway Gateway: %s", input) - _, err := conn.DeleteGateway(input) if err != nil { - if IsErrGatewayNotFound(err) { - return nil - } - return fmt.Errorf("error deleting Storage Gateway Gateway: %w", err) + return fmt.Errorf("error deleting Storage Gateway Gateway (%s): %w", d.Id(), err) } return nil From 2dee622c0dc3508616ae8bca60ba565b6923dfb7 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Wed, 6 Apr 2022 08:47:41 -0500 Subject: [PATCH 20/29] Fix gofmt error --- internal/service/storagegateway/nfs_file_share.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index d8a0aa59173..32d0428ed10 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -247,7 +247,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("audit_destination_arn"); ok { input.AuditDestinationARN = aws.String(v.(string)) } - + if v, ok := d.GetOk("bucket_region"); ok { input.BucketRegion = aws.String(v.(string)) } @@ -263,7 +263,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("file_share_name"); ok { input.FileShareName = aws.String(v.(string)) } - + if v, ok := d.GetOk("vpc_endpoint_dns_name"); ok { input.VPCEndpointDNSName = aws.String(v.(string)) } From e3f1e179748909aa3447c38f4759f92ed0c046a3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 09:58:11 -0400 Subject: [PATCH 21/29] r/aws_storagegateway_gateway: Tidy up resource Update. --- internal/service/storagegateway/enum.go | 6 +++ internal/service/storagegateway/gateway.go | 57 +++++++++++----------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/internal/service/storagegateway/enum.go b/internal/service/storagegateway/enum.go index 3165ddff45c..f3c937e1742 100644 --- a/internal/service/storagegateway/enum.go +++ b/internal/service/storagegateway/enum.go @@ -14,6 +14,12 @@ func authentication_Values() []string { } } +const ( + bandwidthTypeAll = "ALL" + bandwidthTypeDownload = "DOWNLOAD" + bandwidthTypeUpload = "UPLOAD" +) + const ( defaultStorageClassS3IntelligentTiering = "S3_INTELLIGENT_TIERING" defaultStorageClassS3OneZoneIA = "S3_ONEZONE_IA" diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index 93d74d8f636..b811a8e0b2d 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -586,36 +586,32 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChanges("gateway_name", "gateway_timezone", "cloudwatch_log_group_arn") { input := &storagegateway.UpdateGatewayInformationInput{ + CloudWatchLogGroupARN: aws.String(d.Get("cloudwatch_log_group_arn").(string)), GatewayARN: aws.String(d.Id()), GatewayName: aws.String(d.Get("gateway_name").(string)), GatewayTimezone: aws.String(d.Get("gateway_timezone").(string)), - CloudWatchLogGroupARN: aws.String(d.Get("cloudwatch_log_group_arn").(string)), } log.Printf("[DEBUG] Updating Storage Gateway Gateway: %s", input) _, err := conn.UpdateGatewayInformation(input) - if err != nil { - return fmt.Errorf("error updating Storage Gateway Gateway: %w", err) - } - } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { - return fmt.Errorf("error updating tags: %w", err) + if err != nil { + return fmt.Errorf("error updating Storage Gateway Gateway (%s): %w", d.Id(), err) } } if d.HasChange("smb_active_directory_settings") { input := expandStorageGatewayGatewayDomain(d.Get("smb_active_directory_settings").([]interface{}), d.Id()) - log.Printf("[DEBUG] Storage Gateway Gateway %q joining Active Directory domain: %s", d.Id(), aws.StringValue(input.DomainName)) + domainName := aws.StringValue(input.DomainName) + _, err := conn.JoinDomain(input) + if err != nil { - return fmt.Errorf("error joining Active Directory domain: %w", err) + return fmt.Errorf("error joining Storage Gateway Gateway (%s) to Active Directory domain (%s): %w", d.Id(), domainName, err) } if _, err = waitStorageGatewayGatewayJoinDomainJoined(conn, d.Id()); err != nil { - return fmt.Errorf("error waiting for Storage Gateway Gateway (%q) to be Join domain (%s): %w", d.Id(), aws.StringValue(input.DomainName), err) + return fmt.Errorf("error waiting for Storage Gateway Gateway (%s) to join Active Directory domain (%s): %w", d.Id(), domainName, err) } } @@ -625,10 +621,10 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { Password: aws.String(d.Get("smb_guest_password").(string)), } - log.Printf("[DEBUG] Storage Gateway Gateway %q setting SMB guest password", d.Id()) _, err := conn.SetSMBGuestPassword(input) + if err != nil { - return fmt.Errorf("error setting SMB guest password: %w", err) + return fmt.Errorf("error updating Storage Gateway Gateway (%s) SMB guest password: %w", d.Id(), err) } } @@ -638,29 +634,27 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { SMBSecurityStrategy: aws.String(d.Get("smb_security_strategy").(string)), } - log.Printf("[DEBUG] Storage Gateway Gateway %q updating SMB Security Strategy", input) _, err := conn.UpdateSMBSecurityStrategy(input) + if err != nil { - return fmt.Errorf("error updating SMB Security Strategy: %w", err) + return fmt.Errorf("error updating Storage Gateway Gateway (%s) SMB security strategy: %w", d.Id(), err) } } 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)), + GatewayARN: aws.String(d.Id()), } - 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") { - + if d.HasChanges("average_download_rate_limit_in_bits_per_sec", "average_upload_rate_limit_in_bits_per_sec") { deleteInput := &storagegateway.DeleteBandwidthRateLimitInput{ GatewayARN: aws.String(d.Id()), } @@ -674,7 +668,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { updateInput.AverageDownloadRateLimitInBitsPerSec = aws.Int64(int64(v.(int))) needsUpdate = true } else if d.HasChange("average_download_rate_limit_in_bits_per_sec") { - deleteInput.BandwidthType = aws.String("DOWNLOAD") + deleteInput.BandwidthType = aws.String(bandwidthTypeDownload) needsDelete = true } @@ -683,29 +677,36 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { needsUpdate = true } else if d.HasChange("average_upload_rate_limit_in_bits_per_sec") { if needsDelete { - deleteInput.BandwidthType = aws.String("ALL") + deleteInput.BandwidthType = aws.String(bandwidthTypeAll) } else { - deleteInput.BandwidthType = aws.String("UPLOAD") + deleteInput.BandwidthType = aws.String(bandwidthTypeUpload) needsDelete = true } } if needsUpdate { - log.Printf("[DEBUG] Storage Gateway Gateway (%q) updating Bandwidth Rate Limit: %#v", d.Id(), updateInput) _, err := conn.UpdateBandwidthRateLimit(updateInput) + if err != nil { - return fmt.Errorf("error updating Bandwidth Rate Limit: %w", err) + return fmt.Errorf("error updating Storage Gateway Gateway (%s) bandwidth rate limit: %w", d.Id(), err) } } if needsDelete { - log.Printf("[DEBUG] Storage Gateway Gateway (%q) unsetting Bandwidth Rate Limit: %#v", d.Id(), deleteInput) _, err := conn.DeleteBandwidthRateLimit(deleteInput) + if err != nil { - return fmt.Errorf("error unsetting Bandwidth Rate Limit: %w", err) + return fmt.Errorf("error deleting Storage Gateway Gateway (%s) bandwidth rate limit: %w", d.Id(), err) } } + } + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { + return fmt.Errorf("error updating tags: %w", err) + } } return resourceGatewayRead(d, meta) From 52f5de9ef40506ad8e96387c45aa1ece4941a1fc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 11:42:34 -0400 Subject: [PATCH 22/29] r/aws_storagegateway_gateway: Minor tidy up of resource Create. --- internal/service/storagegateway/gateway.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index b811a8e0b2d..1d3c8a0c220 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -240,13 +240,10 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { region := meta.(*conns.AWSClient).Region activationKey := d.Get("activation_key").(string) - gatewayIpAddress := d.Get("gateway_ip_address").(string) - // Perform one time fetch of activation key from gateway IP address - if activationKey == "" { - if gatewayIpAddress == "" { - return fmt.Errorf("either activation_key or gateway_ip_address must be provided") - } + // Perform one time fetch of activation key from gateway IP address. + if v, ok := d.GetOk("gateway_ip_address"); ok { + gatewayIPAddress := v.(string) client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { @@ -255,7 +252,7 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { Timeout: time.Second * 10, } - requestURL := fmt.Sprintf("http://%s/?activationRegion=%s", gatewayIpAddress, region) + requestURL := fmt.Sprintf("http://%s/?activationRegion=%s", gatewayIPAddress, region) if v, ok := d.GetOk("gateway_vpc_endpoint"); ok { requestURL = fmt.Sprintf("%s&vpcEndpoint=%s", requestURL, v.(string)) } @@ -295,7 +292,7 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { response, err = client.Do(request) } if err != nil { - return fmt.Errorf("error retrieving activation key from IP Address (%s): %w", gatewayIpAddress, err) + return fmt.Errorf("error retrieving activation key from IP Address (%s): %w", gatewayIPAddress, err) } log.Printf("[DEBUG] Received HTTP response: %#v", response) @@ -310,7 +307,7 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { activationKey = redirectURL.Query().Get("activationKey") if activationKey == "" { - return fmt.Errorf("empty activationKey received from IP Address: %s", gatewayIpAddress) + return fmt.Errorf("empty activationKey received from IP Address: %s", gatewayIPAddress) } } @@ -720,7 +717,7 @@ func resourceGatewayDelete(d *schema.ResourceData, meta interface{}) error { GatewayARN: aws.String(d.Id()), }) - if operationErrorCode(err) == storagegateway.ErrorCodeGatewayNotFound { + if operationErrorCode(err) == operationErrCodeGatewayNotFound { return nil } From de6992e3b7df65e9dd43bf8c269e0bc41b5cc125 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 12:11:47 -0400 Subject: [PATCH 23/29] r/aws_storagegateway_gateway: Add and use 'FindGatewayByARN'. --- internal/service/storagegateway/errors.go | 6 +- internal/service/storagegateway/find.go | 26 ++++++ internal/service/storagegateway/gateway.go | 21 ++--- .../service/storagegateway/gateway_test.go | 80 +++++++++---------- 4 files changed, 74 insertions(+), 59 deletions(-) diff --git a/internal/service/storagegateway/errors.go b/internal/service/storagegateway/errors.go index 681015d158a..6aec78e3c60 100644 --- a/internal/service/storagegateway/errors.go +++ b/internal/service/storagegateway/errors.go @@ -7,11 +7,13 @@ import ( "github.com/aws/aws-sdk-go/service/storagegateway" ) -// Error code constants missing from AWS Go SDK: -// https://docs.aws.amazon.com/sdk-for-go/api/service/storagegateway/#pkg-constants +// Operation error code constants missing from AWS Go SDK: https://docs.aws.amazon.com/sdk-for-go/api/service/storagegateway/#pkg-constants. +// See https://docs.aws.amazon.com/storagegateway/latest/userguide/AWSStorageGatewayAPI.html#APIOperationErrorCodes for details. const ( operationErrCodeFileShareNotFound = "FileShareNotFound" operationErrCodeFileSystemAssociationNotFound = "FileSystemAssociationNotFound" + operationErrCodeGatewayNotConnected = "GatewayNotConnected" + operationErrCodeGatewayNotFound = "GatewayNotFound" ) // operationErrorCode returns the operation error code from the specified error: diff --git a/internal/service/storagegateway/find.go b/internal/service/storagegateway/find.go index e8421a0ec65..89d6a807175 100644 --- a/internal/service/storagegateway/find.go +++ b/internal/service/storagegateway/find.go @@ -3,6 +3,7 @@ package storagegateway import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/storagegateway" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -82,6 +83,31 @@ func FindUploadBufferDisk(conn *storagegateway.StorageGateway, gatewayARN string return result, err } +func FindGatewayByARN(conn *storagegateway.StorageGateway, arn string) (*storagegateway.DescribeGatewayInformationOutput, error) { + input := &storagegateway.DescribeGatewayInformationInput{ + GatewayARN: aws.String(arn), + } + + output, err := conn.DescribeGatewayInformation(input) + + if operationErrorCode(err) == operationErrCodeGatewayNotFound || tfawserr.ErrCodeEquals(err, storagegateway.ErrorCodeGatewayNotFound) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output, nil +} + func FindNFSFileShareByARN(conn *storagegateway.StorageGateway, arn string) (*storagegateway.NFSFileShareInfo, error) { input := &storagegateway.DescribeNFSFileSharesInput{ FileShareARNList: aws.StringSlice([]string{arn}), diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index 1d3c8a0c220..5c75d783f64 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -436,21 +436,16 @@ func resourceGatewayRead(d *schema.ResourceData, meta interface{}) error { defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig - input := &storagegateway.DescribeGatewayInformationInput{ - GatewayARN: aws.String(d.Id()), - } - - log.Printf("[DEBUG] Reading Storage Gateway Gateway: %s", input) + output, err := FindGatewayByARN(conn, d.Id()) - output, err := conn.DescribeGatewayInformation(input) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] Storage Gateway Gateway (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } if err != nil { - if IsErrGatewayNotFound(err) { - log.Printf("[WARN] Storage Gateway Gateway %q not found - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("error reading Storage Gateway Gateway: %w", err) + return fmt.Errorf("error reading Storage Gateway Gateway (%s): %w", d.Id(), err) } tags := KeyValueTags(output.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) @@ -717,7 +712,7 @@ func resourceGatewayDelete(d *schema.ResourceData, meta interface{}) error { GatewayARN: aws.String(d.Id()), }) - if operationErrorCode(err) == operationErrCodeGatewayNotFound { + if operationErrorCode(err) == operationErrCodeGatewayNotFound || tfawserr.ErrCodeEquals(err, storagegateway.ErrorCodeGatewayNotFound) { return nil } diff --git a/internal/service/storagegateway/gateway_test.go b/internal/service/storagegateway/gateway_test.go index e4bfa629a40..ed30b8fef8c 100644 --- a/internal/service/storagegateway/gateway_test.go +++ b/internal/service/storagegateway/gateway_test.go @@ -5,7 +5,6 @@ import ( "regexp" "testing" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/storagegateway" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -13,6 +12,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfstoragegateway "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccStorageGatewayGateway_GatewayType_cached(t *testing.T) { @@ -28,23 +28,23 @@ func TestAccStorageGatewayGateway_GatewayType_cached(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccGatewayConfig_GatewayType_Cached(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), + resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), resource.TestCheckResourceAttrSet(resourceName, "gateway_id"), resource.TestCheckResourceAttr(resourceName, "gateway_name", rName), + resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "CACHED"), + resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), resource.TestCheckResourceAttr(resourceName, "smb_security_strategy", ""), resource.TestCheckResourceAttr(resourceName, "tape_drive_type", ""), - resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), - resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), - resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), - resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), ), }, { @@ -70,22 +70,22 @@ func TestAccStorageGatewayGateway_GatewayType_fileFSxSMB(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccGatewayConfig_GatewayType_FileFSxSMB(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), + resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), resource.TestCheckResourceAttrSet(resourceName, "gateway_id"), resource.TestCheckResourceAttr(resourceName, "gateway_name", rName), + resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "FILE_FSX_SMB"), + resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), resource.TestCheckResourceAttr(resourceName, "tape_drive_type", ""), - resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), - resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), - resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), - resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), ), }, { @@ -111,22 +111,22 @@ func TestAccStorageGatewayGateway_GatewayType_fileS3(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccGatewayConfig_GatewayType_FileS3(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), + resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), resource.TestCheckResourceAttrSet(resourceName, "gateway_id"), resource.TestCheckResourceAttr(resourceName, "gateway_name", rName), + resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "FILE_S3"), + resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), resource.TestCheckResourceAttr(resourceName, "tape_drive_type", ""), - resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), - resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), - resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), - resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), ), }, { @@ -152,22 +152,22 @@ func TestAccStorageGatewayGateway_GatewayType_stored(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccGatewayConfig_GatewayType_Stored(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), + resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), resource.TestCheckResourceAttrSet(resourceName, "gateway_id"), resource.TestCheckResourceAttr(resourceName, "gateway_name", rName), + resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "STORED"), + resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), resource.TestCheckResourceAttr(resourceName, "tape_drive_type", ""), - resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), - resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), - resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), - resource.TestCheckResourceAttr(resourceName, "gateway_network_interface.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "gateway_network_interface.0.ipv4_address", "aws_instance.test", "private_ip"), ), }, { @@ -193,20 +193,20 @@ func TestAccStorageGatewayGateway_GatewayType_vtl(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccGatewayConfig_GatewayType_Vtl(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "storagegateway", regexp.MustCompile(`gateway/sgw-.+`)), + resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), + resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), resource.TestCheckResourceAttrSet(resourceName, "gateway_id"), resource.TestCheckResourceAttr(resourceName, "gateway_name", rName), resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "VTL"), + resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), resource.TestCheckResourceAttr(resourceName, "tape_drive_type", ""), - resource.TestCheckResourceAttrPair(resourceName, "ec2_instance_id", "aws_instance.test", "id"), - resource.TestCheckResourceAttr(resourceName, "endpoint_type", "STANDARD"), - resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), ), }, { @@ -795,18 +795,17 @@ func testAccCheckGatewayDestroy(s *terraform.State) error { continue } - input := &storagegateway.DescribeGatewayInformationInput{ - GatewayARN: aws.String(rs.Primary.ID), - } + _, err := tfstoragegateway.FindGatewayByARN(conn, rs.Primary.ID) - _, err := conn.DescribeGatewayInformation(input) + if tfresource.NotFound(err) { + continue + } if err != nil { - if tfstoragegateway.IsErrGatewayNotFound(err) { - return nil - } return err } + + return fmt.Errorf("Storage Gateway Gateway %s still exists", rs.Primary.ID) } return nil @@ -821,20 +820,13 @@ func testAccCheckGatewayExists(resourceName string, gateway *storagegateway.Desc } conn := acctest.Provider.Meta().(*conns.AWSClient).StorageGatewayConn - input := &storagegateway.DescribeGatewayInformationInput{ - GatewayARN: aws.String(rs.Primary.ID), - } - output, err := conn.DescribeGatewayInformation(input) + output, err := tfstoragegateway.FindGatewayByARN(conn, rs.Primary.ID) if err != nil { return err } - if output == nil { - return fmt.Errorf("Gateway %q does not exist", rs.Primary.ID) - } - *gateway = *output return nil From 92f19d8ec8656cdcd12b31614e6899e8d7581e93 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 13:07:42 -0400 Subject: [PATCH 24/29] r/aws_storagegateway_gateway: Add 'maintenance_start_time' argument. Acceptance test output: % make testacc TESTS=TestAccStorageGatewayGateway_GatewayType_stored PKG=storagegateway ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/storagegateway/... -v -count 1 -parallel 20 -run='TestAccStorageGatewayGateway_GatewayType_stored' -timeout 180m === RUN TestAccStorageGatewayGateway_GatewayType_stored === PAUSE TestAccStorageGatewayGateway_GatewayType_stored === CONT TestAccStorageGatewayGateway_GatewayType_stored --- PASS: TestAccStorageGatewayGateway_GatewayType_stored (219.24s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway 222.917s --- .changelog/15355.txt | 3 + internal/service/storagegateway/gateway.go | 104 ++++++++++++++++-- .../service/storagegateway/gateway_test.go | 5 + .../r/storagegateway_gateway.html.markdown | 8 ++ 4 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 .changelog/15355.txt diff --git a/.changelog/15355.txt b/.changelog/15355.txt new file mode 100644 index 00000000000..8d7738c0410 --- /dev/null +++ b/.changelog/15355.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_storagegateway_gateway: Add `maintenance_start_time` argument +``` \ No newline at end of file diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index 5c75d783f64..4d1c2ea336c 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -129,6 +129,36 @@ func ResourceGateway() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "maintenance_start_time": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "day_of_week": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 6), + }, + "day_of_month": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 28), + }, + "hour_of_day": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 23), + }, + "minute_of_hour": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 59), + }, + }, + }, + }, "medium_changer_type": { Type: schema.TypeString, Optional: true, @@ -356,6 +386,25 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { } } + if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 { + tfMap := v.([]interface{})[0].(map[string]interface{}) + + input := &storagegateway.UpdateMaintenanceStartTimeInput{ + DayOfMonth: aws.Int64(int64(tfMap["day_of_month"].(int))), + DayOfWeek: aws.Int64(int64(tfMap["day_of_week"].(int))), + GatewayARN: aws.String(d.Id()), + HourOfDay: aws.Int64(int64(tfMap["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(tfMap["minute_of_hour"].(int))), + } + + log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) + _, err := conn.UpdateMaintenanceStartTime(input) + + if err != nil { + return fmt.Errorf("error updating maintenance start time: %w", err) + } + } + if v, ok := d.GetOk("smb_active_directory_settings"); ok && len(v.([]interface{})) > 0 { input := expandStorageGatewayGatewayDomain(v.([]interface{}), d.Id()) log.Printf("[DEBUG] Storage Gateway Gateway %q joining Active Directory domain: %s", d.Id(), aws.StringValue(input.DomainName)) @@ -555,21 +604,44 @@ func resourceGatewayRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting gateway_network_interface: %w", err) } - bandwidthInput := &storagegateway.DescribeBandwidthRateLimitInput{ + bandwidthOutput, err := conn.DescribeBandwidthRateLimit(&storagegateway.DescribeBandwidthRateLimitInput{ GatewayARN: aws.String(d.Id()), + }) + if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") || + tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "This operation is not valid for the specified gateway") { + err = nil + } + if err != nil { + return fmt.Errorf("error reading Storage Gateway Bandwidth rate limit: %w", err) + } + if bandwidthOutput != nil { + d.Set("average_download_rate_limit_in_bits_per_sec", bandwidthOutput.AverageDownloadRateLimitInBitsPerSec) + d.Set("average_upload_rate_limit_in_bits_per_sec", bandwidthOutput.AverageUploadRateLimitInBitsPerSec) } - log.Printf("[DEBUG] Reading Storage Gateway Bandwidth rate limit: %s", bandwidthInput) - bandwidthOutput, err := conn.DescribeBandwidthRateLimit(bandwidthInput) + maintenanceStartTimeOutput, err := conn.DescribeMaintenanceStartTime(&storagegateway.DescribeMaintenanceStartTimeInput{ + GatewayARN: aws.String(d.Id()), + }) if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") || tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "This operation is not valid for the specified gateway") { - return nil + err = nil } if err != nil { - return fmt.Errorf("error reading Storage Gateway Bandwidth rate limit: %w", err) + return fmt.Errorf("error reading Storage Gateway maintenance start time: %w", err) + } + if maintenanceStartTimeOutput != nil { + tfMap := map[string]interface{}{ + "day_of_month": aws.Int64Value(maintenanceStartTimeOutput.DayOfMonth), + "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), + "hour_of_day": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), + "minute_of_hour": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), + } + + if err := d.Set("maintenance_start_time", []map[string]interface{}{tfMap}); err != nil { + return fmt.Errorf("error setting maintenance_start_time: %w", err) + } } - d.Set("average_download_rate_limit_in_bits_per_sec", bandwidthOutput.AverageDownloadRateLimitInBitsPerSec) - d.Set("average_upload_rate_limit_in_bits_per_sec", bandwidthOutput.AverageUploadRateLimitInBitsPerSec) + return nil } @@ -592,6 +664,24 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { } } + if d.HasChange("maintenance_start_time") { + tfMap := d.Get("maintenance_start_time").([]interface{})[0].(map[string]interface{}) + + input := &storagegateway.UpdateMaintenanceStartTimeInput{ + DayOfMonth: aws.Int64(int64(tfMap["day_of_month"].(int))), + DayOfWeek: aws.Int64(int64(tfMap["day_of_week"].(int))), + GatewayARN: aws.String(d.Id()), + HourOfDay: aws.Int64(int64(tfMap["hour_of_day"].(int))), + MinuteOfHour: aws.Int64(int64(tfMap["minute_of_month"].(int))), + } + + _, err := conn.UpdateMaintenanceStartTime(input) + + if err != nil { + return fmt.Errorf("error updating Storage Gateway Gateway (%s) maintenance start time: %w", d.Id(), err) + } + } + if d.HasChange("smb_active_directory_settings") { input := expandStorageGatewayGatewayDomain(d.Get("smb_active_directory_settings").([]interface{}), d.Id()) domainName := aws.StringValue(input.DomainName) diff --git a/internal/service/storagegateway/gateway_test.go b/internal/service/storagegateway/gateway_test.go index ed30b8fef8c..51755ac9249 100644 --- a/internal/service/storagegateway/gateway_test.go +++ b/internal/service/storagegateway/gateway_test.go @@ -40,6 +40,7 @@ func TestAccStorageGatewayGateway_GatewayType_cached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "CACHED"), resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), @@ -82,6 +83,7 @@ func TestAccStorageGatewayGateway_GatewayType_fileFSxSMB(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "FILE_FSX_SMB"), resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), @@ -123,6 +125,7 @@ func TestAccStorageGatewayGateway_GatewayType_fileS3(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "FILE_S3"), resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), @@ -164,6 +167,7 @@ func TestAccStorageGatewayGateway_GatewayType_stored(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "STORED"), resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), @@ -203,6 +207,7 @@ func TestAccStorageGatewayGateway_GatewayType_vtl(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "gateway_timezone", "GMT"), resource.TestCheckResourceAttr(resourceName, "gateway_type", "VTL"), resource.TestCheckResourceAttr(resourceName, "host_environment", "EC2"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "medium_changer_type", ""), resource.TestCheckResourceAttr(resourceName, "smb_active_directory_settings.#", "0"), resource.TestCheckResourceAttr(resourceName, "smb_guest_password", ""), diff --git a/website/docs/r/storagegateway_gateway.html.markdown b/website/docs/r/storagegateway_gateway.html.markdown index 86b87ee80c4..40c2fdbc969 100644 --- a/website/docs/r/storagegateway_gateway.html.markdown +++ b/website/docs/r/storagegateway_gateway.html.markdown @@ -113,6 +113,7 @@ The following arguments are supported: * `gateway_type` - (Optional) Type of the gateway. The default value is `STORED`. Valid values: `CACHED`, `FILE_FSX_SMB`, `FILE_S3`, `STORED`, `VTL`. * `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). * `cloudwatch_log_group_arn` - (Optional) The Amazon Resource Name (ARN) of the Amazon CloudWatch log group to use to monitor and log events in the gateway. +* `maintenance_start_time` - (Optional) The gateway's weekly maintenance start time information, including day and time of the week. The maintenance time is the time in your gateway's time zone. More details below. * `medium_changer_type` - (Optional) Type of medium changer to use for tape gateway. Terraform cannot detect drift of this argument. Valid values: `STK-L700`, `AWS-Gateway-VTL`, `IBM-03584L32-0402`. * `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` and `FILE_FSX_SMB` gateway types. 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` and `FILE_FSX_SMB` gateway types. 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. @@ -121,6 +122,13 @@ The following arguments are supported: * `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. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. +### maintenance_start_time + +* `day_of_month` - (Optional) The day of the month component of the maintenance start time represented as an ordinal number from 1 to 28, where 1 represents the first day of the month and 28 represents the last day of the month. +* `day_of_week` - (Optional) The day of the week component of the maintenance start time week represented as an ordinal number from 0 to 6, where 0 represents Sunday and 6 Saturday. +* `hour_of_day` - (Required) The hour component of the maintenance start time represented as _hh_, where _hh_ is the hour (00 to 23). The hour of the day is in the time zone of the gateway. +* `minute_of_hour` - (Required) The minute component of the maintenance start time represented as _mm_, where _mm_ is the minute (00 to 59). The minute of the hour is in the time zone of the gateway. + ### smb_active_directory_settings Information to join the gateway to an Active Directory domain for Server Message Block (SMB) file shares. From c9963d908aeb87b0f86eab5f89700252df75e7cb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 14:03:26 -0400 Subject: [PATCH 25/29] Add 'TestAccStorageGatewayGateway_maintenanceStartTime'. --- .../service/storagegateway/gateway_test.go | 165 ++++++++++++------ 1 file changed, 115 insertions(+), 50 deletions(-) diff --git a/internal/service/storagegateway/gateway_test.go b/internal/service/storagegateway/gateway_test.go index 51755ac9249..d79b09d1877 100644 --- a/internal/service/storagegateway/gateway_test.go +++ b/internal/service/storagegateway/gateway_test.go @@ -792,6 +792,48 @@ func TestAccStorageGatewayGateway_bandwidthAll(t *testing.T) { }) } +func TestAccStorageGatewayGateway_maintenanceStartTime(t *testing.T) { + var gateway storagegateway.DescribeGatewayInformationOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_storagegateway_gateway.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, storagegateway.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGatewayMaintenanceStartTimeConfig(rName, 22, 0, 3, 0), + Check: resource.ComposeTestCheckFunc( + testAccCheckGatewayExists(resourceName, &gateway), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour_of_day", "22"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute_of_hour", "0"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "3"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_month", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"}, + }, + { + Config: testAccGatewayMaintenanceStartTimeConfig(rName, 21, 10, 0, 12), + Check: resource.ComposeTestCheckFunc( + testAccCheckGatewayExists(resourceName, &gateway), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour_of_day", "21"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute_of_hour", "10"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "0"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_month", "12"), + ), + }, + }, + }) +} + func testAccCheckGatewayDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).StorageGatewayConn @@ -841,8 +883,7 @@ func testAccCheckGatewayExists(resourceName string, gateway *storagegateway.Desc // testAcc_VPCBase provides a publicly accessible subnet // and security group, suitable for Storage Gateway EC2 instances of any type func testAcc_VPCBase(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), - fmt.Sprintf(` + return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -876,6 +917,7 @@ resource "aws_route" "test" { } resource "aws_security_group" "test" { + name = %[1]q vpc_id = aws_vpc.test.id egress { @@ -955,40 +997,40 @@ resource "aws_instance" "test" { } func testAccGatewayConfig_GatewayType_Cached(rName string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "CACHED" } -`, rName) +`, rName)) } func testAccGatewayConfig_GatewayType_FileFSxSMB(rName string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "FILE_FSX_SMB" } -`, rName) +`, rName)) } func testAccGatewayConfig_GatewayType_FileS3(rName string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "FILE_S3" } -`, rName) +`, rName)) } func testAccGatewayConfig_Log_Group(rName string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_cloudwatch_log_group" "test" { name = %[1]q } @@ -1000,44 +1042,44 @@ resource "aws_storagegateway_gateway" "test" { gateway_type = "FILE_S3" cloudwatch_log_group_arn = aws_cloudwatch_log_group.test.arn } -`, rName) +`, rName)) } func testAccGatewayConfig_GatewayType_Stored(rName string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "STORED" } -`, rName) +`, rName)) } func testAccGatewayConfig_GatewayType_Vtl(rName string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "VTL" } -`, rName) +`, rName)) } func testAccGatewayConfig_GatewayTimezone(rName, gatewayTimezone string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q - gateway_timezone = %q + gateway_name = %[1]q + gateway_timezone = %[2]q gateway_type = "FILE_S3" } -`, rName, gatewayTimezone) +`, rName, gatewayTimezone)) } func testAccGatewayConfig_GatewayVPCEndpoint(rName string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` data "aws_vpc_endpoint_service" "storagegateway" { service = "storagegateway" } @@ -1048,6 +1090,10 @@ resource "aws_vpc_endpoint" "test" { subnet_ids = [aws_subnet.test.id] vpc_endpoint_type = data.aws_vpc_endpoint_service.storagegateway.service_type vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } } resource "aws_storagegateway_gateway" "test" { @@ -1057,7 +1103,7 @@ resource "aws_storagegateway_gateway" "test" { gateway_type = "CACHED" gateway_vpc_endpoint = aws_vpc_endpoint.test.dns_entry[0].dns_name } -`, rName) +`, rName)) } func testAccGatewayConfig_DirectoryServiceSimpleDirectory(rName, domainName string) string { @@ -1143,6 +1189,7 @@ resource "aws_route" "test" { } resource "aws_security_group" "test" { + name = %[1]q vpc_id = aws_vpc.test.id egress { @@ -1282,31 +1329,31 @@ resource "aws_storagegateway_gateway" "test" { } func testAccGatewayConfig_SMBGuestPassword(rName, smbGuestPassword string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "FILE_S3" - smb_guest_password = %q + smb_guest_password = %[2]q } -`, rName, smbGuestPassword) +`, rName, smbGuestPassword)) } func testAccGatewaySMBSecurityStrategyConfig(rName, strategy string) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "FILE_S3" - smb_security_strategy = %q + smb_security_strategy = %[2]q } -`, rName, strategy) +`, rName, strategy)) } func testAccGatewaySMBVisibilityConfig(rName string, visible bool) string { - return testAcc_FileGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_FileGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip gateway_name = %[1]q @@ -1314,42 +1361,42 @@ resource "aws_storagegateway_gateway" "test" { gateway_type = "FILE_S3" smb_file_share_visibility = %[2]t } -`, rName, visible) +`, rName, visible)) } func testAccGatewayTags1Config(rName, tagKey1, tagValue1 string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "CACHED" tags = { - %q = %q + %[2]q = %[3]q } } -`, rName, tagKey1, tagValue1) +`, rName, tagKey1, tagValue1)) } func testAccGatewayTags2Config(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip - gateway_name = %q + gateway_name = %[1]q gateway_timezone = "GMT" gateway_type = "CACHED" tags = { - %q = %q - %q = %q + %[2]q = %[3]q + %[4]q = %[5]q } } -`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +`, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } func testAccGatewayBandwidthUploadConfig(rName string, rate int) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip gateway_name = %[1]q @@ -1357,11 +1404,11 @@ resource "aws_storagegateway_gateway" "test" { gateway_type = "CACHED" average_upload_rate_limit_in_bits_per_sec = %[2]d } -`, rName, rate) +`, rName, rate)) } func testAccGatewayBandwidthDownloadConfig(rName string, rate int) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip gateway_name = %[1]q @@ -1369,11 +1416,11 @@ resource "aws_storagegateway_gateway" "test" { gateway_type = "CACHED" average_download_rate_limit_in_bits_per_sec = %[2]d } -`, rName, rate) +`, rName, rate)) } func testAccGatewayBandwidthAllConfig(rName string, rate int) string { - return testAcc_TapeAndVolumeGatewayBase(rName) + fmt.Sprintf(` + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip gateway_name = %[1]q @@ -1382,5 +1429,23 @@ resource "aws_storagegateway_gateway" "test" { average_upload_rate_limit_in_bits_per_sec = %[2]d average_download_rate_limit_in_bits_per_sec = %[2]d } -`, rName, rate) +`, rName, rate)) +} + +func testAccGatewayMaintenanceStartTimeConfig(rName string, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth int) string { + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(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 = "CACHED" + + maintenance_start_time { + hour_of_day = %[2]d + minute_of_hour = %[3]d + day_of_week = %[4]d + day_of_month = %[5]d + } +} +`, rName, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth)) } From 6c2e7db00985c0d440916f9484cbf42e1d4677c6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 14:05:10 -0400 Subject: [PATCH 26/29] Revert "Fix gofmt error" This reverts commit 2dee622c0dc3508616ae8bca60ba565b6923dfb7. --- internal/service/storagegateway/nfs_file_share.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/storagegateway/nfs_file_share.go b/internal/service/storagegateway/nfs_file_share.go index 32d0428ed10..d8a0aa59173 100644 --- a/internal/service/storagegateway/nfs_file_share.go +++ b/internal/service/storagegateway/nfs_file_share.go @@ -247,7 +247,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("audit_destination_arn"); ok { input.AuditDestinationARN = aws.String(v.(string)) } - + if v, ok := d.GetOk("bucket_region"); ok { input.BucketRegion = aws.String(v.(string)) } @@ -263,7 +263,7 @@ func resourceNFSFileShareCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("file_share_name"); ok { input.FileShareName = aws.String(v.(string)) } - + if v, ok := d.GetOk("vpc_endpoint_dns_name"); ok { input.VPCEndpointDNSName = aws.String(v.(string)) } From 748ac26fe16bd41b06faeb35276336f772f01385 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Apr 2022 14:21:17 -0400 Subject: [PATCH 27/29] Pass 'null' for missing 'day_of_week' or 'day_of_month' values. --- internal/service/storagegateway/gateway_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/service/storagegateway/gateway_test.go b/internal/service/storagegateway/gateway_test.go index d79b09d1877..8b1311fbd14 100644 --- a/internal/service/storagegateway/gateway_test.go +++ b/internal/service/storagegateway/gateway_test.go @@ -3,6 +3,7 @@ package storagegateway_test import ( "fmt" "regexp" + "strconv" "testing" "github.com/aws/aws-sdk-go/service/storagegateway" @@ -1433,6 +1434,14 @@ resource "aws_storagegateway_gateway" "test" { } func testAccGatewayMaintenanceStartTimeConfig(rName string, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth int) string { + nullOrValue := func(v int) string { + if v == 0 { + return "null" + } + + return strconv.Quote(strconv.Itoa(v)) + } + return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` resource "aws_storagegateway_gateway" "test" { gateway_ip_address = aws_instance.test.public_ip @@ -1443,9 +1452,9 @@ resource "aws_storagegateway_gateway" "test" { maintenance_start_time { hour_of_day = %[2]d minute_of_hour = %[3]d - day_of_week = %[4]d - day_of_month = %[5]d + day_of_week = %[4]s + day_of_month = %[5]s } } -`, rName, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth)) +`, rName, hourOfDay, minuteOfHour, nullOrValue(dayOfWeek), nullOrValue(dayOfMonth))) } From ac56cd8df4b9469f0145728b868b3d2c51f312ae Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 7 Apr 2022 10:52:44 -0400 Subject: [PATCH 28/29] Fix golangci-lint errors. --- internal/service/storagegateway/errors.go | 1 - internal/service/storagegateway/status.go | 1 - internal/service/storagegateway/wait.go | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/service/storagegateway/errors.go b/internal/service/storagegateway/errors.go index 6aec78e3c60..24e2078db69 100644 --- a/internal/service/storagegateway/errors.go +++ b/internal/service/storagegateway/errors.go @@ -12,7 +12,6 @@ import ( const ( operationErrCodeFileShareNotFound = "FileShareNotFound" operationErrCodeFileSystemAssociationNotFound = "FileSystemAssociationNotFound" - operationErrCodeGatewayNotConnected = "GatewayNotConnected" operationErrCodeGatewayNotFound = "GatewayNotFound" ) diff --git a/internal/service/storagegateway/status.go b/internal/service/storagegateway/status.go index 72a51f641e5..0a2f24e06a1 100644 --- a/internal/service/storagegateway/status.go +++ b/internal/service/storagegateway/status.go @@ -11,7 +11,6 @@ import ( const ( storageGatewayGatewayStatusConnected = "GatewayConnected" storediSCSIVolumeStatusNotFound = "NotFound" - nfsFileShareStatusNotFound = "NotFound" ) func statusStorageGatewayGateway(conn *storagegateway.StorageGateway, gatewayARN string) resource.StateRefreshFunc { diff --git a/internal/service/storagegateway/wait.go b/internal/service/storagegateway/wait.go index 7e9b2dd586e..515376c5059 100644 --- a/internal/service/storagegateway/wait.go +++ b/internal/service/storagegateway/wait.go @@ -75,7 +75,7 @@ func waitStorediSCSIVolumeAvailable(conn *storagegateway.StorageGateway, volumeA return nil, err } -func waitNFSFileShareCreated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { //nolint:unparam +func waitNFSFileShareCreated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusCreating}, Target: []string{fileShareStatusAvailable}, @@ -112,7 +112,7 @@ func waitNFSFileShareDeleted(conn *storagegateway.StorageGateway, arn string, ti return nil, err } -func waitNFSFileShareUpdated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { //nolint:unparam +func waitNFSFileShareUpdated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) { stateConf := &resource.StateChangeConf{ Pending: []string{fileShareStatusUpdating}, Target: []string{fileShareStatusAvailable}, From 06216661ccff2633589669096d62471af82f7363 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 7 Apr 2022 12:19:56 -0400 Subject: [PATCH 29/29] r/aws_storagegateway_gateway: Make 'maintenance_start_time.day_of_month' and 'maintenance_start_time.day_of_week' nullable. Acceptance test output: % make testacc TESTS=TestAccStorageGatewayGateway_maintenanceStartTime PKG=storagegateway ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/storagegateway/... -v -count 1 -parallel 20 -run='TestAccStorageGatewayGateway_maintenanceStartTime' -timeout 180m === RUN TestAccStorageGatewayGateway_maintenanceStartTime === PAUSE TestAccStorageGatewayGateway_maintenanceStartTime === CONT TestAccStorageGatewayGateway_maintenanceStartTime --- PASS: TestAccStorageGatewayGateway_maintenanceStartTime (221.15s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway 227.231s --- internal/service/storagegateway/gateway.go | 118 +++++++++++++----- .../service/storagegateway/gateway_test.go | 23 ++-- 2 files changed, 95 insertions(+), 46 deletions(-) diff --git a/internal/service/storagegateway/gateway.go b/internal/service/storagegateway/gateway.go index 4d1c2ea336c..3f1fd3642d4 100644 --- a/internal/service/storagegateway/gateway.go +++ b/internal/service/storagegateway/gateway.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "regexp" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -17,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/experimental/nullable" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -137,14 +139,14 @@ func ResourceGateway() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "day_of_week": { - Type: schema.TypeInt, + Type: nullable.TypeNullableInt, Optional: true, - ValidateFunc: validation.IntBetween(0, 6), + ValidateFunc: nullable.ValidateTypeStringNullableIntBetween(0, 6), }, "day_of_month": { - Type: schema.TypeInt, + Type: nullable.TypeNullableInt, Optional: true, - ValidateFunc: validation.IntBetween(1, 28), + ValidateFunc: nullable.ValidateTypeStringNullableIntBetween(1, 28), }, "hour_of_day": { Type: schema.TypeInt, @@ -386,16 +388,9 @@ func resourceGatewayCreate(d *schema.ResourceData, meta interface{}) error { } } - if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 { - tfMap := v.([]interface{})[0].(map[string]interface{}) - - input := &storagegateway.UpdateMaintenanceStartTimeInput{ - DayOfMonth: aws.Int64(int64(tfMap["day_of_month"].(int))), - DayOfWeek: aws.Int64(int64(tfMap["day_of_week"].(int))), - GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(tfMap["hour_of_day"].(int))), - MinuteOfHour: aws.Int64(int64(tfMap["minute_of_hour"].(int))), - } + if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input := expandUpdateMaintenanceStartTimeInput(v.([]interface{})[0].(map[string]interface{})) + input.GatewayARN = aws.String(d.Id()) log.Printf("[DEBUG] Storage Gateway Gateway %q updating maintenance start time", d.Id()) _, err := conn.UpdateMaintenanceStartTime(input) @@ -607,13 +602,16 @@ func resourceGatewayRead(d *schema.ResourceData, meta interface{}) error { bandwidthOutput, err := conn.DescribeBandwidthRateLimit(&storagegateway.DescribeBandwidthRateLimitInput{ GatewayARN: aws.String(d.Id()), }) + if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") || tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "This operation is not valid for the specified gateway") { err = nil } + if err != nil { return fmt.Errorf("error reading Storage Gateway Bandwidth rate limit: %w", err) } + if bandwidthOutput != nil { d.Set("average_download_rate_limit_in_bits_per_sec", bandwidthOutput.AverageDownloadRateLimitInBitsPerSec) d.Set("average_upload_rate_limit_in_bits_per_sec", bandwidthOutput.AverageUploadRateLimitInBitsPerSec) @@ -622,24 +620,22 @@ func resourceGatewayRead(d *schema.ResourceData, meta interface{}) error { maintenanceStartTimeOutput, err := conn.DescribeMaintenanceStartTime(&storagegateway.DescribeMaintenanceStartTimeInput{ GatewayARN: aws.String(d.Id()), }) + if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified operation is not supported") || tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "This operation is not valid for the specified gateway") { err = nil } + if err != nil { return fmt.Errorf("error reading Storage Gateway maintenance start time: %w", err) } - if maintenanceStartTimeOutput != nil { - tfMap := map[string]interface{}{ - "day_of_month": aws.Int64Value(maintenanceStartTimeOutput.DayOfMonth), - "day_of_week": aws.Int64Value(maintenanceStartTimeOutput.DayOfWeek), - "hour_of_day": aws.Int64Value(maintenanceStartTimeOutput.HourOfDay), - "minute_of_hour": aws.Int64Value(maintenanceStartTimeOutput.MinuteOfHour), - } - if err := d.Set("maintenance_start_time", []map[string]interface{}{tfMap}); err != nil { + if maintenanceStartTimeOutput != nil { + if err := d.Set("maintenance_start_time", []map[string]interface{}{flattenDescribeMaintenanceStartTimeOutput(maintenanceStartTimeOutput)}); err != nil { return fmt.Errorf("error setting maintenance_start_time: %w", err) } + } else { + d.Set("maintenance_start_time", nil) } return nil @@ -665,20 +661,16 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("maintenance_start_time") { - tfMap := d.Get("maintenance_start_time").([]interface{})[0].(map[string]interface{}) - - input := &storagegateway.UpdateMaintenanceStartTimeInput{ - DayOfMonth: aws.Int64(int64(tfMap["day_of_month"].(int))), - DayOfWeek: aws.Int64(int64(tfMap["day_of_week"].(int))), - GatewayARN: aws.String(d.Id()), - HourOfDay: aws.Int64(int64(tfMap["hour_of_day"].(int))), - MinuteOfHour: aws.Int64(int64(tfMap["minute_of_month"].(int))), - } + if v, ok := d.GetOk("maintenance_start_time"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input := expandUpdateMaintenanceStartTimeInput(v.([]interface{})[0].(map[string]interface{})) + input.GatewayARN = aws.String(d.Id()) - _, err := conn.UpdateMaintenanceStartTime(input) + log.Printf("[DEBUG] Updating Storage Gateway maintenance start time: %s", input) + _, err := conn.UpdateMaintenanceStartTime(input) - if err != nil { - return fmt.Errorf("error updating Storage Gateway Gateway (%s) maintenance start time: %w", d.Id(), err) + if err != nil { + return fmt.Errorf("error updating Storage Gateway Gateway (%s) maintenance start time: %w", d.Id(), err) + } } } @@ -686,6 +678,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { input := expandStorageGatewayGatewayDomain(d.Get("smb_active_directory_settings").([]interface{}), d.Id()) domainName := aws.StringValue(input.DomainName) + log.Printf("[DEBUG] Joining Storage Gateway to Active Directory domain: %s", input) _, err := conn.JoinDomain(input) if err != nil { @@ -703,6 +696,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { Password: aws.String(d.Get("smb_guest_password").(string)), } + log.Printf("[DEBUG] Setting Storage Gateway SMB guest password: %s", input) _, err := conn.SetSMBGuestPassword(input) if err != nil { @@ -716,6 +710,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { SMBSecurityStrategy: aws.String(d.Get("smb_security_strategy").(string)), } + log.Printf("[DEBUG] Updating Storage Gateway SMB security strategy: %s", input) _, err := conn.UpdateSMBSecurityStrategy(input) if err != nil { @@ -729,6 +724,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { GatewayARN: aws.String(d.Id()), } + log.Printf("[DEBUG] Updating Storage Gateway SMB file share visibility: %s", input) _, err := conn.UpdateSMBFileShareVisibility(input) if err != nil { @@ -767,6 +763,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { } if needsUpdate { + log.Printf("[DEBUG] Updating Storage Gateway bandwidth rate limit: %s", updateInput) _, err := conn.UpdateBandwidthRateLimit(updateInput) if err != nil { @@ -775,6 +772,7 @@ func resourceGatewayUpdate(d *schema.ResourceData, meta interface{}) error { } if needsDelete { + log.Printf("[DEBUG] Deleting Storage Gateway bandwidth rate limit: %s", deleteInput) _, err := conn.DeleteBandwidthRateLimit(deleteInput) if err != nil { @@ -864,6 +862,58 @@ func flattenStorageGatewayGatewayNetworkInterfaces(nis []*storagegateway.Network return tfList } +func expandUpdateMaintenanceStartTimeInput(tfMap map[string]interface{}) *storagegateway.UpdateMaintenanceStartTimeInput { + if tfMap == nil { + return nil + } + + apiObject := &storagegateway.UpdateMaintenanceStartTimeInput{} + + if v, null, _ := nullable.Int(tfMap["day_of_month"].(string)).Value(); !null && v > 0 { + apiObject.DayOfMonth = aws.Int64(v) + } + + if v, null, _ := nullable.Int(tfMap["day_of_week"].(string)).Value(); !null && v > 0 { + apiObject.DayOfWeek = aws.Int64(v) + } + + if v, ok := tfMap["hour_of_day"].(int); ok { + apiObject.HourOfDay = aws.Int64(int64(v)) + } + + if v, ok := tfMap["minute_of_hour"].(int); ok { + apiObject.MinuteOfHour = aws.Int64(int64(v)) + } + + return apiObject +} + +func flattenDescribeMaintenanceStartTimeOutput(apiObject *storagegateway.DescribeMaintenanceStartTimeOutput) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{} + + if v := apiObject.DayOfMonth; v != nil { + tfMap["day_of_month"] = strconv.FormatInt(aws.Int64Value(v), 10) + } + + if v := apiObject.DayOfWeek; v != nil { + tfMap["day_of_week"] = strconv.FormatInt(aws.Int64Value(v), 10) + } + + if v := apiObject.HourOfDay; v != nil { + tfMap["hour_of_day"] = aws.Int64Value(v) + } + + if v := apiObject.MinuteOfHour; v != nil { + tfMap["minute_of_hour"] = aws.Int64Value(v) + } + + return tfMap +} + // The API returns multiple responses for a missing gateway func IsErrGatewayNotFound(err error) bool { if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified gateway was not found.") { diff --git a/internal/service/storagegateway/gateway_test.go b/internal/service/storagegateway/gateway_test.go index 8b1311fbd14..337137f0e7b 100644 --- a/internal/service/storagegateway/gateway_test.go +++ b/internal/service/storagegateway/gateway_test.go @@ -805,14 +805,14 @@ func TestAccStorageGatewayGateway_maintenanceStartTime(t *testing.T) { CheckDestroy: testAccCheckGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccGatewayMaintenanceStartTimeConfig(rName, 22, 0, 3, 0), + Config: testAccGatewayMaintenanceStartTimeConfig(rName, 22, 0, "3", ""), Check: resource.ComposeTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.#", "1"), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour_of_day", "22"), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute_of_hour", "0"), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "3"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_month", "0"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_month", ""), ), }, { @@ -822,12 +822,12 @@ func TestAccStorageGatewayGateway_maintenanceStartTime(t *testing.T) { ImportStateVerifyIgnore: []string{"activation_key", "gateway_ip_address"}, }, { - Config: testAccGatewayMaintenanceStartTimeConfig(rName, 21, 10, 0, 12), + Config: testAccGatewayMaintenanceStartTimeConfig(rName, 21, 10, "", "12"), Check: resource.ComposeTestCheckFunc( testAccCheckGatewayExists(resourceName, &gateway), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.hour_of_day", "21"), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.minute_of_hour", "10"), - resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", "0"), + resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_week", ""), resource.TestCheckResourceAttr(resourceName, "maintenance_start_time.0.day_of_month", "12"), ), }, @@ -1433,13 +1433,12 @@ resource "aws_storagegateway_gateway" "test" { `, rName, rate)) } -func testAccGatewayMaintenanceStartTimeConfig(rName string, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth int) string { - nullOrValue := func(v int) string { - if v == 0 { - return "null" - } - - return strconv.Quote(strconv.Itoa(v)) +func testAccGatewayMaintenanceStartTimeConfig(rName string, hourOfDay, minuteOfHour int, dayOfWeek, dayOfMonth string) string { + if dayOfWeek == "" { + dayOfWeek = strconv.Quote(dayOfWeek) + } + if dayOfMonth == "" { + dayOfMonth = strconv.Quote(dayOfMonth) } return acctest.ConfigCompose(testAcc_TapeAndVolumeGatewayBase(rName), fmt.Sprintf(` @@ -1456,5 +1455,5 @@ resource "aws_storagegateway_gateway" "test" { day_of_month = %[5]s } } -`, rName, hourOfDay, minuteOfHour, nullOrValue(dayOfWeek), nullOrValue(dayOfMonth))) +`, rName, hourOfDay, minuteOfHour, dayOfWeek, dayOfMonth)) }