diff --git a/.changelog/39670.txt b/.changelog/39670.txt new file mode 100644 index 00000000000..504b991307a --- /dev/null +++ b/.changelog/39670.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_backup_vault: Fix `empty result` errors reading vaults in certain Regions +``` \ No newline at end of file diff --git a/internal/service/backup/logically_air_gapped_vault.go b/internal/service/backup/logically_air_gapped_vault.go index a11e7022b1f..dc37ee24494 100644 --- a/internal/service/backup/logically_air_gapped_vault.go +++ b/internal/service/backup/logically_air_gapped_vault.go @@ -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 { diff --git a/internal/service/backup/vault.go b/internal/service/backup/vault.go index 4f7e6529482..b4fb6889a93 100644 --- a/internal/service/backup/vault.go +++ b/internal/service/backup/vault.go @@ -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), } @@ -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 }