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

r/aws_backup_vault: Fix empty result errors reading vaults in certain Regions #39670

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/39670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_backup_vault: Fix `empty result` errors reading vaults in certain Regions
```
12 changes: 11 additions & 1 deletion internal/service/backup/logically_air_gapped_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,17 @@ type logicallyAirGappedVaultResourceModel struct {
}

func findLogicallyAirGappedBackupVaultByName(ctx context.Context, conn *backup.Client, name string) (*backup.DescribeBackupVaultOutput, error) { // nosemgrep:ci.backup-in-func-name
return findVaultByNameAndType(ctx, conn, name, awstypes.VaultTypeLogicallyAirGappedBackupVault)
output, err := findVaultByName(ctx, conn, name)

if err != nil {
return nil, err
}

if output.VaultType != awstypes.VaultTypeLogicallyAirGappedBackupVault {
return nil, tfresource.NewEmptyResultError(name)
}

return output, nil
}

func statusLogicallyAirGappedVault(ctx context.Context, conn *backup.Client, name string) retry.StateRefreshFunc {
Expand Down
18 changes: 12 additions & 6 deletions internal/service/backup/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,20 @@ func resourceVaultDelete(ctx context.Context, d *schema.ResourceData, meta inter
}

func findBackupVaultByName(ctx context.Context, conn *backup.Client, name string) (*backup.DescribeBackupVaultOutput, error) { // nosemgrep:ci.backup-in-func-name
return findVaultByNameAndType(ctx, conn, name, awstypes.VaultTypeBackupVault)
output, err := findVaultByName(ctx, conn, name)

if err != nil {
return nil, err
}

if output.VaultType != awstypes.VaultTypeBackupVault && output.VaultType != "" {
return nil, tfresource.NewEmptyResultError(name)
}

return output, nil
}

func findVaultByNameAndType(ctx context.Context, conn *backup.Client, name string, vaultType awstypes.VaultType) (*backup.DescribeBackupVaultOutput, error) {
func findVaultByName(ctx context.Context, conn *backup.Client, name string) (*backup.DescribeBackupVaultOutput, error) {
input := &backup.DescribeBackupVaultInput{
BackupVaultName: aws.String(name),
}
Expand All @@ -216,10 +226,6 @@ func findVaultByNameAndType(ctx context.Context, conn *backup.Client, name strin
return nil, err
}

if output.VaultType != vaultType {
return nil, tfresource.NewEmptyResultError(input)
}

return output, nil
}

Expand Down
Loading