Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fsx: Migrate to AWS SDK v2 #38343

Merged
merged 25 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e534af8
fsx: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
0d446bb
gopatch
mattburgess Jul 11, 2024
a6ee3a6
make gen
mattburgess Jul 11, 2024
155a42a
r/fsx_backup: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
7627263
r/fsx_data_repository_association: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
565d79a
r/fsx_file_cache: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
aa7f310
r/fsx_lustre_file_system: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
593c5be
d/fsx_ontap_file_system,r/fsx_ontap_file_system: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
705f2dd
d/fsx_ontap_storage_virtual_machine,d/fsx_ontap_storage_virtual_machi…
mattburgess Jul 11, 2024
d37ccf9
r/fsx_ontap_volume: Migrate to AWS SDK v2
mattburgess Jul 11, 2024
0157744
r/fsx_openzfs_file_system: Migrate to AWS SDK v2
mattburgess Jul 13, 2024
e236641
d/fsx_openzfs_snapshot: Migrate to AWS SDK v2
mattburgess Jul 13, 2024
e20ea27
d/fsx_openzfs_snapshot,r/fsx_openzfs_snapshot: Migrate to AWS SDK v2
mattburgess Jul 13, 2024
c81701d
r/fsx_openzfs_volume: Migrate to AWS SDK v2
mattburgess Jul 13, 2024
8d4fcf6
r/fsx_windows_file_system: Migrate to AWS SDK v2
mattburgess Jul 15, 2024
335a845
fsx: Migrate sweepers to AWS SDK v2
mattburgess Jul 15, 2024
8cb11b2
d/fsx_common_schema: Migrate to AWS SDK v2
mattburgess Jul 15, 2024
c09be6e
Merge branch 'main' into HEAD
ewbankkit Jul 19, 2024
d01db03
fsx: Cosmetics.
ewbankkit Jul 19, 2024
2b6d716
r/aws_fsx_openzfs_volume: Correctly set `tags` on Read.
ewbankkit Jul 19, 2024
2a07e1c
Acceptance test output:
ewbankkit Jul 19, 2024
a5ff10a
d/aws_fsx_openzfs_snapshot: Correctly set `tags` on Read.
ewbankkit Jul 19, 2024
6cdefc9
d/aws_fsx_openzfs_snapshot: Correctly set `tags` on Read.
ewbankkit Jul 19, 2024
54c003f
d/aws_fsx_ontap_storage_virtual_machine: Correctly set `tags` on Read.
ewbankkit Jul 19, 2024
282e873
Fix acceptance test configurations.
ewbankkit Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading