Skip to content

Commit

Permalink
use resource ID as input to delete operation; ignore automated backup…
Browse files Browse the repository at this point in the history
…s that can't be removed
  • Loading branch information
anGie44 committed Jun 18, 2021
1 parent 194ab9b commit f2be7d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_backup_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceAwsBackupVaultDelete(d *schema.ResourceData, meta interface{}) erro
conn := meta.(*AWSClient).backupconn

input := &backup.DeleteBackupVaultInput{
BackupVaultName: aws.String(d.Get("name").(string)),
BackupVaultName: aws.String(d.Id()),
}

_, err := conn.DeleteBackupVault(input)
Expand Down
14 changes: 9 additions & 5 deletions aws/resource_aws_backup_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strings"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -47,22 +48,25 @@ func testSweepBackupVaults(region string) error {
continue
}

name := aws.StringValue(vault.BackupVaultName)

// Ignore Default Backup Vault in region (cannot be deleted)
if aws.StringValue(vault.BackupVaultName) == "Default" {
log.Printf("[INFO] Skipping Backup Vault: Default")
// and automated Backups that result in AccessDeniedException when deleted
if name == "Default" || strings.Contains(name, "automatic-backup-vault") {
log.Printf("[INFO] Skipping Backup Vault: %s", name)
continue
}

// Backup Vault deletion only supported when empty
// Reference: https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DeleteBackupVault.html
if aws.Int64Value(vault.NumberOfRecoveryPoints) != 0 {
log.Printf("[INFO] Skipping Backup Vault (%s): not empty", aws.StringValue(vault.BackupVaultName))
log.Printf("[INFO] Skipping Backup Vault (%s): not empty", name)
continue
}

r := resourceAwsBackupVault()
d := r.Data(nil)
d.SetId(aws.StringValue(vault.BackupVaultName))
d.SetId(name)

sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}
Expand All @@ -74,7 +78,7 @@ func testSweepBackupVaults(region string) error {
errs = multierror.Append(errs, fmt.Errorf("error listing Backup Vaults for %s: %w", region, err))
}

if err = testSweepResourceOrchestrator(sweepResources); err != nil {
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping Backup Vaults for %s: %w", region, err))
}

Expand Down

0 comments on commit f2be7d7

Please sign in to comment.