Skip to content

Commit

Permalink
Merge pull request hashicorp#38343 from mattburgess/fsx-awssdkv2-migr…
Browse files Browse the repository at this point in the history
…ation

fsx: Migrate to AWS SDK v2
  • Loading branch information
ewbankkit authored Jul 19, 2024
2 parents ac15f48 + 282e873 commit cc6a0f5
Show file tree
Hide file tree
Showing 43 changed files with 2,451 additions and 2,346 deletions.
11 changes: 11 additions & 0 deletions .changelog/38343.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:bug
resource/aws_fsx_openzfs_volume: Correctly set `tags` on Read
```

```release-note:bug
data-source/aws_fsx_openzfs_snapshot: Correctly set `tags` on Read
```

```release-note:bug
data-source/aws_fsx_ontap_storage_virtual_machine: Correctly set `tags` on Read
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/firehose v1.32.0
github.com/aws/aws-sdk-go-v2/service/fis v1.26.3
github.com/aws/aws-sdk-go-v2/service/fms v1.35.3
github.com/aws/aws-sdk-go-v2/service/fsx v1.47.2
github.com/aws/aws-sdk-go-v2/service/glacier v1.24.3
github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.27.0
github.com/aws/aws-sdk-go-v2/service/grafana v1.24.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ github.com/aws/aws-sdk-go-v2/service/fis v1.26.3 h1:NwddG0xUTBM2zoq4D8rotQmT2Z/S
github.com/aws/aws-sdk-go-v2/service/fis v1.26.3/go.mod h1:QmdVf0N/vrhckZLHK4x+f+u9EUuMhetsRgu1rjU1eL0=
github.com/aws/aws-sdk-go-v2/service/fms v1.35.3 h1:QeYAz3JhpkTxkS+fifDBfmgWFdSRBI21MQzN2bCO1xo=
github.com/aws/aws-sdk-go-v2/service/fms v1.35.3/go.mod h1:GXASgVouW5X/bmEgOoV/tkzJkp5ib7ZeA+YxMc5piqs=
github.com/aws/aws-sdk-go-v2/service/fsx v1.47.2 h1:EDZ4UX4c8NJl5Zm2tj1OlbVdNA0wv2xNt55L6g38Va4=
github.com/aws/aws-sdk-go-v2/service/fsx v1.47.2/go.mod h1:OKCxqzNOd8LpwsIgoWIhjTkDONHuv3uLoObiT/fbS4Q=
github.com/aws/aws-sdk-go-v2/service/glacier v1.24.3 h1:de8RU808VMx8km6t2wY3WDWigB6GqbNEcyVQRJFaIYs=
github.com/aws/aws-sdk-go-v2/service/glacier v1.24.3/go.mod h1:F/qjepwnxPHHUTK9ikZp14jLyrvB18kZ/22MmaPxtHE=
github.com/aws/aws-sdk-go-v2/service/globalaccelerator v1.27.0 h1:nlm6tZX8gwsVktDKTQe3IOagNVK1+6CGf9IpdWM6x+E=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 42 additions & 43 deletions internal/service/fsx/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/fsx"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/fsx"
awstypes "github.com/aws/aws-sdk-go-v2/service/fsx/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -82,7 +84,7 @@ func resourceBackup() *schema.Resource {

func resourceBackupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn(ctx)
conn := meta.(*conns.AWSClient).FSxClient(ctx)

input := &fsx.CreateBackupInput{
ClientRequestToken: aws.String(id.UniqueId()),
Expand All @@ -105,13 +107,13 @@ func resourceBackupCreate(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "creating FSx Backup: %s", "can only specify either file_system_id or volume_id")
}

output, err := conn.CreateBackupWithContext(ctx, input)
output, err := conn.CreateBackup(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating FSx Backup: %s", err)
}

d.SetId(aws.StringValue(output.Backup.BackupId))
d.SetId(aws.ToString(output.Backup.BackupId))

