From b90ab2aef1e7bc005a0f5ad533803d34326e50ef Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 20 Aug 2021 20:41:35 +0300 Subject: [PATCH 1/6] mv fsx common functions to internal package + poc --- aws/internal/service/fsx/finder/finder.go | 40 +++++++++++ aws/internal/service/fsx/waiter/status.go | 42 +++++++++++ aws/internal/service/fsx/waiter/waiter.go | 69 +++++++++++++++++++ aws/resource_aws_fsx_backup.go | 2 +- aws/resource_aws_fsx_lustre_file_system.go | 34 ++++----- ...esource_aws_fsx_lustre_file_system_test.go | 14 ++-- 6 files changed, 171 insertions(+), 30 deletions(-) diff --git a/aws/internal/service/fsx/finder/finder.go b/aws/internal/service/fsx/finder/finder.go index c74a509b431..96782578302 100644 --- a/aws/internal/service/fsx/finder/finder.go +++ b/aws/internal/service/fsx/finder/finder.go @@ -34,3 +34,43 @@ func BackupByID(conn *fsx.FSx, id string) (*fsx.Backup, error) { return output.Backups[0], nil } + +func FileSystemByID(conn *fsx.FSx, id string) (*fsx.FileSystem, error) { + input := &fsx.DescribeFileSystemsInput{ + FileSystemIds: []*string{aws.String(id)}, + } + + var filesystems []*fsx.FileSystem + + err := conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool { + for _, fs := range page.FileSystems { + if fs == nil { + continue + } + + filesystems = append(filesystems, fs) + } + + return !lastPage + }) + + if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if filesystems == nil || filesystems[0] == nil { + return nil, &resource.NotFoundError{ + Message: "Empty result", + LastRequest: input, + } + } + + return filesystems[0], nil +} diff --git a/aws/internal/service/fsx/waiter/status.go b/aws/internal/service/fsx/waiter/status.go index eaaa05bc09e..339eb669d20 100644 --- a/aws/internal/service/fsx/waiter/status.go +++ b/aws/internal/service/fsx/waiter/status.go @@ -23,3 +23,45 @@ func BackupStatus(conn *fsx.FSx, id string) resource.StateRefreshFunc { return output, aws.StringValue(output.Lifecycle), nil } } + +func FileSystemStatus(conn *fsx.FSx, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := finder.FileSystemByID(conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, aws.StringValue(output.Lifecycle), nil + } +} + +func FileSystemAdministrativeActionsStatus(conn *fsx.FSx, id, action string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := finder.FileSystemByID(conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + for _, administrativeAction := range output.AdministrativeActions { + if administrativeAction == nil { + continue + } + + if aws.StringValue(administrativeAction.AdministrativeActionType) == action { + return output, aws.StringValue(administrativeAction.Status), nil + } + } + + return output, fsx.StatusCompleted, nil + } +} diff --git a/aws/internal/service/fsx/waiter/waiter.go b/aws/internal/service/fsx/waiter/waiter.go index 4edfce96421..6657affc87f 100644 --- a/aws/internal/service/fsx/waiter/waiter.go +++ b/aws/internal/service/fsx/waiter/waiter.go @@ -1,10 +1,13 @@ package waiter import ( + "errors" "time" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/fsx" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) const ( @@ -45,3 +48,69 @@ func BackupDeleted(conn *fsx.FSx, id string) (*fsx.Backup, error) { return nil, err } + +func FileSystemAvailable(conn *fsx.FSx, id string, timeout time.Duration) (*fsx.FileSystem, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{fsx.FileSystemLifecycleCreating, fsx.FileSystemLifecycleUpdating}, + Target: []string{fsx.FileSystemLifecycleAvailable}, + Refresh: FileSystemStatus(conn, id), + Timeout: timeout, + Delay: 30 * time.Second, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*fsx.FileSystem); ok { + if output.FailureDetails != nil { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.FailureDetails.Message))) + } + } + + return nil, err +} + +func FileSystemDeleted(conn *fsx.FSx, id string, timeout time.Duration) (*fsx.FileSystem, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{fsx.FileSystemLifecycleAvailable, fsx.FileSystemLifecycleDeleting}, + Target: []string{}, + Refresh: FileSystemStatus(conn, id), + Timeout: timeout, + Delay: 30 * time.Second, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*fsx.FileSystem); ok { + if output.FailureDetails != nil { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.FailureDetails.Message))) + } + } + + return nil, err +} + +func FileSystemAdministrativeActionsCompleted(conn *fsx.FSx, id, action string, timeout time.Duration) (*fsx.FileSystem, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{ + fsx.StatusInProgress, + fsx.StatusPending, + }, + Target: []string{ + fsx.StatusCompleted, + fsx.StatusUpdatedOptimizing, + }, + Refresh: FileSystemAdministrativeActionsStatus(conn, id, action), + Timeout: timeout, + Delay: 30 * time.Second, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*fsx.FileSystem); ok { + if output.FailureDetails != nil { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.FailureDetails.Message))) + } + } + + return nil, err +} diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go index 7c8b4b8aa41..7c394e802c7 100644 --- a/aws/resource_aws_fsx_backup.go +++ b/aws/resource_aws_fsx_backup.go @@ -164,7 +164,7 @@ func resourceAwsFsxBackupDelete(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("error deleting FSx Backup (%s): %w", d.Id(), err) } - log.Println("[DEBUG] Waiting for filesystem to delete") + log.Println("[DEBUG] Waiting for backup to delete") if _, err := waiter.BackupDeleted(conn, d.Id()); err != nil { return fmt.Errorf("error waiting for FSx Backup (%s) to deleted: %w", d.Id(), err) } diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index 54909f3f7d8..daff48264da 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -14,6 +14,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/finder" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/waiter" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) func resourceAwsFsxLustreFileSystem() *schema.Resource { @@ -329,10 +332,9 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) } - log.Println("[DEBUG] Waiting for filesystem to become available") - - if err := waitForFsxFileSystemCreation(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("Error waiting for filesystem (%s) to become available: %w", d.Id(), err) + log.Println("[DEBUG] Waiting for lustre filesystem to become available") + if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return fmt.Errorf("error waiting for FSx Lustre FileSystem (%s) to be available: %w", d.Id(), err) } return resourceAwsFsxLustreFileSystemRead(d, meta) @@ -386,9 +388,8 @@ func resourceAwsFsxLustreFileSystemUpdate(d *schema.ResourceData, meta interface } log.Println("[DEBUG] Waiting for filesystem to become available") - - if err := waitForFsxFileSystemUpdate(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("Error waiting for filesystem (%s) to become available: %w", d.Id(), err) + if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return fmt.Errorf("error waiting for FSx Lustre File System (%s) to be available: %w", d.Id(), err) } } @@ -400,22 +401,15 @@ func resourceAwsFsxLustreFileSystemRead(d *schema.ResourceData, meta interface{} defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - filesystem, err := describeFsxFileSystem(conn, d.Id()) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { - log.Printf("[WARN] FSx File System (%s) not found, removing from state", d.Id()) + filesystem, err := finder.FileSystemByID(conn, d.Id()) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] FSx Lustre File System (%s) not found, removing from state", d.Id()) d.SetId("") return nil } if err != nil { - return fmt.Errorf("Error reading FSx Lustre File System (%s): %w", d.Id(), err) - } - - if filesystem == nil { - log.Printf("[WARN] FSx File System (%s) not found, removing from state", d.Id()) - d.SetId("") - return nil + return fmt.Errorf("error reading FSx Lustre File System (%s): %w", d.Id(), err) } lustreConfig := filesystem.LustreConfiguration @@ -504,8 +498,8 @@ func resourceAwsFsxLustreFileSystemDelete(d *schema.ResourceData, meta interface log.Println("[DEBUG] Waiting for filesystem to delete") - if err := waitForFsxFileSystemDeletion(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return fmt.Errorf("Error waiting for filesystem (%s) to delete: %w", d.Id(), err) + if _, err := waiter.FileSystemDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + return fmt.Errorf("error waiting for FSx lustre filesystem (%s) to deleted: %w", d.Id(), err) } return nil diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index b2b0c17bb25..202b31c47f5 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -13,6 +13,8 @@ import ( "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/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/finder" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) func init() { @@ -824,8 +826,7 @@ func testAccCheckFsxLustreFileSystemExists(resourceName string, fs *fsx.FileSyst conn := testAccProvider.Meta().(*AWSClient).fsxconn - filesystem, err := describeFsxFileSystem(conn, rs.Primary.ID) - + filesystem, err := finder.FileSystemByID(conn, rs.Primary.ID) if err != nil { return err } @@ -848,16 +849,11 @@ func testAccCheckFsxLustreFileSystemDestroy(s *terraform.State) error { continue } - filesystem, err := describeFsxFileSystem(conn, rs.Primary.ID) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { + filesystem, err := finder.FileSystemByID(conn, rs.Primary.ID) + if tfresource.NotFound(err) { continue } - if err != nil { - return err - } - if filesystem != nil { return fmt.Errorf("FSx File System (%s) still exists", rs.Primary.ID) } From 77f14bfe3224efd3e9b1eb41876e33027b3eda6b Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 20 Aug 2021 20:52:01 +0300 Subject: [PATCH 2/6] changelog --- .changelog/20643.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/20643.txt diff --git a/.changelog/20643.txt b/.changelog/20643.txt new file mode 100644 index 00000000000..3c5464eac16 --- /dev/null +++ b/.changelog/20643.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_fsx_windows_filesystem: Allow creating filesystem from backup using `backup_id`. +``` \ No newline at end of file From c6b0d71bfa837a9eacf32b59b961e4980da05813 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 21 Aug 2021 19:04:59 +0300 Subject: [PATCH 3/6] windows --- aws/resource_aws_fsx_lustre_file_system.go | 1 - ...esource_aws_fsx_lustre_file_system_test.go | 4 +- aws/resource_aws_fsx_windows_file_system.go | 90 +++++++++++++------ ...source_aws_fsx_windows_file_system_test.go | 73 ++++++++++++--- .../r/fsx_lustre_file_system.html.markdown | 2 +- .../r/fsx_windows_file_system.html.markdown | 3 +- 6 files changed, 128 insertions(+), 45 deletions(-) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index daff48264da..535360f4bcc 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -497,7 +497,6 @@ func resourceAwsFsxLustreFileSystemDelete(d *schema.ResourceData, meta interface } log.Println("[DEBUG] Waiting for filesystem to delete") - if _, err := waiter.FileSystemDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return fmt.Errorf("error waiting for FSx lustre filesystem (%s) to deleted: %w", d.Id(), err) } diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index 202b31c47f5..3d75ac53886 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -832,7 +832,7 @@ func testAccCheckFsxLustreFileSystemExists(resourceName string, fs *fsx.FileSyst } if filesystem == nil { - return fmt.Errorf("FSx File System (%s) not found", rs.Primary.ID) + return fmt.Errorf("FSx Lustre File System (%s) not found", rs.Primary.ID) } *fs = *filesystem @@ -855,7 +855,7 @@ func testAccCheckFsxLustreFileSystemDestroy(s *terraform.State) error { } if filesystem != nil { - return fmt.Errorf("FSx File System (%s) still exists", rs.Primary.ID) + return fmt.Errorf("FSx Lustre File System (%s) still exists", rs.Primary.ID) } } return nil diff --git a/aws/resource_aws_fsx_windows_file_system.go b/aws/resource_aws_fsx_windows_file_system.go index fb9df280df4..eedd05048de 100644 --- a/aws/resource_aws_fsx_windows_file_system.go +++ b/aws/resource_aws_fsx_windows_file_system.go @@ -14,6 +14,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/finder" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/waiter" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) func resourceAwsFsxWindowsFileSystem() *schema.Resource { @@ -97,6 +100,11 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource { Default: 7, ValidateFunc: validation.IntBetween(0, 90), }, + "backup_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "copy_tags_to_backups": { Type: schema.TypeBool, Optional: true, @@ -192,7 +200,8 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource { }, "storage_capacity": { Type: schema.TypeInt, - Required: true, + Optional: true, + Computed: true, ValidateFunc: validation.IntBetween(32, 65536), }, "subnet_ids": { @@ -273,65 +282,96 @@ func resourceAwsFsxWindowsFileSystemCreate(d *schema.ResourceData, meta interfac }, } + backupInput := &fsx.CreateFileSystemFromBackupInput{ + ClientRequestToken: aws.String(resource.UniqueId()), + SubnetIds: expandStringList(d.Get("subnet_ids").([]interface{})), + WindowsConfiguration: &fsx.CreateFileSystemWindowsConfiguration{ + AutomaticBackupRetentionDays: aws.Int64(int64(d.Get("automatic_backup_retention_days").(int))), + CopyTagsToBackups: aws.Bool(d.Get("copy_tags_to_backups").(bool)), + ThroughputCapacity: aws.Int64(int64(d.Get("throughput_capacity").(int))), + }, + } + if v, ok := d.GetOk("active_directory_id"); ok { input.WindowsConfiguration.ActiveDirectoryId = aws.String(v.(string)) + backupInput.WindowsConfiguration.ActiveDirectoryId = aws.String(v.(string)) } if v, ok := d.GetOk("aliases"); ok { input.WindowsConfiguration.Aliases = expandStringSet(v.(*schema.Set)) + backupInput.WindowsConfiguration.Aliases = expandStringSet(v.(*schema.Set)) } if v, ok := d.GetOk("deployment_type"); ok { input.WindowsConfiguration.DeploymentType = aws.String(v.(string)) + backupInput.WindowsConfiguration.DeploymentType = aws.String(v.(string)) } if v, ok := d.GetOk("preferred_subnet_id"); ok { input.WindowsConfiguration.PreferredSubnetId = aws.String(v.(string)) + backupInput.WindowsConfiguration.PreferredSubnetId = aws.String(v.(string)) } if v, ok := d.GetOk("daily_automatic_backup_start_time"); ok { input.WindowsConfiguration.DailyAutomaticBackupStartTime = aws.String(v.(string)) + backupInput.WindowsConfiguration.DailyAutomaticBackupStartTime = aws.String(v.(string)) } if v, ok := d.GetOk("kms_key_id"); ok { input.KmsKeyId = aws.String(v.(string)) + backupInput.KmsKeyId = aws.String(v.(string)) } if v, ok := d.GetOk("security_group_ids"); ok { input.SecurityGroupIds = expandStringSet(v.(*schema.Set)) + backupInput.SecurityGroupIds = expandStringSet(v.(*schema.Set)) } if v, ok := d.GetOk("self_managed_active_directory"); ok { input.WindowsConfiguration.SelfManagedActiveDirectoryConfiguration = expandFsxSelfManagedActiveDirectoryConfigurationCreate(v.([]interface{})) + backupInput.WindowsConfiguration.SelfManagedActiveDirectoryConfiguration = expandFsxSelfManagedActiveDirectoryConfigurationCreate(v.([]interface{})) } if v, ok := d.GetOk("audit_log_configuration"); ok && len(v.([]interface{})) > 0 { input.WindowsConfiguration.AuditLogConfiguration = expandFsxWindowsAuditLogCreateConfiguration(v.([]interface{})) + backupInput.WindowsConfiguration.AuditLogConfiguration = expandFsxWindowsAuditLogCreateConfiguration(v.([]interface{})) } if len(tags) > 0 { input.Tags = tags.IgnoreAws().FsxTags() + backupInput.Tags = tags.IgnoreAws().FsxTags() } if v, ok := d.GetOk("weekly_maintenance_start_time"); ok { input.WindowsConfiguration.WeeklyMaintenanceStartTime = aws.String(v.(string)) + backupInput.WindowsConfiguration.WeeklyMaintenanceStartTime = aws.String(v.(string)) } if v, ok := d.GetOk("storage_type"); ok { input.StorageType = aws.String(v.(string)) + backupInput.StorageType = aws.String(v.(string)) } - result, err := conn.CreateFileSystem(input) - if err != nil { - return fmt.Errorf("Error creating FSx filesystem: %w", err) - } + if v, ok := d.GetOk("backup_id"); ok { + backupInput.BackupId = aws.String(v.(string)) + result, err := conn.CreateFileSystemFromBackup(backupInput) + if err != nil { + return fmt.Errorf("Error creating FSx Windows filesystem from backup: %w", err) + } - d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) + d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) + } else { + result, err := conn.CreateFileSystem(input) + if err != nil { + return fmt.Errorf("Error creating FSx Windows filesystem: %w", err) + } - log.Println("[DEBUG] Waiting for filesystem to become available") + d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) + } - if err := waitForFsxFileSystemCreation(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("Error waiting for filesystem (%s) to become available: %w", d.Id(), err) + log.Println("[DEBUG] Waiting for filesystem to become available") + if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return fmt.Errorf("error waiting for FSx Windows FileSystem (%s) to be available: %w", d.Id(), err) } return resourceAwsFsxWindowsFileSystemRead(d, meta) @@ -397,8 +437,8 @@ func resourceAwsFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interfac return fmt.Errorf("error updating FSx Windows File System (%s): %w", d.Id(), err) } - if err := waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn, d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, d.Timeout(schema.TimeoutUpdate)); err != nil { - return fmt.Errorf("error waiting for FSx Windows File System (%s) update: %w", d.Id(), err) + if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, d.Timeout(schema.TimeoutUpdate)); err != nil { + return fmt.Errorf("error waiting for FSx Windows filesystem (%s) to updated: %w", d.Id(), err) } } @@ -410,22 +450,15 @@ func resourceAwsFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{ defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - filesystem, err := describeFsxFileSystem(conn, d.Id()) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { - log.Printf("[WARN] FSx File System (%s) not found, removing from state", d.Id()) + filesystem, err := finder.FileSystemByID(conn, d.Id()) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] FSx Windows File System (%s) not found, removing from state", d.Id()) d.SetId("") return nil } if err != nil { - return fmt.Errorf("Error reading FSx File System (%s): %w", d.Id(), err) - } - - if filesystem == nil { - log.Printf("[WARN] FSx File System (%s) not found, removing from state", d.Id()) - d.SetId("") - return nil + return fmt.Errorf("error reading FSx Windows File System (%s): %w", d.Id(), err) } if filesystem.LustreConfiguration != nil { @@ -513,9 +546,8 @@ func resourceAwsFsxWindowsFileSystemDelete(d *schema.ResourceData, meta interfac } log.Println("[DEBUG] Waiting for filesystem to delete") - - if err := waitForFsxFileSystemDeletion(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return fmt.Errorf("Error waiting for filesystem (%s) to delete: %w", d.Id(), err) + if _, err := waiter.FileSystemDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + return fmt.Errorf("error waiting for FSx Windows filesystem (%s) to deleted: %w", d.Id(), err) } return nil @@ -547,8 +579,8 @@ func updateFsxAliases(conn *fsx.FSx, identifier string, oldSet *schema.Set, newS return fmt.Errorf("error associating aliases to FSx file system (%s): %w", identifier, err) } - if err := waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasAssociation, timeout); err != nil { - return fmt.Errorf("Error waiting for FSX Windows filesystem (%s) alias to be associated: %w", identifier, err) + if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasAssociation, timeout); err != nil { + return fmt.Errorf("error waiting for FSx Windows filesystem (%s) alias to be associated: %w", identifier, err) } } } @@ -566,8 +598,8 @@ func updateFsxAliases(conn *fsx.FSx, identifier string, oldSet *schema.Set, newS return fmt.Errorf("error disassociating aliases from FSx file system (%s): %w", identifier, err) } - if err := waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasDisassociation, timeout); err != nil { - return fmt.Errorf("Error waiting for FSX Windows filesystem (%s) alias to disassociated: %w", identifier, err) + if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasDisassociation, timeout); err != nil { + return fmt.Errorf("error waiting for FSx Windows filesystem (%s) alias to be disassociated: %w", identifier, err) } } } diff --git a/aws/resource_aws_fsx_windows_file_system_test.go b/aws/resource_aws_fsx_windows_file_system_test.go index f64f2852c64..aa9f1c1d9e8 100644 --- a/aws/resource_aws_fsx_windows_file_system_test.go +++ b/aws/resource_aws_fsx_windows_file_system_test.go @@ -12,6 +12,8 @@ import ( "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/terraform-providers/terraform-provider-aws/aws/internal/service/fsx/finder" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) func init() { @@ -633,6 +635,37 @@ func TestAccAWSFsxWindowsFileSystem_StorageCapacity(t *testing.T) { }) } +func TestAccAWSFsxWindowsFileSystem_fromBackup(t *testing.T) { + var filesystem fsx.FileSystem + resourceName := "aws_fsx_windows_file_system.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxWindowsFileSystemDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxWindowsFileSystemFromBackup(), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem), + resource.TestCheckResourceAttrPair(resourceName, "backup_id", "aws_fsx_backup.test", "id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "security_group_ids", + "skip_final_backup", + "backup_id", + }, + }, + }, + }) +} + func TestAccAWSFsxWindowsFileSystem_Tags(t *testing.T) { var filesystem1, filesystem2, filesystem3 fsx.FileSystem resourceName := "aws_fsx_windows_file_system.test" @@ -812,14 +845,13 @@ func testAccCheckFsxWindowsFileSystemExists(resourceName string, fs *fsx.FileSys conn := testAccProvider.Meta().(*AWSClient).fsxconn - filesystem, err := describeFsxFileSystem(conn, rs.Primary.ID) - + filesystem, err := finder.FileSystemByID(conn, rs.Primary.ID) if err != nil { return err } if filesystem == nil { - return fmt.Errorf("FSx File System (%s) not found", rs.Primary.ID) + return fmt.Errorf("FSx Windows File System (%s) not found", rs.Primary.ID) } *fs = *filesystem @@ -836,18 +868,13 @@ func testAccCheckFsxWindowsFileSystemDestroy(s *terraform.State) error { continue } - filesystem, err := describeFsxFileSystem(conn, rs.Primary.ID) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { + filesystem, err := finder.FileSystemByID(conn, rs.Primary.ID) + if tfresource.NotFound(err) { continue } - if err != nil { - return err - } - if filesystem != nil { - return fmt.Errorf("FSx File System (%s) still exists", rs.Primary.ID) + return fmt.Errorf("FSx Windows File System (%s) still exists", rs.Primary.ID) } } return nil @@ -1201,6 +1228,30 @@ resource "aws_fsx_windows_file_system" "test" { `) } +func testAccAwsFsxWindowsFileSystemFromBackup() string { + return testAccAwsFsxWindowsFileSystemConfigBase() + ` +resource "aws_fsx_windows_file_system" "base" { + active_directory_id = aws_directory_service_directory.test.id + skip_final_backup = true + storage_capacity = 32 + subnet_ids = [aws_subnet.test1.id] + throughput_capacity = 8 +} + +resource "aws_fsx_backup" "test" { + file_system_id = aws_fsx_windows_file_system.base.id +} + +resource "aws_fsx_windows_file_system" "test" { + active_directory_id = aws_directory_service_directory.test.id + backup_id = aws_fsx_backup.test.id + skip_final_backup = true + subnet_ids = [aws_subnet.test1.id] + throughput_capacity = 8 +} +` +} + func testAccAwsFsxWindowsFileSystemConfigTags1(tagKey1, tagValue1 string) string { return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(` resource "aws_fsx_windows_file_system" "test" { diff --git a/website/docs/r/fsx_lustre_file_system.html.markdown b/website/docs/r/fsx_lustre_file_system.html.markdown index 5fa2bdac67a..d9aa4ef518f 100644 --- a/website/docs/r/fsx_lustre_file_system.html.markdown +++ b/website/docs/r/fsx_lustre_file_system.html.markdown @@ -24,7 +24,7 @@ resource "aws_fsx_lustre_file_system" "example" { The following arguments are supported: -* `storage_capacity` - (Required) The storage capacity (GiB) of the file system. Minimum of `1200`. See more details at [Allowed values for Fsx storage capacity](https://docs.aws.amazon.com/fsx/latest/APIReference/API_CreateFileSystem.html#FSx-CreateFileSystem-request-StorageCapacity). Update is allowed only for `SCRATCH_2` and `PERSISTENT_1` deployment types, See more details at [Fsx Storage Capacity Update](https://docs.aws.amazon.com/fsx/latest/APIReference/API_UpdateFileSystem.html#FSx-UpdateFileSystem-request-StorageCapacity). +* `storage_capacity` - (Optional) The storage capacity (GiB) of the file system. Minimum of `1200`. See more details at [Allowed values for Fsx storage capacity](https://docs.aws.amazon.com/fsx/latest/APIReference/API_CreateFileSystem.html#FSx-CreateFileSystem-request-StorageCapacity). Update is allowed only for `SCRATCH_2` and `PERSISTENT_1` deployment types, See more details at [Fsx Storage Capacity Update](https://docs.aws.amazon.com/fsx/latest/APIReference/API_UpdateFileSystem.html#FSx-UpdateFileSystem-request-StorageCapacity). Required when not creating filesystem for a backup. * `subnet_ids` - (Required) A list of IDs for the subnets that the file system will be accessible from. File systems currently support only one subnet. The file server is also launched in that subnet's Availability Zone. * `backup_id` - (Optional) The ID of the source backup to create the filesystem from. * `export_path` - (Optional) S3 URI (with optional prefix) where the root of your Amazon FSx file system is exported. Can only be specified with `import_path` argument and the path must use the same Amazon S3 bucket as specified in `import_path`. Set equal to `import_path` to overwrite files on export. Defaults to `s3://{IMPORT BUCKET}/FSxLustre{CREATION TIMESTAMP}`. diff --git a/website/docs/r/fsx_windows_file_system.html.markdown b/website/docs/r/fsx_windows_file_system.html.markdown index 8498466b874..c2c678e74e3 100644 --- a/website/docs/r/fsx_windows_file_system.html.markdown +++ b/website/docs/r/fsx_windows_file_system.html.markdown @@ -52,9 +52,10 @@ resource "aws_fsx_windows_file_system" "example" { The following arguments are supported: -* `storage_capacity` - (Required) Storage capacity (GiB) of the file system. Minimum of 32 and maximum of 65536. If the storage type is set to `HDD` the minimum value is 2000. +* `storage_capacity` - (Optional) Storage capacity (GiB) of the file system. Minimum of 32 and maximum of 65536. If the storage type is set to `HDD` the minimum value is 2000. Required when not creating filesystem for a backup. * `subnet_ids` - (Required) A list of IDs for the subnets that the file system will be accessible from. To specify more than a single subnet set `deployment_type` to `MULTI_AZ_1`. * `throughput_capacity` - (Required) Throughput (megabytes per second) of the file system in power of 2 increments. Minimum of `8` and maximum of `2048`. +* `backup_id` - (Optional) The ID of the source backup to create the filesystem from. * `active_directory_id` - (Optional) The ID for an existing Microsoft Active Directory instance that the file system should join when it's created. Cannot be specified with `self_managed_active_directory`. * `aliases` - (Optional) An array DNS alias names that you want to associate with the Amazon FSx file system. For more information, see [Working with DNS Aliases](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/managing-dns-aliases.html) * `automatic_backup_retention_days` - (Optional) The number of days to retain automatic backups. Minimum of `0` and maximum of `90`. Defaults to `7`. Set to `0` to disable. From b2041bd5c0919558676e16900c9851f3d111724c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 21 Aug 2021 23:23:05 +0300 Subject: [PATCH 4/6] remove fsx --- aws/fsx.go | 155 ----------------------------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 aws/fsx.go diff --git a/aws/fsx.go b/aws/fsx.go deleted file mode 100644 index 9e4cc968e8a..00000000000 --- a/aws/fsx.go +++ /dev/null @@ -1,155 +0,0 @@ -package aws - -import ( - "errors" - "time" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/fsx" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" -) - -func describeFsxFileSystem(conn *fsx.FSx, id string) (*fsx.FileSystem, error) { - input := &fsx.DescribeFileSystemsInput{ - FileSystemIds: []*string{aws.String(id)}, - } - var filesystem *fsx.FileSystem - - err := conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool { - for _, fs := range page.FileSystems { - if aws.StringValue(fs.FileSystemId) == id { - filesystem = fs - return false - } - } - - return !lastPage - }) - - return filesystem, err -} - -func refreshFsxFileSystemLifecycle(conn *fsx.FSx, id string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - filesystem, err := describeFsxFileSystem(conn, id) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - if filesystem == nil { - return nil, "", nil - } - - return filesystem, aws.StringValue(filesystem.Lifecycle), nil - } -} - -func refreshFsxFileSystemAdministrativeActionsStatusFileSystemUpdate(conn *fsx.FSx, id, action string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - filesystem, err := describeFsxFileSystem(conn, id) - - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - if filesystem == nil { - return nil, "", nil - } - - for _, administrativeAction := range filesystem.AdministrativeActions { - if administrativeAction == nil { - continue - } - - if aws.StringValue(administrativeAction.AdministrativeActionType) == action { - return filesystem, aws.StringValue(administrativeAction.Status), nil - } - } - - return filesystem, fsx.StatusCompleted, nil - } -} - -func waitForFsxFileSystemCreation(conn *fsx.FSx, id string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{fsx.FileSystemLifecycleCreating}, - Target: []string{fsx.FileSystemLifecycleAvailable}, - Refresh: refreshFsxFileSystemLifecycle(conn, id), - Timeout: timeout, - Delay: 30 * time.Second, - } - - outputRaw, err := stateConf.WaitForState() - - if output, ok := outputRaw.(*fsx.FileSystem); ok { - if output.FailureDetails != nil { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.FailureDetails.Message))) - } - } - - return err -} - -func waitForFsxFileSystemDeletion(conn *fsx.FSx, id string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{fsx.FileSystemLifecycleAvailable, fsx.FileSystemLifecycleDeleting}, - Target: []string{}, - Refresh: refreshFsxFileSystemLifecycle(conn, id), - Timeout: timeout, - Delay: 30 * time.Second, - } - - outputRaw, err := stateConf.WaitForState() - - if output, ok := outputRaw.(*fsx.FileSystem); ok { - if output.FailureDetails != nil { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.FailureDetails.Message))) - } - } - - return err -} - -func waitForFsxFileSystemUpdate(conn *fsx.FSx, id string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{fsx.FileSystemLifecycleUpdating}, - Target: []string{fsx.FileSystemLifecycleAvailable}, - Refresh: refreshFsxFileSystemLifecycle(conn, id), - Timeout: timeout, - Delay: 30 * time.Second, - } - - _, err := stateConf.WaitForState() - - return err -} - -func waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn *fsx.FSx, id, action string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{ - fsx.StatusInProgress, - fsx.StatusPending, - }, - Target: []string{ - fsx.StatusCompleted, - fsx.StatusUpdatedOptimizing, - }, - Refresh: refreshFsxFileSystemAdministrativeActionsStatusFileSystemUpdate(conn, id, action), - Timeout: timeout, - Delay: 30 * time.Second, - } - - _, err := stateConf.WaitForState() - - return err -} From bb68e5956c021137b90021b5f99aa84a135823d0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Aug 2021 11:27:51 -0400 Subject: [PATCH 5/6] Tweak error messages. --- aws/resource_aws_fsx_lustre_file_system.go | 26 +++++++++++-------- ...esource_aws_fsx_lustre_file_system_test.go | 6 ++--- aws/resource_aws_fsx_windows_file_system.go | 25 +++++++++++------- ...source_aws_fsx_windows_file_system_test.go | 6 ++--- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/aws/resource_aws_fsx_lustre_file_system.go b/aws/resource_aws_fsx_lustre_file_system.go index 535360f4bcc..898c99a43da 100644 --- a/aws/resource_aws_fsx_lustre_file_system.go +++ b/aws/resource_aws_fsx_lustre_file_system.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/fsx" + "github.com/hashicorp/aws-sdk-go-base/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -317,24 +318,28 @@ func resourceAwsFsxLustreFileSystemCreate(d *schema.ResourceData, meta interface if v, ok := d.GetOk("backup_id"); ok { backupInput.BackupId = aws.String(v.(string)) + + log.Printf("[DEBUG] Creating FSx Lustre File System: %s", backupInput) result, err := conn.CreateFileSystemFromBackup(backupInput) + if err != nil { - return fmt.Errorf("Error creating FSx Lustre filesystem from backup: %w", err) + return fmt.Errorf("error creating FSx Lustre File System from backup: %w", err) } d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) } else { + log.Printf("[DEBUG] Creating FSx Lustre File System: %s", input) result, err := conn.CreateFileSystem(input) + if err != nil { - return fmt.Errorf("Error creating FSx Lustre filesystem: %w", err) + return fmt.Errorf("error creating FSx Lustre File System: %w", err) } d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) } - log.Println("[DEBUG] Waiting for lustre filesystem to become available") if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("error waiting for FSx Lustre FileSystem (%s) to be available: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Lustre File System (%s) to be available: %w", d.Id(), err) } return resourceAwsFsxLustreFileSystemRead(d, meta) @@ -387,7 +392,6 @@ func resourceAwsFsxLustreFileSystemUpdate(d *schema.ResourceData, meta interface return fmt.Errorf("error updating FSX Lustre File System (%s): %w", d.Id(), err) } - log.Println("[DEBUG] Waiting for filesystem to become available") if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return fmt.Errorf("error waiting for FSx Lustre File System (%s) to be available: %w", d.Id(), err) } @@ -462,11 +466,11 @@ func resourceAwsFsxLustreFileSystemRead(d *schema.ResourceData, meta interface{} //lintignore:AWSR002 if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return fmt.Errorf("error setting tags: %w", err) } if err := d.Set("tags_all", tags.Map()); err != nil { - return fmt.Errorf("error setting tags_all: %s", err) + return fmt.Errorf("error setting tags_all: %w", err) } d.Set("vpc_id", filesystem.VpcId) @@ -486,19 +490,19 @@ func resourceAwsFsxLustreFileSystemDelete(d *schema.ResourceData, meta interface FileSystemId: aws.String(d.Id()), } + log.Printf("[DEBUG] Deleting FSx Lustre File System: %s", d.Id()) _, err := conn.DeleteFileSystem(request) - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { + if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) { return nil } if err != nil { - return fmt.Errorf("Error deleting FSx Lustre filesystem: %w", err) + return fmt.Errorf("error deleting FSx Lustre File System (%s): %w", d.Id(), err) } - log.Println("[DEBUG] Waiting for filesystem to delete") if _, err := waiter.FileSystemDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return fmt.Errorf("error waiting for FSx lustre filesystem (%s) to deleted: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Lustre File System (%s) to deleted: %w", d.Id(), err) } return nil diff --git a/aws/resource_aws_fsx_lustre_file_system_test.go b/aws/resource_aws_fsx_lustre_file_system_test.go index 3d75ac53886..cc160e082af 100644 --- a/aws/resource_aws_fsx_lustre_file_system_test.go +++ b/aws/resource_aws_fsx_lustre_file_system_test.go @@ -57,15 +57,15 @@ func testSweepFSXLustreFileSystems(region string) error { }) if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing FSx Lustre Filesystems for %s: %w", region, err)) + errs = multierror.Append(errs, fmt.Errorf("error listing FSx Lustre File Systems for %s: %w", region, err)) } if err = testSweepResourceOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Lustre Filesystems for %s: %w", region, err)) + errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Lustre File Systems for %s: %w", region, err)) } if testSweepSkipSweepError(errs.ErrorOrNil()) { - log.Printf("[WARN] Skipping FSx Lustre Filesystems sweep for %s: %s", region, errs) + log.Printf("[WARN] Skipping FSx Lustre File System sweep for %s: %s", region, errs) return nil } diff --git a/aws/resource_aws_fsx_windows_file_system.go b/aws/resource_aws_fsx_windows_file_system.go index eedd05048de..678beff69d3 100644 --- a/aws/resource_aws_fsx_windows_file_system.go +++ b/aws/resource_aws_fsx_windows_file_system.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/fsx" + "github.com/hashicorp/aws-sdk-go-base/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" @@ -354,24 +355,28 @@ func resourceAwsFsxWindowsFileSystemCreate(d *schema.ResourceData, meta interfac if v, ok := d.GetOk("backup_id"); ok { backupInput.BackupId = aws.String(v.(string)) + + log.Printf("[DEBUG] Creating FSx Windows File System: %s", backupInput) result, err := conn.CreateFileSystemFromBackup(backupInput) + if err != nil { - return fmt.Errorf("Error creating FSx Windows filesystem from backup: %w", err) + return fmt.Errorf("error creating FSx Windows File System from backup: %w", err) } d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) } else { + log.Printf("[DEBUG] Creating FSx Windows File System: %s", input) result, err := conn.CreateFileSystem(input) + if err != nil { - return fmt.Errorf("Error creating FSx Windows filesystem: %w", err) + return fmt.Errorf("error creating FSx Windows File System: %w", err) } d.SetId(aws.StringValue(result.FileSystem.FileSystemId)) } - log.Println("[DEBUG] Waiting for filesystem to become available") if _, err := waiter.FileSystemAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return fmt.Errorf("error waiting for FSx Windows FileSystem (%s) to be available: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Windows File System (%s) to be available: %w", d.Id(), err) } return resourceAwsFsxWindowsFileSystemRead(d, meta) @@ -438,7 +443,7 @@ func resourceAwsFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interfac } if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, d.Timeout(schema.TimeoutUpdate)); err != nil { - return fmt.Errorf("error waiting for FSx Windows filesystem (%s) to updated: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Windows File System (%s) to update: %w", d.Id(), err) } } @@ -483,7 +488,7 @@ func resourceAwsFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{ d.Set("storage_type", filesystem.StorageType) if err := d.Set("aliases", aws.StringValueSlice(expandFsxAliasValues(filesystem.WindowsConfiguration.Aliases))); err != nil { - return fmt.Errorf("error setting aliases: %s", err) + return fmt.Errorf("error setting aliases: %w", err) } if err := d.Set("network_interface_ids", aws.StringValueSlice(filesystem.NetworkInterfaceIds)); err != nil { @@ -535,19 +540,19 @@ func resourceAwsFsxWindowsFileSystemDelete(d *schema.ResourceData, meta interfac }, } + log.Printf("[DEBUG] Deleting FSx Windows File System: %s", d.Id()) _, err := conn.DeleteFileSystem(input) - if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") { + if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) { return nil } if err != nil { - return fmt.Errorf("Error deleting FSx filesystem: %w", err) + return fmt.Errorf("error deleting FSx Windows File System (%s): %w", d.Id(), err) } - log.Println("[DEBUG] Waiting for filesystem to delete") if _, err := waiter.FileSystemDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return fmt.Errorf("error waiting for FSx Windows filesystem (%s) to deleted: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Windows File System (%s) to delete: %w", d.Id(), err) } return nil diff --git a/aws/resource_aws_fsx_windows_file_system_test.go b/aws/resource_aws_fsx_windows_file_system_test.go index aa9f1c1d9e8..0eb57eee08a 100644 --- a/aws/resource_aws_fsx_windows_file_system_test.go +++ b/aws/resource_aws_fsx_windows_file_system_test.go @@ -57,15 +57,15 @@ func testSweepFSXWindowsFileSystems(region string) error { }) if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing FSx Windows Filesystems for %s: %w", region, err)) + errs = multierror.Append(errs, fmt.Errorf("error listing FSx Windows File Systems for %s: %w", region, err)) } if err = testSweepResourceOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Windows Filesystems for %s: %w", region, err)) + errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Windows File Systems for %s: %w", region, err)) } if testSweepSkipSweepError(errs.ErrorOrNil()) { - log.Printf("[WARN] Skipping FSx Windows Filesystems sweep for %s: %s", region, errs) + log.Printf("[WARN] Skipping FSx Windows File System sweep for %s: %s", region, errs) return nil } From 8e83f52b0558cf8c7deb50628abd31d3a46f4b70 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Mon, 23 Aug 2021 18:10:17 +0300 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Kit Ewbank --- aws/resource_aws_fsx_windows_file_system.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_fsx_windows_file_system.go b/aws/resource_aws_fsx_windows_file_system.go index 678beff69d3..13575e85c54 100644 --- a/aws/resource_aws_fsx_windows_file_system.go +++ b/aws/resource_aws_fsx_windows_file_system.go @@ -585,7 +585,7 @@ func updateFsxAliases(conn *fsx.FSx, identifier string, oldSet *schema.Set, newS } if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasAssociation, timeout); err != nil { - return fmt.Errorf("error waiting for FSx Windows filesystem (%s) alias to be associated: %w", identifier, err) + return fmt.Errorf("error waiting for FSx Windows File System (%s) alias to be associated: %w", identifier, err) } } } @@ -604,7 +604,7 @@ func updateFsxAliases(conn *fsx.FSx, identifier string, oldSet *schema.Set, newS } if _, err := waiter.FileSystemAdministrativeActionsCompleted(conn, identifier, fsx.AdministrativeActionTypeFileSystemAliasDisassociation, timeout); err != nil { - return fmt.Errorf("error waiting for FSx Windows filesystem (%s) alias to be disassociated: %w", identifier, err) + return fmt.Errorf("error waiting for FSx Windows File System (%s) alias to be disassociated: %w", identifier, err) } } }