From 44ab09d436fbf089fd9f5169d603dec21150e876 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 6 Mar 2021 16:23:05 +0200 Subject: [PATCH 01/10] refactor to use waiter + attributes --- aws/internal/service/efs/waiter/status.go | 23 +++ aws/internal/service/efs/waiter/waiter.go | 58 +++++++- aws/resource_aws_efs_file_system.go | 165 ++++++---------------- aws/resource_aws_efs_file_system_test.go | 41 ++---- 4 files changed, 131 insertions(+), 156 deletions(-) diff --git a/aws/internal/service/efs/waiter/status.go b/aws/internal/service/efs/waiter/status.go index d48fb58c92b5..97d4f7d1612d 100644 --- a/aws/internal/service/efs/waiter/status.go +++ b/aws/internal/service/efs/waiter/status.go @@ -28,3 +28,26 @@ func AccessPointLifeCycleState(conn *efs.EFS, accessPointId string) resource.Sta return mt, aws.StringValue(mt.LifeCycleState), nil } } + +// FileSystemLifeCycleState fetches the Access Point and its LifecycleState +func FileSystemLifeCycleState(conn *efs.EFS, fileSystemID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + input := &efs.DescribeFileSystemsInput{ + FileSystemId: aws.String(fileSystemID), + } + + output, err := conn.DescribeFileSystems(input) + + if err != nil { + return nil, "", err + } + + if output == nil || len(output.FileSystems) == 0 || output.FileSystems[0] == nil { + return nil, "", nil + } + + mt := output.FileSystems[0] + + return mt, aws.StringValue(mt.LifeCycleState), nil + } +} diff --git a/aws/internal/service/efs/waiter/waiter.go b/aws/internal/service/efs/waiter/waiter.go index 71db067975ae..ed4c94309b42 100644 --- a/aws/internal/service/efs/waiter/waiter.go +++ b/aws/internal/service/efs/waiter/waiter.go @@ -9,16 +9,22 @@ import ( const ( // Maximum amount of time to wait for an Operation to return Success - AccessPointCreatedTimeout = 10 * time.Minute - AccessPointDeletedTimeout = 10 * time.Minute + AccessPointCreatedTimeout = 10 * time.Minute + AccessPointDeletedTimeout = 10 * time.Minute + FileSystemAvailableTimeout = 10 * time.Minute + FileSystemAvailableDelayTimeout = 2 * time.Second + FileSystemAvailableMinTimeout = 3 * time.Second + FileSystemDeletedTimeout = 10 * time.Minute + FileSystemDeletedDelayTimeout = 2 * time.Second + FileSystemDeletedMinTimeout = 3 * time.Second ) // AccessPointCreated waits for an Operation to return Success -func AccessPointCreated(conn *efs.EFS, accessPointId string) (*efs.AccessPointDescription, error) { +func AccessPointCreated(conn *efs.EFS, fileSystemID string) (*efs.AccessPointDescription, error) { stateConf := &resource.StateChangeConf{ Pending: []string{efs.LifeCycleStateCreating}, Target: []string{efs.LifeCycleStateAvailable}, - Refresh: AccessPointLifeCycleState(conn, accessPointId), + Refresh: AccessPointLifeCycleState(conn, fileSystemID), Timeout: AccessPointCreatedTimeout, } @@ -32,11 +38,11 @@ func AccessPointCreated(conn *efs.EFS, accessPointId string) (*efs.AccessPointDe } // AccessPointDelete waits for an Access Point to return Deleted -func AccessPointDeleted(conn *efs.EFS, accessPointId string) (*efs.AccessPointDescription, error) { +func AccessPointDeleted(conn *efs.EFS, fileSystemID string) (*efs.AccessPointDescription, error) { stateConf := &resource.StateChangeConf{ Pending: []string{efs.LifeCycleStateAvailable, efs.LifeCycleStateDeleting, efs.LifeCycleStateDeleted}, Target: []string{}, - Refresh: AccessPointLifeCycleState(conn, accessPointId), + Refresh: AccessPointLifeCycleState(conn, fileSystemID), Timeout: AccessPointDeletedTimeout, } @@ -48,3 +54,43 @@ func AccessPointDeleted(conn *efs.EFS, accessPointId string) (*efs.AccessPointDe return nil, err } + +// FileSystemAvailable waits for an Operation to return Available +func FileSystemAvailable(conn *efs.EFS, fileSystemID string) (*efs.FileSystemDescription, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{efs.LifeCycleStateCreating, efs.LifeCycleStateUpdating}, + Target: []string{efs.LifeCycleStateAvailable}, + Refresh: FileSystemLifeCycleState(conn, fileSystemID), + Timeout: FileSystemAvailableTimeout, + Delay: FileSystemAvailableDelayTimeout, + MinTimeout: FileSystemAvailableMinTimeout, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*efs.FileSystemDescription); ok { + return output, err + } + + return nil, err +} + +// FileSystemDeleted waits for an Operation to return Deleted +func FileSystemDeleted(conn *efs.EFS, fileSystemID string) (*efs.FileSystemDescription, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{efs.LifeCycleStateAvailable, efs.LifeCycleStateDeleting}, + Target: []string{}, + Refresh: FileSystemLifeCycleState(conn, fileSystemID), + Timeout: FileSystemDeletedTimeout, + Delay: FileSystemDeletedDelayTimeout, + MinTimeout: FileSystemDeletedMinTimeout, + } + + outputRaw, err := stateConf.WaitForState() + + if output, ok := outputRaw.(*efs.FileSystemDescription); ok { + return output, err + } + + return nil, err +} diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 3ee30becd2b8..ab3ad210f48c 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -4,15 +4,14 @@ import ( "errors" "fmt" "log" - "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/efs" "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" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/efs/waiter" ) func resourceAwsEfsFileSystem() *schema.Resource { @@ -41,14 +40,11 @@ func resourceAwsEfsFileSystem() *schema.Resource { }, "performance_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - efs.PerformanceModeGeneralPurpose, - efs.PerformanceModeMaxIo, - }, false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(efs.PerformanceMode_Values(), false), }, "encrypted": { @@ -75,17 +71,21 @@ func resourceAwsEfsFileSystem() *schema.Resource { Type: schema.TypeFloat, Optional: true, }, - + "number_of_mount_targets": { + Type: schema.TypeInt, + Computed: true, + }, + "owner_id": { + Type: schema.TypeString, + Computed: true, + }, "tags": tagsSchema(), "throughput_mode": { - Type: schema.TypeString, - Optional: true, - Default: efs.ThroughputModeBursting, - ValidateFunc: validation.StringInSlice([]string{ - efs.ThroughputModeBursting, - efs.ThroughputModeProvisioned, - }, false), + Type: schema.TypeString, + Optional: true, + Default: efs.ThroughputModeBursting, + ValidateFunc: validation.StringInSlice(efs.ThroughputMode_Values(), false), }, "lifecycle_policy": { @@ -95,15 +95,9 @@ func resourceAwsEfsFileSystem() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "transition_to_ia": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - efs.TransitionToIARulesAfter7Days, - efs.TransitionToIARulesAfter14Days, - efs.TransitionToIARulesAfter30Days, - efs.TransitionToIARulesAfter60Days, - efs.TransitionToIARulesAfter90Days, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(efs.TransitionToIARules_Values(), false), }, }, }, @@ -155,25 +149,16 @@ func resourceAwsEfsFileSystemCreate(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] EFS file system create options: %#v", *createOpts) fs, err := conn.CreateFileSystem(createOpts) if err != nil { - return fmt.Errorf("Error creating EFS file system: %s", err) + return fmt.Errorf("Error creating EFS file system: %w", err) } d.SetId(aws.StringValue(fs.FileSystemId)) log.Printf("[INFO] EFS file system ID: %s", d.Id()) - stateConf := &resource.StateChangeConf{ - Pending: []string{efs.LifeCycleStateCreating}, - Target: []string{efs.LifeCycleStateAvailable}, - Refresh: resourceEfsFileSystemCreateUpdateRefreshFunc(d.Id(), conn), - Timeout: 10 * time.Minute, - Delay: 2 * time.Second, - MinTimeout: 3 * time.Second, + if _, err := waiter.FileSystemAvailable(conn, d.Id()); err != nil { + return fmt.Errorf("error waiting for EFS file system (%s) to be available: %w", d.Id(), err) } - _, err = stateConf.WaitForState() - if err != nil { - return fmt.Errorf("Error waiting for EFS file system (%q) to create: %s", d.Id(), err) - } log.Printf("[DEBUG] EFS file system %q created.", d.Id()) _, hasLifecyclePolicy := d.GetOk("lifecycle_policy") @@ -208,21 +193,11 @@ func resourceAwsEfsFileSystemUpdate(d *schema.ResourceData, meta interface{}) er _, err := conn.UpdateFileSystem(input) if err != nil { - return fmt.Errorf("error updating EFS File System %q: %s", d.Id(), err) + return fmt.Errorf("error updating EFS File System %q: %w", d.Id(), err) } - stateConf := &resource.StateChangeConf{ - Pending: []string{efs.LifeCycleStateUpdating}, - Target: []string{efs.LifeCycleStateAvailable}, - Refresh: resourceEfsFileSystemCreateUpdateRefreshFunc(d.Id(), conn), - Timeout: 10 * time.Minute, - Delay: 2 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, err = stateConf.WaitForState() - if err != nil { - return fmt.Errorf("error waiting for EFS file system (%q) to update: %s", d.Id(), err) + if _, err := waiter.FileSystemAvailable(conn, d.Id()); err != nil { + return fmt.Errorf("error waiting for EFS file system (%s) to be available: %w", d.Id(), err) } } @@ -250,7 +225,7 @@ func resourceAwsEfsFileSystemUpdate(d *schema.ResourceData, meta interface{}) er o, n := d.GetChange("tags") if err := keyvaluetags.EfsUpdateTags(conn, d.Id(), o, n); err != nil { - return fmt.Errorf("error updating EFS file system (%s) tags: %s", d.Id(), err) + return fmt.Errorf("error updating EFS file system (%s) tags: %w", d.Id(), err) } } @@ -285,29 +260,23 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro } } if fs == nil { - log.Printf("[WARN] EFS (%s) not found, removing from state", d.Id()) + log.Printf("[WARN] EFS File System (%s) not found, removing from state", d.Id()) d.SetId("") return nil } - fsARN := arn.ARN{ - AccountID: meta.(*AWSClient).accountid, - Partition: meta.(*AWSClient).partition, - Region: meta.(*AWSClient).region, - Resource: fmt.Sprintf("file-system/%s", aws.StringValue(fs.FileSystemId)), - Service: "elasticfilesystem", - }.String() - - d.Set("arn", fsARN) + d.Set("arn", fs.FileSystemArn) d.Set("creation_token", fs.CreationToken) d.Set("encrypted", fs.Encrypted) d.Set("kms_key_id", fs.KmsKeyId) d.Set("performance_mode", fs.PerformanceMode) d.Set("provisioned_throughput_in_mibps", fs.ProvisionedThroughputInMibps) d.Set("throughput_mode", fs.ThroughputMode) + d.Set("owner_id", fs.OwnerId) + d.Set("number_of_mount_targets", fs.NumberOfMountTargets) if err := d.Set("tags", keyvaluetags.EfsKeyValueTags(fs.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return fmt.Errorf("error setting tags: %w", err) } d.Set("dns_name", meta.(*AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) @@ -316,12 +285,12 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro FileSystemId: fs.FileSystemId, }) if err != nil { - return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %s", + return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %w", aws.StringValue(fs.FileSystemId), err) } if err := d.Set("lifecycle_policy", flattenEfsFileSystemLifecyclePolicies(res.LifecyclePolicies)); err != nil { - return fmt.Errorf("error setting lifecycle_policy: %s", err) + return fmt.Errorf("error setting lifecycle_policy: %w", err) } return nil @@ -335,50 +304,22 @@ func resourceAwsEfsFileSystemDelete(d *schema.ResourceData, meta interface{}) er FileSystemId: aws.String(d.Id()), }) if err != nil { + if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") { + return nil + } return fmt.Errorf("Error delete file system: %s with err %s", d.Id(), err.Error()) } - err = waitForDeleteEfsFileSystem(conn, d.Id(), 10*time.Minute) - if err != nil { - return fmt.Errorf("Error waiting for EFS file system (%q) to delete: %w", d.Id(), err) + if _, err := waiter.FileSystemDeleted(conn, d.Id()); err != nil { + if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") { + return nil + } + return fmt.Errorf("error waiting for EFS access point (%s) deletion: %w", d.Id(), err) } - log.Printf("[DEBUG] EFS file system %q deleted.", d.Id()) - return nil } -func waitForDeleteEfsFileSystem(conn *efs.EFS, id string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{"available", "deleting"}, - Target: []string{}, - Refresh: func() (interface{}, string, error) { - resp, err := conn.DescribeFileSystems(&efs.DescribeFileSystemsInput{ - FileSystemId: aws.String(id), - }) - if err != nil { - if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") { - return nil, "", nil - } - return nil, "error", err - } - - if hasEmptyFileSystems(resp) { - return nil, "", nil - } - - fs := resp.FileSystems[0] - log.Printf("[DEBUG] current status of %q: %q", *fs.FileSystemId, *fs.LifeCycleState) - return fs, *fs.LifeCycleState, nil - }, - Timeout: timeout, - Delay: 2 * time.Second, - MinTimeout: 3 * time.Second, - } - _, err := stateConf.WaitForState() - return err -} - func hasEmptyFileSystems(fs *efs.DescribeFileSystemsOutput) bool { if fs != nil && len(fs.FileSystems) > 0 { return false @@ -386,26 +327,6 @@ func hasEmptyFileSystems(fs *efs.DescribeFileSystemsOutput) bool { return true } -func resourceEfsFileSystemCreateUpdateRefreshFunc(id string, conn *efs.EFS) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - resp, err := conn.DescribeFileSystems(&efs.DescribeFileSystemsInput{ - FileSystemId: aws.String(id), - }) - if err != nil { - return nil, "error", err - } - - if hasEmptyFileSystems(resp) { - return nil, "not-found", fmt.Errorf("EFS file system %q could not be found.", id) - } - - fs := resp.FileSystems[0] - state := aws.StringValue(fs.LifeCycleState) - log.Printf("[DEBUG] current status of %q: %q", id, state) - return fs, state, nil - } -} - func flattenEfsFileSystemLifecyclePolicies(apiObjects []*efs.LifecyclePolicy) []interface{} { var tfList []interface{} diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 250fbe618efc..7bd771c15c2d 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -5,11 +5,10 @@ import ( "log" "regexp" "testing" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/efs" - multierror "github.com/hashicorp/go-multierror" + "github.com/hashicorp/go-multierror" "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" @@ -32,6 +31,7 @@ func testSweepEfsFileSystems(region string) error { return fmt.Errorf("error getting client: %s", err) } conn := client.(*AWSClient).efsconn + var sweeperErrs *multierror.Error var errors error input := &efs.DescribeFileSystemsInput{} @@ -41,17 +41,14 @@ func testSweepEfsFileSystems(region string) error { log.Printf("[INFO] Deleting EFS File System: %s", id) - _, err := conn.DeleteFileSystem(&efs.DeleteFileSystemInput{ - FileSystemId: filesystem.FileSystemId, - }) - if err != nil { - errors = multierror.Append(errors, fmt.Errorf("error deleting EFS File System %q: %w", id, err)) - continue - } + r := resourceAwsEfsFileSystem() + d := r.Data(nil) + d.SetId(id) + err := r.Delete(d, client) - err = waitForDeleteEfsFileSystem(conn, id, 10*time.Minute) if err != nil { - errors = multierror.Append(fmt.Errorf("error waiting for EFS File System %q to delete: %w", id, err)) + log.Printf("[ERROR] %s", err) + sweeperErrs = multierror.Append(sweeperErrs, err) continue } } @@ -61,7 +58,7 @@ func testSweepEfsFileSystems(region string) error { errors = multierror.Append(errors, fmt.Errorf("error retrieving EFS File Systems: %w", err)) } - return errors + return sweeperErrs.ErrorOrNil() } func TestResourceAWSEFSFileSystem_hasEmptyFileSystems(t *testing.T) { @@ -103,6 +100,8 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "throughput_mode", efs.ThroughputModeBursting), testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemPerformanceMode(resourceName, "generalPurpose"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testAccMatchResourceAttrAccountID(resourceName, "owner_id"), ), }, { @@ -434,7 +433,7 @@ func TestAccAWSEFSFileSystem_lifecyclePolicy_removal(t *testing.T) { func TestAccAWSEFSFileSystem_disappears(t *testing.T) { var desc efs.FileSystemDescription resourceName := "aws_efs_file_system.test" - rName := acctest.RandomWithPrefix("tf-acc-disappears") + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -445,7 +444,7 @@ func TestAccAWSEFSFileSystem_disappears(t *testing.T) { Config: testAccAWSEFSFileSystemConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckEfsFileSystem(resourceName, &desc), - testAccCheckEfsFileSystemDisappears(&desc), + testAccCheckResourceDisappears(testAccProvider, resourceAwsEfsFileSystem(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -508,20 +507,6 @@ func testAccCheckEfsFileSystem(resourceID string, fDesc *efs.FileSystemDescripti } } -func testAccCheckEfsFileSystemDisappears(fDesc *efs.FileSystemDescription) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).efsconn - - input := &efs.DeleteFileSystemInput{ - FileSystemId: fDesc.FileSystemId, - } - - _, err := conn.DeleteFileSystem(input) - - return err - } -} - func testAccCheckEfsCreationToken(resourceID string, expectedToken string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceID] From b53b3e82d05371fe438a1fd650a95a2cd211d4b8 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 6 Mar 2021 16:24:37 +0200 Subject: [PATCH 02/10] add docs --- website/docs/r/efs_file_system.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/efs_file_system.html.markdown b/website/docs/r/efs_file_system.html.markdown index 13d99be706e6..d6fc3249242a 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -64,6 +64,8 @@ In addition to all arguments above, the following attributes are exported: * `arn` - Amazon Resource Name of the file system. * `id` - The ID that identifies the file system (e.g. fs-ccfc0d65). * `dns_name` - The DNS name for the filesystem per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html). +* `owner_id` - The AWS account that created the file system. If the file system was createdby an IAM user, the parent account to which the user belongs is the owner. +* `number_of_mount_targets` - The current number of mount targets that the file system has. ## Import From 2753a955ac4a6518cb2aabbbc335e82b471d32d4 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 6 Mar 2021 17:01:55 +0200 Subject: [PATCH 03/10] add size in bytes --- aws/resource_aws_efs_file_system.go | 44 ++++++++++++++++++++ aws/resource_aws_efs_file_system_test.go | 4 ++ website/docs/r/efs_file_system.html.markdown | 7 ++++ 3 files changed, 55 insertions(+) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index ab3ad210f48c..200ea685fcc3 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -102,6 +102,26 @@ func resourceAwsEfsFileSystem() *schema.Resource { }, }, }, + "size_in_bytes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "value": { + Type: schema.TypeInt, + Computed: true, + }, + "value_in_ia": { + Type: schema.TypeInt, + Computed: true, + }, + "value_in_standard": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, }, } } @@ -279,6 +299,10 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("error setting tags: %w", err) } + if err := d.Set("size_in_bytes", flattenEfsFileSystemSizeInBytes(fs.SizeInBytes)); err != nil { + return fmt.Errorf("error setting size_in_bytes: %w", err) + } + d.Set("dns_name", meta.(*AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) res, err := conn.DescribeLifecycleConfiguration(&efs.DescribeLifecycleConfigurationInput{ @@ -368,3 +392,23 @@ func expandEfsFileSystemLifecyclePolicies(tfList []interface{}) []*efs.Lifecycle return apiObjects } + +func flattenEfsFileSystemSizeInBytes(sizeInBytes *efs.FileSystemSize) []interface{} { + if sizeInBytes == nil { + return []interface{}{} + } + + m := map[string]interface{}{ + "value": aws.Int64Value(sizeInBytes.Value), + } + + if sizeInBytes.ValueInIA != nil { + m["value_in_ia"] = aws.Int64Value(sizeInBytes.ValueInIA) + } + + if sizeInBytes.ValueInStandard != nil { + m["value_in_standard"] = aws.Int64Value(sizeInBytes.ValueInStandard) + } + + return []interface{}{m} +} diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 7bd771c15c2d..74906edbbe50 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -101,6 +101,10 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { testAccCheckEfsFileSystem(resourceName, &desc), testAccCheckEfsFileSystemPerformanceMode(resourceName, "generalPurpose"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(resourceName, "size_in_bytes.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "size_in_bytes.0.value"), + resource.TestCheckResourceAttrSet(resourceName, "size_in_bytes.0.value_in_ia"), + resource.TestCheckResourceAttrSet(resourceName, "size_in_bytes.0.value_in_standard"), testAccMatchResourceAttrAccountID(resourceName, "owner_id"), ), }, diff --git a/website/docs/r/efs_file_system.html.markdown b/website/docs/r/efs_file_system.html.markdown index d6fc3249242a..e59a4f878dbb 100644 --- a/website/docs/r/efs_file_system.html.markdown +++ b/website/docs/r/efs_file_system.html.markdown @@ -66,6 +66,13 @@ In addition to all arguments above, the following attributes are exported: * `dns_name` - The DNS name for the filesystem per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html). * `owner_id` - The AWS account that created the file system. If the file system was createdby an IAM user, the parent account to which the user belongs is the owner. * `number_of_mount_targets` - The current number of mount targets that the file system has. +* `size_in_bytes` - The latest known metered size (in bytes) of data stored in the file system, the value is not the exact size that the file system was at any point in time. See [Size In Bytes](#size-in-bytes). + +### Size In Bytes + +* `value` - The latest known metered size (in bytes) of data stored in the file system. +* `value_in_ia` - The latest known metered size (in bytes) of data stored in the Infrequent Access storage class. +* `value_in_standard` - The latest known metered size (in bytes) of data stored in the Standard storage class. ## Import From 2756c00de94709f498b3590bc2c7504df9dc6714 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 6 Mar 2021 17:06:44 +0200 Subject: [PATCH 04/10] changelog --- .changelog/17969.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17969.txt diff --git a/.changelog/17969.txt b/.changelog/17969.txt new file mode 100644 index 000000000000..40a3386fda36 --- /dev/null +++ b/.changelog/17969.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_efs_file_system: Add `number_of_mount_targets`, `size_in_bytes` and `owner_id` attributes +``` \ No newline at end of file From cbb60cccd6aee178f3784282421964d8340b62f4 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 6 Mar 2021 17:06:50 +0200 Subject: [PATCH 05/10] fmt --- aws/internal/service/efs/waiter/waiter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/internal/service/efs/waiter/waiter.go b/aws/internal/service/efs/waiter/waiter.go index ed4c94309b42..fd065e5c89d4 100644 --- a/aws/internal/service/efs/waiter/waiter.go +++ b/aws/internal/service/efs/waiter/waiter.go @@ -20,11 +20,11 @@ const ( ) // AccessPointCreated waits for an Operation to return Success -func AccessPointCreated(conn *efs.EFS, fileSystemID string) (*efs.AccessPointDescription, error) { +func AccessPointCreated(conn *efs.EFS, accessPointId string) (*efs.AccessPointDescription, error) { stateConf := &resource.StateChangeConf{ Pending: []string{efs.LifeCycleStateCreating}, Target: []string{efs.LifeCycleStateAvailable}, - Refresh: AccessPointLifeCycleState(conn, fileSystemID), + Refresh: AccessPointLifeCycleState(conn, accessPointId), Timeout: AccessPointCreatedTimeout, } @@ -38,11 +38,11 @@ func AccessPointCreated(conn *efs.EFS, fileSystemID string) (*efs.AccessPointDes } // AccessPointDelete waits for an Access Point to return Deleted -func AccessPointDeleted(conn *efs.EFS, fileSystemID string) (*efs.AccessPointDescription, error) { +func AccessPointDeleted(conn *efs.EFS, accessPointId string) (*efs.AccessPointDescription, error) { stateConf := &resource.StateChangeConf{ Pending: []string{efs.LifeCycleStateAvailable, efs.LifeCycleStateDeleting, efs.LifeCycleStateDeleted}, Target: []string{}, - Refresh: AccessPointLifeCycleState(conn, fileSystemID), + Refresh: AccessPointLifeCycleState(conn, accessPointId), Timeout: AccessPointDeletedTimeout, } From 945044ff223727e0d93a4b0cb4dd6773d7ad6550 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sun, 7 Mar 2021 09:41:58 +0200 Subject: [PATCH 06/10] Update aws/resource_aws_efs_file_system.go Co-authored-by: Kit Ewbank --- aws/resource_aws_efs_file_system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 200ea685fcc3..e1f74ade2d94 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -306,7 +306,7 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro d.Set("dns_name", meta.(*AWSClient).RegionalHostname(fmt.Sprintf("%s.efs", aws.StringValue(fs.FileSystemId)))) res, err := conn.DescribeLifecycleConfiguration(&efs.DescribeLifecycleConfigurationInput{ - FileSystemId: fs.FileSystemId, + FileSystemId: aws.String(d.Id()), }) if err != nil { return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %w", From 3f6a0763fc8f923f1c8964e6f95c91f04358334e Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sun, 7 Mar 2021 09:42:05 +0200 Subject: [PATCH 07/10] Update aws/resource_aws_efs_file_system.go Co-authored-by: Kit Ewbank --- aws/resource_aws_efs_file_system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index e1f74ade2d94..5166f75d8111 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -338,7 +338,7 @@ func resourceAwsEfsFileSystemDelete(d *schema.ResourceData, meta interface{}) er if isAWSErr(err, efs.ErrCodeFileSystemNotFound, "") { return nil } - return fmt.Errorf("error waiting for EFS access point (%s) deletion: %w", d.Id(), err) + return fmt.Errorf("error waiting for EFS file system (%s) deletion: %w", d.Id(), err) } return nil From c823f2515da810ec4111e0dbaba12982070e3704 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sun, 7 Mar 2021 09:42:12 +0200 Subject: [PATCH 08/10] Update aws/resource_aws_efs_file_system.go Co-authored-by: Kit Ewbank --- aws/resource_aws_efs_file_system.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 5166f75d8111..76800d8ebbb0 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -309,8 +309,7 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro FileSystemId: aws.String(d.Id()), }) if err != nil { - return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %w", - aws.StringValue(fs.FileSystemId), err) + return fmt.Errorf("Error describing lifecycle configuration for EFS file system (%s): %w", d.Id(), err) } if err := d.Set("lifecycle_policy", flattenEfsFileSystemLifecyclePolicies(res.LifecyclePolicies)); err != nil { From eb9bb0c0f8acb19ba553e3ab15c94afc4cd3f038 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sun, 7 Mar 2021 10:04:26 +0200 Subject: [PATCH 09/10] fmt --- aws/resource_aws_efs_file_system_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws/resource_aws_efs_file_system_test.go b/aws/resource_aws_efs_file_system_test.go index 74906edbbe50..047db100e498 100644 --- a/aws/resource_aws_efs_file_system_test.go +++ b/aws/resource_aws_efs_file_system_test.go @@ -33,7 +33,6 @@ func testSweepEfsFileSystems(region string) error { conn := client.(*AWSClient).efsconn var sweeperErrs *multierror.Error - var errors error input := &efs.DescribeFileSystemsInput{} err = conn.DescribeFileSystemsPages(input, func(page *efs.DescribeFileSystemsOutput, lastPage bool) bool { for _, filesystem := range page.FileSystems { @@ -55,7 +54,7 @@ func testSweepEfsFileSystems(region string) error { return true }) if err != nil { - errors = multierror.Append(errors, fmt.Errorf("error retrieving EFS File Systems: %w", err)) + sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error retrieving EFS File Systems: %w", err)) } return sweeperErrs.ErrorOrNil() From 0ccb9981c55381374c026562cb57996526d7c320 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Thu, 11 Mar 2021 01:26:38 +0200 Subject: [PATCH 10/10] Update aws/resource_aws_efs_file_system.go Co-authored-by: Kit Ewbank --- aws/resource_aws_efs_file_system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_efs_file_system.go b/aws/resource_aws_efs_file_system.go index 76800d8ebbb0..7a90f70fe397 100644 --- a/aws/resource_aws_efs_file_system.go +++ b/aws/resource_aws_efs_file_system.go @@ -213,7 +213,7 @@ func resourceAwsEfsFileSystemUpdate(d *schema.ResourceData, meta interface{}) er _, err := conn.UpdateFileSystem(input) if err != nil { - return fmt.Errorf("error updating EFS File System %q: %w", d.Id(), err) + return fmt.Errorf("error updating EFS file system (%s): %w", d.Id(), err) } if _, err := waiter.FileSystemAvailable(conn, d.Id()); err != nil {