if _, err := waitBackupAvailable(ctx, conn, d.Id()); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for FSx Backup (%s) create: %s", d.Id(), err)
Expand All @@ -122,7 +124,7 @@ func resourceBackupCreate(ctx context.Context, d *schema.ResourceData, meta inte

func resourceBackupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn(ctx)
conn := meta.(*conns.AWSClient).FSxClient(ctx)

backup, err := findBackupByID(ctx, conn, d.Id())

Expand Down Expand Up @@ -162,14 +164,14 @@ func resourceBackupUpdate(ctx context.Context, d *schema.ResourceData, meta inte

func resourceBackupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn(ctx)
conn := meta.(*conns.AWSClient).FSxClient(ctx)

log.Printf("[INFO] Deleting FSx Backup: %s", d.Id())
_, err := conn.DeleteBackupWithContext(ctx, &fsx.DeleteBackupInput{
_, err := conn.DeleteBackup(ctx, &fsx.DeleteBackupInput{
BackupId: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeBackupNotFound) {
if errs.IsA[*awstypes.BackupNotFound](err) {
return diags
}

Expand All @@ -184,56 +186,53 @@ func resourceBackupDelete(ctx context.Context, d *schema.ResourceData, meta inte
return diags
}

func findBackupByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.Backup, error) {
func findBackupByID(ctx context.Context, conn *fsx.Client, id string) (*awstypes.Backup, error) {
input := &fsx.DescribeBackupsInput{
BackupIds: aws.StringSlice([]string{id}),
BackupIds: []string{id},
}

return findBackup(ctx, conn, input, tfslices.PredicateTrue[*fsx.Backup]())
return findBackup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.Backup]())
}

func findBackup(ctx context.Context, conn *fsx.FSx, input *fsx.DescribeBackupsInput, filter tfslices.Predicate[*fsx.Backup]) (*fsx.Backup, error) {
func findBackup(ctx context.Context, conn *fsx.Client, input *fsx.DescribeBackupsInput, filter tfslices.Predicate[*awstypes.Backup]) (*awstypes.Backup, error) {
output, err := findBackups(ctx, conn, input, filter)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output)
return tfresource.AssertSingleValueResult(output)
}

func findBackups(ctx context.Context, conn *fsx.FSx, input *fsx.DescribeBackupsInput, filter tfslices.Predicate[*fsx.Backup]) ([]*fsx.Backup, error) {
var output []*fsx.Backup
func findBackups(ctx context.Context, conn *fsx.Client, input *fsx.DescribeBackupsInput, filter tfslices.Predicate[*awstypes.Backup]) ([]awstypes.Backup, error) {
var output []awstypes.Backup

err := conn.DescribeBackupsPagesWithContext(ctx, input, func(page *fsx.DescribeBackupsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
pages := fsx.NewDescribeBackupsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

for _, v := range page.Backups {
if v != nil && filter(v) {
output = append(output, v)
if errs.IsA[*awstypes.FileSystemNotFound](err) || errs.IsA[*awstypes.BackupNotFound](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) || tfawserr.ErrCodeEquals(err, fsx.ErrCodeBackupNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
if err != nil {
return nil, err
}
}

if err != nil {
return nil, err
for _, v := range page.Backups {
if filter(&v) {
output = append(output, v)
}
}
}

return output, nil
}

func statusBackup(ctx context.Context, conn *fsx.FSx, id string) retry.StateRefreshFunc {
func statusBackup(ctx context.Context, conn *fsx.Client, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := findBackupByID(ctx, conn, id)

Expand All @@ -245,44 +244,44 @@ func statusBackup(ctx context.Context, conn *fsx.FSx, id string) retry.StateRefr
return nil, "", err
}

return output, aws.StringValue(output.Lifecycle), nil
return output, string(output.Lifecycle), nil
}
}

func waitBackupAvailable(ctx context.Context, conn *fsx.FSx, id string) (*fsx.Backup, error) {
func waitBackupAvailable(ctx context.Context, conn *fsx.Client, id string) (*awstypes.Backup, error) {
const (
timeout = 10 * time.Minute
)
stateConf := &retry.StateChangeConf{
Pending: []string{fsx.BackupLifecycleCreating, fsx.BackupLifecyclePending, fsx.BackupLifecycleTransferring},
Target: []string{fsx.BackupLifecycleAvailable},
Pending: enum.Slice(awstypes.BackupLifecycleCreating, awstypes.BackupLifecyclePending, awstypes.BackupLifecycleTransferring),
Target: enum.Slice(awstypes.BackupLifecycleAvailable),
Refresh: statusBackup(ctx, conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*fsx.Backup); ok {
if output, ok := outputRaw.(*awstypes.Backup); ok {
return output, err
}

return nil, err
}

func waitBackupDeleted(ctx context.Context, conn *fsx.FSx, id string) (*fsx.Backup, error) {
func waitBackupDeleted(ctx context.Context, conn *fsx.Client, id string) (*awstypes.Backup, error) {
const (
timeout = 10 * time.Minute
)
stateConf := &retry.StateChangeConf{
Pending: []string{fsx.FileSystemLifecycleDeleting},
Pending: enum.Slice(awstypes.FileSystemLifecycleDeleting),
Target: []string{},
Refresh: statusBackup(ctx, conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*fsx.Backup); ok {
if output, ok := outputRaw.(*awstypes.Backup); ok {
return output, err
}

Expand Down
Loading

0 comments on commit cc6a0f5

Please sign in to comment.