Skip to content

Commit

Permalink
Merge pull request #39670 from hashicorp/b-aws_backup_vault-not-found…
Browse files Browse the repository at this point in the history
….ca-central-1

r/aws_backup_vault: Fix `empty result` errors reading vaults in certain Regions
  • Loading branch information
ewbankkit authored Oct 10, 2024
2 parents 7f260d9 + e9492bc commit 6d9b545
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
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

0 comments on commit 6d9b545

Please sign in to comment.