From 2637659af374b7a6c33237659a42247824b883d4 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 10 Aug 2021 00:56:50 +0300 Subject: [PATCH 01/11] initial commit --- aws/internal/service/fsx/finder/finder.go | 36 +++ aws/internal/service/fsx/waiter/status.go | 25 ++ aws/internal/service/fsx/waiter/waiter.go | 47 ++++ aws/provider.go | 1 + aws/resource_aws_fsx_backup.go | 189 +++++++++++++++ aws/resource_aws_fsx_backup_test.go | 278 ++++++++++++++++++++++ 6 files changed, 576 insertions(+) create mode 100644 aws/internal/service/fsx/finder/finder.go create mode 100644 aws/internal/service/fsx/waiter/status.go create mode 100644 aws/internal/service/fsx/waiter/waiter.go create mode 100644 aws/resource_aws_fsx_backup.go create mode 100644 aws/resource_aws_fsx_backup_test.go diff --git a/aws/internal/service/fsx/finder/finder.go b/aws/internal/service/fsx/finder/finder.go new file mode 100644 index 00000000000..234ff80f801 --- /dev/null +++ b/aws/internal/service/fsx/finder/finder.go @@ -0,0 +1,36 @@ +package finder + +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/resource" +) + +func BackupByID(conn *fsx.FSx, id string) (*fsx.Backup, error) { + input := &fsx.DescribeBackupsInput{ + BackupIds: aws.StringSlice([]string{id}), + } + + output, err := conn.DescribeBackups(input) + + if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) || tfawserr.ErrCodeEquals(err, fsx.ErrCodeBackupNotFound) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.Backups == nil || len(output.Backups) == 0 { + return nil, &resource.NotFoundError{ + Message: "Empty result", + LastRequest: input, + } + } + + return output.Backups[0], nil +} diff --git a/aws/internal/service/fsx/waiter/status.go b/aws/internal/service/fsx/waiter/status.go new file mode 100644 index 00000000000..eaaa05bc09e --- /dev/null +++ b/aws/internal/service/fsx/waiter/status.go @@ -0,0 +1,25 @@ +package waiter + +import ( + "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/service/fsx/finder" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" +) + +func BackupStatus(conn *fsx.FSx, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := finder.BackupByID(conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, aws.StringValue(output.Lifecycle), nil + } +} diff --git a/aws/internal/service/fsx/waiter/waiter.go b/aws/internal/service/fsx/waiter/waiter.go new file mode 100644 index 00000000000..5d16e568312 --- /dev/null +++ b/aws/internal/service/fsx/waiter/waiter.go @@ -0,0 +1,47 @@ +package waiter + +import ( + "time" + + "github.com/aws/aws-sdk-go/service/fsx" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +const ( + BackupAvailableTimeout = 10 * time.Minute + BackupDeletedTimeout = 10 * time.Minute +) + +func BackupAvailable(conn *fsx.FSx, id string) (*fsx.Backup, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{fsx.BackupLifecycleCreating, fsx.BackupLifecyclePending}, + Target: []string{fsx.BackupLifecycleAvailable}, + Refresh: BackupStatus(conn, id), + Timeout: BackupAvailableTimeout, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*fsx.Backup); ok { + return output, err + } + + return nil, err +} + +func BackupDeleted(conn *fsx.FSx, id string) (*fsx.Backup, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{fsx.FileSystemLifecycleDeleting}, + Target: []string{}, + Refresh: BackupStatus(conn, id), + Timeout: BackupDeletedTimeout, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*fsx.Backup); ok { + return output, err + } + + return nil, err +} diff --git a/aws/provider.go b/aws/provider.go index 1beb5e9c100..fc256f58722 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -766,6 +766,7 @@ func Provider() *schema.Provider { "aws_emr_managed_scaling_policy": resourceAwsEMRManagedScalingPolicy(), "aws_emr_security_configuration": resourceAwsEMRSecurityConfiguration(), "aws_flow_log": resourceAwsFlowLog(), + "aws_fsx_backup": resourceAwsFsxBackup(), "aws_fsx_lustre_file_system": resourceAwsFsxLustreFileSystem(), "aws_fsx_windows_file_system": resourceAwsFsxWindowsFileSystem(), "aws_fms_admin_account": resourceAwsFmsAdminAccount(), diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go new file mode 100644 index 00000000000..645c9e7de34 --- /dev/null +++ b/aws/resource_aws_fsx_backup.go @@ -0,0 +1,189 @@ +package aws + +import ( + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/fsx" + "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" + "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" +) + +func resourceAwsFsxBackup() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsFsxBackupCreate, + Read: resourceAwsFsxBackupRead, + Update: resourceAwsFsxBackupUpdate, + Delete: resourceAwsFsxBackupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "file_system_id": { + Type: schema.TypeString, + Required: true, + }, + "kms_key_id": { + Type: schema.TypeString, + Computed: true, + }, + "owner_id": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), + "tags_all": tagsSchemaComputed(), + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + + CustomizeDiff: customdiff.Sequence( + SetTagsDiff, + ), + } +} + +func resourceAwsFsxBackupCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).fsxconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) + + input := &fsx.CreateBackupInput{ + ClientRequestToken: aws.String(resource.UniqueId()), + FileSystemId: aws.String(d.Get("file_system_id").(string)), + } + + if len(tags) > 0 { + input.Tags = tags.IgnoreAws().FsxTags() + } + + result, err := conn.CreateBackup(input) + if err != nil { + return fmt.Errorf("Error creating FSx Backup: %w", err) + } + + d.SetId(aws.StringValue(result.Backup.BackupId)) + + log.Println("[DEBUG] Waiting for FSx backup to become available") + if _, err := waiter.BackupAvailable(conn, d.Id()); err != nil { + return fmt.Errorf("error waiting for FSx backup (%s) to be available: %w", d.Id(), err) + } + + return resourceAwsFsxBackupRead(d, meta) +} + +func resourceAwsFsxBackupUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).fsxconn + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + + if err := keyvaluetags.FsxUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { + return fmt.Errorf("error updating FSx Lustre File System (%s) tags: %w", d.Get("arn").(string), err) + } + } + + return resourceAwsFsxBackupRead(d, meta) +} + +func resourceAwsFsxBackupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).fsxconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig + + backup, err := finder.BackupByID(conn, d.Id()) + if err != nil { + return err + } + + if !d.IsNewResource() && backup == nil { + log.Printf("[WARN] FSx Backup (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + d.Set("arn", backup.ResourceARN) + d.Set("type", backup.Type) + + // d.Set("dns_name", filesystem.DNSName) + // d.Set("export_path", lustreConfig.DataRepositoryConfiguration.ExportPath) + // d.Set("import_path", lustreConfig.DataRepositoryConfiguration.ImportPath) + // d.Set("auto_import_policy", lustreConfig.DataRepositoryConfiguration.AutoImportPolicy) + // d.Set("imported_file_chunk_size", lustreConfig.DataRepositoryConfiguration.ImportedFileChunkSize) + // d.Set("deployment_type", lustreConfig.DeploymentType) + // if lustreConfig.PerUnitStorageThroughput != nil { + // d.Set("per_unit_storage_throughput", lustreConfig.PerUnitStorageThroughput) + // } + // d.Set("mount_name", lustreConfig.MountName) + // d.Set("storage_type", filesystem.StorageType) + // if lustreConfig.DriveCacheType != nil { + // d.Set("drive_cache_type", lustreConfig.DriveCacheType) + // } + + if backup.KmsKeyId != nil { + d.Set("kms_key_id", backup.KmsKeyId) + } + + // if err := d.Set("network_interface_ids", aws.StringValueSlice(filesystem.NetworkInterfaceIds)); err != nil { + // return fmt.Errorf("error setting network_interface_ids: %w", err) + // } + + d.Set("owner_id", backup.OwnerId) + + tags := keyvaluetags.FsxKeyValueTags(backup.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + 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: %w", err) + } + + return nil +} + +func resourceAwsFsxBackupDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).fsxconn + + request := &fsx.DeleteBackupInput{ + BackupId: aws.String(d.Id()), + } + + _, err := retryOnAwsCode(fsx.ErrCodeBackupInProgress, func() (interface{}, error) { + return conn.DeleteBackup(request) + }) + if isAWSErr(err, fsx.ErrCodeBackupNotFound, "") { + return nil + } + + if err != nil { + return fmt.Errorf("Error deleting FSx Backup: %w", err) + } + + log.Println("[DEBUG] Waiting for filesystem 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) + } + + return nil +} diff --git a/aws/resource_aws_fsx_backup_test.go b/aws/resource_aws_fsx_backup_test.go new file mode 100644 index 00000000000..03aee58ebf9 --- /dev/null +++ b/aws/resource_aws_fsx_backup_test.go @@ -0,0 +1,278 @@ +package aws + +import ( + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/service/fsx" + "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() { +// resource.AddTestSweepers("aws_fsx_lustre_file_system", &resource.Sweeper{ +// Name: "aws_fsx_lustre_file_system", +// F: testSweepFSXBackups, +// }) +// } + +// func testSweepFSXBackups(region string) error { +// client, err := sharedClientForRegion(region) + +// if err != nil { +// return fmt.Errorf("error getting client: %s", err) +// } + +// conn := client.(*AWSClient).fsxconn +// sweepResources := make([]*testSweepResource, 0) +// var errs *multierror.Error +// input := &fsx.DescribeBackupsInput{} + +// err = conn.DescribeBackupsPages(input, func(page *fsx.DescribeBackupsOutput, lastPage bool) bool { +// if page == nil { +// return !lastPage +// } + +// for _, fs := range page.Backups { +// if aws.StringValue(fs.BackupType) != fsx.BackupTypeLustre { +// continue +// } + +// r := resourceAwsFsxBackup() +// d := r.Data(nil) +// d.SetId(aws.StringValue(fs.BackupId)) + +// sweepResources = append(sweepResources, NewTestSweepResource(r, d, client)) +// } + +// return !lastPage +// }) + +// if err != nil { +// errs = multierror.Append(errs, fmt.Errorf("error listing FSx Lustre Filesystems 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)) +// } + +// if testSweepSkipSweepError(errs.ErrorOrNil()) { +// log.Printf("[WARN] Skipping FSx Lustre Filesystems sweep for %s: %s", region, errs) +// return nil +// } + +// return errs.ErrorOrNil() +// } + +func TestAccAWSFsxBackup_basic(t *testing.T) { + var backup fsx.Backup + resourceName := "aws_fsx_backup.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxBackupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxBackupConfigBasic(), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "fsx", regexp.MustCompile(`backup/.+`)), + // resource.TestMatchResourceAttr(resourceName, "dns_name", regexp.MustCompile(`fs-.+\.fsx\.`)), + // resource.TestCheckResourceAttr(resourceName, "export_path", ""), + // resource.TestCheckResourceAttr(resourceName, "import_path", ""), + // resource.TestCheckResourceAttr(resourceName, "imported_file_chunk_size", "0"), + // resource.TestCheckResourceAttrSet(resourceName, "mount_name"), + // resource.TestCheckResourceAttr(resourceName, "network_interface_ids.#", "2"), + testAccCheckResourceAttrAccountID(resourceName, "owner_id"), + // resource.TestCheckResourceAttr(resourceName, "storage_capacity", "1200"), + // resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"), + // resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + // resource.TestMatchResourceAttr(resourceName, "vpc_id", regexp.MustCompile(`^vpc-.+`)), + // resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)), + // resource.TestCheckResourceAttr(resourceName, "deployment_type", deploymentType), + // resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"), + // resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd), + // resource.TestCheckResourceAttr(resourceName, "copy_tags_to_backups", "false"), + // resource.TestCheckResourceAttr(resourceName, "data_compression_type", fsx.DataCompressionTypeNone), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSFsxBackup_disappears(t *testing.T) { + var backup fsx.Backup + resourceName := "aws_fsx_backup.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxBackupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxBackupConfigBasic(), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + testAccCheckResourceDisappears(testAccProvider, resourceAwsFsxBackup(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSFsxBackup_Tags(t *testing.T) { + var backup fsx.Backup + resourceName := "aws_fsx_backup.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxBackupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxBackupConfigTags1("key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAwsFsxBackupConfigTags2("key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAwsFsxBackupConfigTags1("key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func testAccCheckFsxBackupExists(resourceName string, fs *fsx.Backup) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + conn := testAccProvider.Meta().(*AWSClient).fsxconn + + output, err := finder.BackupByID(conn, rs.Primary.ID) + if err != nil { + return err + } + + if output == nil { + return fmt.Errorf("FSx Backup (%s) not found", rs.Primary.ID) + } + + *fs = *output + + return nil + } +} + +func testAccCheckFsxBackupDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).fsxconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_fsx_backup" { + continue + } + + _, err := finder.BackupByID(conn, rs.Primary.ID) + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("FSx Backup %s still exists", rs.Primary.ID) + } + return nil +} + +func testAccAwsFsxBackupConfigBase() string { + return composeConfig(testAccAvailableAZsNoOptInConfig(), ` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" +} + +resource "aws_subnet" "test1" { + vpc_id = aws_vpc.test.id + cidr_block = "10.0.1.0/24" + availability_zone = data.aws_availability_zones.available.names[0] +} + +resource "aws_fsx_lustre_file_system" "test" { + storage_capacity = 1200 + subnet_ids = [aws_subnet.test1.id] + deployment_type = "PERSISTENT_1" + per_unit_storage_throughput = 50 +} +`) +} + +func testAccAwsFsxBackupConfigBasic() string { + return composeConfig(testAccAwsFsxBackupConfigBase(), ` +resource "aws_fsx_backup" "test" { + file_system_id = aws_fsx_lustre_file_system.test.id +} +`) +} + +func testAccAwsFsxBackupConfigTags1(tagKey1, tagValue1 string) string { + return composeConfig(testAccAwsFsxBackupConfigBase(), fmt.Sprintf(` +resource "aws_fsx_backup" "test" { + file_system_id = aws_fsx_lustre_file_system.test.id + + tags = { + %[1]q = %[2]q + } +} +`, tagKey1, tagValue1)) +} + +func testAccAwsFsxBackupConfigTags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return composeConfig(testAccAwsFsxBackupConfigBase(), fmt.Sprintf(` +resource "aws_fsx_backup" "test" { + file_system_id = aws_fsx_lustre_file_system.test.id + + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} +`, tagKey1, tagValue1, tagKey2, tagValue2)) +} From bc1d2aafb00bcefbd4ad46b0b715eb7856f416fe Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 10 Aug 2021 13:38:43 +0300 Subject: [PATCH 02/11] add missing waiter modes + attribute in read --- aws/internal/service/fsx/waiter/waiter.go | 2 +- aws/resource_aws_fsx_backup.go | 24 +++-------------------- aws/resource_aws_fsx_backup_test.go | 16 --------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/aws/internal/service/fsx/waiter/waiter.go b/aws/internal/service/fsx/waiter/waiter.go index 5d16e568312..4edfce96421 100644 --- a/aws/internal/service/fsx/waiter/waiter.go +++ b/aws/internal/service/fsx/waiter/waiter.go @@ -14,7 +14,7 @@ const ( func BackupAvailable(conn *fsx.FSx, id string) (*fsx.Backup, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{fsx.BackupLifecycleCreating, fsx.BackupLifecyclePending}, + Pending: []string{fsx.BackupLifecycleCreating, fsx.BackupLifecyclePending, fsx.BackupLifecycleTransferring}, Target: []string{fsx.BackupLifecycleAvailable}, Refresh: BackupStatus(conn, id), Timeout: BackupAvailableTimeout, diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go index 645c9e7de34..56b931890fe 100644 --- a/aws/resource_aws_fsx_backup.go +++ b/aws/resource_aws_fsx_backup.go @@ -123,29 +123,13 @@ func resourceAwsFsxBackupRead(d *schema.ResourceData, meta interface{}) error { d.Set("arn", backup.ResourceARN) d.Set("type", backup.Type) - // d.Set("dns_name", filesystem.DNSName) - // d.Set("export_path", lustreConfig.DataRepositoryConfiguration.ExportPath) - // d.Set("import_path", lustreConfig.DataRepositoryConfiguration.ImportPath) - // d.Set("auto_import_policy", lustreConfig.DataRepositoryConfiguration.AutoImportPolicy) - // d.Set("imported_file_chunk_size", lustreConfig.DataRepositoryConfiguration.ImportedFileChunkSize) - // d.Set("deployment_type", lustreConfig.DeploymentType) - // if lustreConfig.PerUnitStorageThroughput != nil { - // d.Set("per_unit_storage_throughput", lustreConfig.PerUnitStorageThroughput) - // } - // d.Set("mount_name", lustreConfig.MountName) - // d.Set("storage_type", filesystem.StorageType) - // if lustreConfig.DriveCacheType != nil { - // d.Set("drive_cache_type", lustreConfig.DriveCacheType) - // } + fs := backup.FileSystem + d.Set("file_system_id", fs.FileSystemId) if backup.KmsKeyId != nil { d.Set("kms_key_id", backup.KmsKeyId) } - // if err := d.Set("network_interface_ids", aws.StringValueSlice(filesystem.NetworkInterfaceIds)); err != nil { - // return fmt.Errorf("error setting network_interface_ids: %w", err) - // } - d.Set("owner_id", backup.OwnerId) tags := keyvaluetags.FsxKeyValueTags(backup.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) @@ -169,9 +153,7 @@ func resourceAwsFsxBackupDelete(d *schema.ResourceData, meta interface{}) error BackupId: aws.String(d.Id()), } - _, err := retryOnAwsCode(fsx.ErrCodeBackupInProgress, func() (interface{}, error) { - return conn.DeleteBackup(request) - }) + _, err := conn.DeleteBackup(request) if isAWSErr(err, fsx.ErrCodeBackupNotFound, "") { return nil } diff --git a/aws/resource_aws_fsx_backup_test.go b/aws/resource_aws_fsx_backup_test.go index 03aee58ebf9..07972f97db3 100644 --- a/aws/resource_aws_fsx_backup_test.go +++ b/aws/resource_aws_fsx_backup_test.go @@ -82,24 +82,8 @@ func TestAccAWSFsxBackup_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckFsxBackupExists(resourceName, &backup), testAccMatchResourceAttrRegionalARN(resourceName, "arn", "fsx", regexp.MustCompile(`backup/.+`)), - // resource.TestMatchResourceAttr(resourceName, "dns_name", regexp.MustCompile(`fs-.+\.fsx\.`)), - // resource.TestCheckResourceAttr(resourceName, "export_path", ""), - // resource.TestCheckResourceAttr(resourceName, "import_path", ""), - // resource.TestCheckResourceAttr(resourceName, "imported_file_chunk_size", "0"), - // resource.TestCheckResourceAttrSet(resourceName, "mount_name"), - // resource.TestCheckResourceAttr(resourceName, "network_interface_ids.#", "2"), testAccCheckResourceAttrAccountID(resourceName, "owner_id"), - // resource.TestCheckResourceAttr(resourceName, "storage_capacity", "1200"), - // resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"), - // resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "0"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - // resource.TestMatchResourceAttr(resourceName, "vpc_id", regexp.MustCompile(`^vpc-.+`)), - // resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)), - // resource.TestCheckResourceAttr(resourceName, "deployment_type", deploymentType), - // resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"), - // resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd), - // resource.TestCheckResourceAttr(resourceName, "copy_tags_to_backups", "false"), - // resource.TestCheckResourceAttr(resourceName, "data_compression_type", fsx.DataCompressionTypeNone), ), }, { From d3738ddc48ab24d516a8d07ac7db22eea27b152e Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 13:11:13 +0300 Subject: [PATCH 03/11] correct finder + more tests --- aws/internal/service/fsx/finder/finder.go | 2 +- aws/resource_aws_fsx_backup.go | 23 ++++--- aws/resource_aws_fsx_backup_test.go | 81 ++++++++++++++++++++++- 3 files changed, 94 insertions(+), 12 deletions(-) diff --git a/aws/internal/service/fsx/finder/finder.go b/aws/internal/service/fsx/finder/finder.go index 234ff80f801..c74a509b431 100644 --- a/aws/internal/service/fsx/finder/finder.go +++ b/aws/internal/service/fsx/finder/finder.go @@ -25,7 +25,7 @@ func BackupByID(conn *fsx.FSx, id string) (*fsx.Backup, error) { return nil, err } - if output == nil || output.Backups == nil || len(output.Backups) == 0 { + if output == nil || len(output.Backups) == 0 || output.Backups[0] == nil { return nil, &resource.NotFoundError{ Message: "Empty result", LastRequest: input, diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go index 56b931890fe..e085bc0b32a 100644 --- a/aws/resource_aws_fsx_backup.go +++ b/aws/resource_aws_fsx_backup.go @@ -7,12 +7,14 @@ 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" "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 resourceAwsFsxBackup() *schema.Resource { @@ -38,6 +40,7 @@ func resourceAwsFsxBackup() *schema.Resource { "file_system_id": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "kms_key_id": { Type: schema.TypeString, @@ -47,7 +50,7 @@ func resourceAwsFsxBackup() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tagsSchema(), + "tags": tagsSchemaComputed(), "tags_all": tagsSchemaComputed(), "type": { Type: schema.TypeString, @@ -110,16 +113,16 @@ func resourceAwsFsxBackupRead(d *schema.ResourceData, meta interface{}) error { ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig backup, err := finder.BackupByID(conn, d.Id()) - if err != nil { - return err - } - - if !d.IsNewResource() && backup == nil { + if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] FSx Backup (%s) not found, removing from state", d.Id()) d.SetId("") return nil } + if err != nil { + return fmt.Errorf("error reading FSx Backup (%s): %w", d.Id(), err) + } + d.Set("arn", backup.ResourceARN) d.Set("type", backup.Type) @@ -154,12 +157,12 @@ func resourceAwsFsxBackupDelete(d *schema.ResourceData, meta interface{}) error } _, err := conn.DeleteBackup(request) - if isAWSErr(err, fsx.ErrCodeBackupNotFound, "") { - return nil - } if err != nil { - return fmt.Errorf("Error deleting FSx Backup: %w", err) + if tfawserr.ErrCodeEquals(err, fsx.ErrCodeBackupNotFound) { + return nil + } + return fmt.Errorf("Error deleting FSx Backup (%s): %w", d.Id(), err) } log.Println("[DEBUG] Waiting for filesystem to delete") diff --git a/aws/resource_aws_fsx_backup_test.go b/aws/resource_aws_fsx_backup_test.go index 07972f97db3..7e3a3cd289e 100644 --- a/aws/resource_aws_fsx_backup_test.go +++ b/aws/resource_aws_fsx_backup_test.go @@ -117,7 +117,29 @@ func TestAccAWSFsxBackup_disappears(t *testing.T) { }) } -func TestAccAWSFsxBackup_Tags(t *testing.T) { +func TestAccAWSFsxBackup_disappears_filesystem(t *testing.T) { + var backup fsx.Backup + resourceName := "aws_fsx_backup.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxBackupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxBackupConfigBasic(), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + testAccCheckResourceDisappears(testAccProvider, resourceAwsFsxLustreFileSystem(), "aws_fsx_lustre_file_system.test"), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSFsxBackup_tags(t *testing.T) { var backup fsx.Backup resourceName := "aws_fsx_backup.test" @@ -161,6 +183,33 @@ func TestAccAWSFsxBackup_Tags(t *testing.T) { }) } +func TestAccAWSFsxBackup_implictTags(t *testing.T) { + var backup fsx.Backup + resourceName := "aws_fsx_backup.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckFsxBackupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAwsFsxBackupConfigImplictTags("key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckFsxBackupExists(resourceName, &backup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckFsxBackupExists(resourceName string, fs *fsx.Backup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -260,3 +309,33 @@ resource "aws_fsx_backup" "test" { } `, tagKey1, tagValue1, tagKey2, tagValue2)) } + +func testAccAwsFsxBackupConfigImplictTags(tagKey1, tagValue1 string) string { + return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" +} + +resource "aws_subnet" "test1" { + vpc_id = aws_vpc.test.id + cidr_block = "10.0.1.0/24" + availability_zone = data.aws_availability_zones.available.names[0] +} + +resource "aws_fsx_lustre_file_system" "test" { + storage_capacity = 1200 + subnet_ids = [aws_subnet.test1.id] + deployment_type = "PERSISTENT_1" + per_unit_storage_throughput = 50 + copy_tags_to_backups = true + + tags = { + %[1]q = %[2]q + } +} + +resource "aws_fsx_backup" "test" { + file_system_id = aws_fsx_lustre_file_system.test.id +} +`, tagKey1, tagValue1)) +} From f6b8ced89d43104159c0402d9473f0c64667d896 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 13:21:03 +0300 Subject: [PATCH 04/11] docs --- website/docs/r/fsx_backup.html.markdown | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 website/docs/r/fsx_backup.html.markdown diff --git a/website/docs/r/fsx_backup.html.markdown b/website/docs/r/fsx_backup.html.markdown new file mode 100644 index 00000000000..04579908c61 --- /dev/null +++ b/website/docs/r/fsx_backup.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: "File System (FSx)" +layout: "aws" +page_title: "AWS: aws_fsx_backup" +description: |- + Manages a FSx Backup. +--- + +# Resource: aws_fsx_backup + +Provides a FSx backup resource. + +## Example Usage + +```terraform +resource "aws_fsx_backup" "example" { + file_system_id = aws_fsx_lustre_file_system.example.id +} + +resource "aws_fsx_lustre_file_system" "example" { + storage_capacity = 1200 + subnet_ids = [aws_subnet.example.id] + deployment_type = "PERSISTENT_1" + per_unit_storage_throughput = 50 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `file_system_id` - (Required) The ID of the file system to back up. +* `tags` - (Optional) A map of tags to assign to the file system. 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. If you have set `copy_tags_to_backups` to true, and you specify one or more tags, no existing file system tags are copied from the file system to the backup. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - Amazon Resource Name of the backup. +* `id` - Identifier of the backup, e.g. `fs-12345678` +* `kms_key_id` - The ID of the AWS Key Management Service (AWS KMS) key used to encrypt the backup of the Amazon FSx file system's data at rest. +* `owner_id` - AWS account identifier that created the file system. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). +* `type` - The type of the file system backup. + +## Timeouts + +`aws_fsx_backup` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) +configuration options: + +* `create` - (Default `30m`) How long to wait for the backup to be created. +* `delete` - (Default `30m`) How long to wait for the backup to be deleted. + +## Import + +FSx Backups can be imported using the `id`, e.g. + +``` +$ terraform import aws_fsx_backup.example fs-543ab12b1ca672f33 +``` From 7db5f37aba9acf3ca9882b86f2eb7c5910006220 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 13:23:00 +0300 Subject: [PATCH 05/11] changelog --- .changelog/20569.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/20569.txt diff --git a/.changelog/20569.txt b/.changelog/20569.txt new file mode 100644 index 00000000000..bb5efca3619 --- /dev/null +++ b/.changelog/20569.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_fsx_backup +``` \ No newline at end of file From fe1c227c9aa2cfcb9a031914b540d4e051866ad1 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 13:24:44 +0300 Subject: [PATCH 06/11] docs --- website/docs/r/fsx_backup.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/fsx_backup.html.markdown b/website/docs/r/fsx_backup.html.markdown index 04579908c61..67e57a18ca3 100644 --- a/website/docs/r/fsx_backup.html.markdown +++ b/website/docs/r/fsx_backup.html.markdown @@ -48,8 +48,8 @@ In addition to all arguments above, the following attributes are exported: `aws_fsx_backup` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options: -* `create` - (Default `30m`) How long to wait for the backup to be created. -* `delete` - (Default `30m`) How long to wait for the backup to be deleted. +* `create` - (Default `10m`) How long to wait for the backup to be created. +* `delete` - (Default `10m`) How ålong to wait for the backup to be deleted. ## Import From 45ebb53cb06935bf634ca1fa9e5fab8b9ad9f12f Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 13:26:13 +0300 Subject: [PATCH 07/11] docs --- aws/resource_aws_fsx_backup_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_fsx_backup_test.go b/aws/resource_aws_fsx_backup_test.go index 7e3a3cd289e..128dd16f84b 100644 --- a/aws/resource_aws_fsx_backup_test.go +++ b/aws/resource_aws_fsx_backup_test.go @@ -331,7 +331,7 @@ resource "aws_fsx_lustre_file_system" "test" { tags = { %[1]q = %[2]q - } + } } resource "aws_fsx_backup" "test" { From 8786d822ebc59ca0f56ce2d7dfd3879388edb820 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 14 Aug 2021 14:53:05 +0300 Subject: [PATCH 08/11] sweeper --- aws/resource_aws_fsx_backup_test.go | 85 ++++++++++++++--------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/aws/resource_aws_fsx_backup_test.go b/aws/resource_aws_fsx_backup_test.go index 128dd16f84b..a82439c0776 100644 --- a/aws/resource_aws_fsx_backup_test.go +++ b/aws/resource_aws_fsx_backup_test.go @@ -2,70 +2,69 @@ package aws import ( "fmt" + "log" "regexp" "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/fsx" + multierror "github.com/hashicorp/go-multierror" "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() { -// resource.AddTestSweepers("aws_fsx_lustre_file_system", &resource.Sweeper{ -// Name: "aws_fsx_lustre_file_system", -// F: testSweepFSXBackups, -// }) -// } - -// func testSweepFSXBackups(region string) error { -// client, err := sharedClientForRegion(region) +func init() { + resource.AddTestSweepers("aws_fsx_backup", &resource.Sweeper{ + Name: "aws_fsx_backup", + F: testSweepFSXBackups, + }) +} -// if err != nil { -// return fmt.Errorf("error getting client: %s", err) -// } +func testSweepFSXBackups(region string) error { + client, err := sharedClientForRegion(region) -// conn := client.(*AWSClient).fsxconn -// sweepResources := make([]*testSweepResource, 0) -// var errs *multierror.Error -// input := &fsx.DescribeBackupsInput{} + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } -// err = conn.DescribeBackupsPages(input, func(page *fsx.DescribeBackupsOutput, lastPage bool) bool { -// if page == nil { -// return !lastPage -// } + conn := client.(*AWSClient).fsxconn + sweepResources := make([]*testSweepResource, 0) + var errs *multierror.Error + input := &fsx.DescribeBackupsInput{} -// for _, fs := range page.Backups { -// if aws.StringValue(fs.BackupType) != fsx.BackupTypeLustre { -// continue -// } + err = conn.DescribeBackupsPages(input, func(page *fsx.DescribeBackupsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } -// r := resourceAwsFsxBackup() -// d := r.Data(nil) -// d.SetId(aws.StringValue(fs.BackupId)) + for _, fs := range page.Backups { + r := resourceAwsFsxBackup() + d := r.Data(nil) + d.SetId(aws.StringValue(fs.BackupId)) -// sweepResources = append(sweepResources, NewTestSweepResource(r, d, client)) -// } + sweepResources = append(sweepResources, NewTestSweepResource(r, d, client)) + } -// return !lastPage -// }) + return !lastPage + }) -// if err != nil { -// errs = multierror.Append(errs, fmt.Errorf("error listing FSx Lustre Filesystems for %s: %w", region, err)) -// } + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("error listing FSx Backups 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)) -// } + if err = testSweepResourceOrchestrator(sweepResources); err != nil { + errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Backups for %s: %w", region, err)) + } -// if testSweepSkipSweepError(errs.ErrorOrNil()) { -// log.Printf("[WARN] Skipping FSx Lustre Filesystems sweep for %s: %s", region, errs) -// return nil -// } + if testSweepSkipSweepError(errs.ErrorOrNil()) { + log.Printf("[WARN] Skipping FSx Backups sweep for %s: %s", region, errs) + return nil + } -// return errs.ErrorOrNil() -// } + return errs.ErrorOrNil() +} func TestAccAWSFsxBackup_basic(t *testing.T) { var backup fsx.Backup From c01cb04588266c3d545d25b4586ac54e8c0807ac Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Tue, 17 Aug 2021 16:17:36 +0300 Subject: [PATCH 09/11] Apply suggestions from code review Co-authored-by: Kit Ewbank --- aws/resource_aws_fsx_backup.go | 5 +++-- website/docs/r/fsx_backup.html.markdown | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go index e085bc0b32a..31aec09c579 100644 --- a/aws/resource_aws_fsx_backup.go +++ b/aws/resource_aws_fsx_backup.go @@ -156,18 +156,19 @@ func resourceAwsFsxBackupDelete(d *schema.ResourceData, meta interface{}) error BackupId: aws.String(d.Id()), } + log.Printf("[INFO] Deleting FSx Backup: %s", d.Id()) _, err := conn.DeleteBackup(request) if err != nil { if tfawserr.ErrCodeEquals(err, fsx.ErrCodeBackupNotFound) { return nil } - return fmt.Errorf("Error deleting FSx Backup (%s): %w", d.Id(), err) + return fmt.Errorf("error deleting FSx Backup (%s): %w", d.Id(), err) } log.Println("[DEBUG] Waiting for filesystem 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) + return fmt.Errorf("error waiting for FSx Backup (%s) to deleted: %w", d.Id(), err) } return nil diff --git a/website/docs/r/fsx_backup.html.markdown b/website/docs/r/fsx_backup.html.markdown index 67e57a18ca3..cc94025ee0e 100644 --- a/website/docs/r/fsx_backup.html.markdown +++ b/website/docs/r/fsx_backup.html.markdown @@ -8,7 +8,7 @@ description: |- # Resource: aws_fsx_backup -Provides a FSx backup resource. +Provides a FSx Backup resource. ## Example Usage From f47f2eb294fd9c8d7427a8b31c54e57f3d501501 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Tue, 17 Aug 2021 16:18:20 +0300 Subject: [PATCH 10/11] Apply suggestions from code review Co-authored-by: Kit Ewbank --- aws/resource_aws_fsx_backup.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_fsx_backup.go b/aws/resource_aws_fsx_backup.go index 31aec09c579..7c8b4b8aa41 100644 --- a/aws/resource_aws_fsx_backup.go +++ b/aws/resource_aws_fsx_backup.go @@ -80,14 +80,14 @@ func resourceAwsFsxBackupCreate(d *schema.ResourceData, meta interface{}) error result, err := conn.CreateBackup(input) if err != nil { - return fmt.Errorf("Error creating FSx Backup: %w", err) + return fmt.Errorf("error creating FSx Backup: %w", err) } d.SetId(aws.StringValue(result.Backup.BackupId)) log.Println("[DEBUG] Waiting for FSx backup to become available") if _, err := waiter.BackupAvailable(conn, d.Id()); err != nil { - return fmt.Errorf("error waiting for FSx backup (%s) to be available: %w", d.Id(), err) + return fmt.Errorf("error waiting for FSx Backup (%s) to be available: %w", d.Id(), err) } return resourceAwsFsxBackupRead(d, meta) @@ -100,7 +100,7 @@ func resourceAwsFsxBackupUpdate(d *schema.ResourceData, meta interface{}) error o, n := d.GetChange("tags_all") if err := keyvaluetags.FsxUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { - return fmt.Errorf("error updating FSx Lustre File System (%s) tags: %w", d.Get("arn").(string), err) + return fmt.Errorf("error updating FSx Backup (%s) tags: %w", d.Get("arn").(string), err) } } @@ -129,9 +129,7 @@ func resourceAwsFsxBackupRead(d *schema.ResourceData, meta interface{}) error { fs := backup.FileSystem d.Set("file_system_id", fs.FileSystemId) - if backup.KmsKeyId != nil { - d.Set("kms_key_id", backup.KmsKeyId) - } + d.Set("kms_key_id", backup.KmsKeyId) d.Set("owner_id", backup.OwnerId) From 1e5ba0402a9bf8ad091e52b7741ff04af72bc26d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Aug 2021 09:35:13 -0400 Subject: [PATCH 11/11] Update website/docs/r/fsx_backup.html.markdown --- website/docs/r/fsx_backup.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/fsx_backup.html.markdown b/website/docs/r/fsx_backup.html.markdown index cc94025ee0e..c5dc53c76a7 100644 --- a/website/docs/r/fsx_backup.html.markdown +++ b/website/docs/r/fsx_backup.html.markdown @@ -49,7 +49,7 @@ In addition to all arguments above, the following attributes are exported: configuration options: * `create` - (Default `10m`) How long to wait for the backup to be created. -* `delete` - (Default `10m`) How ålong to wait for the backup to be deleted. +* `delete` - (Default `10m`) How long to wait for the backup to be deleted. ## Import