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

Add force_delete to aws_backup_vault resource #13247

Closed
igoratencompass opened this issue May 10, 2020 · 12 comments · Fixed by #26199
Closed

Add force_delete to aws_backup_vault resource #13247

igoratencompass opened this issue May 10, 2020 · 12 comments · Fixed by #26199
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/backup Issues and PRs that pertain to the backup service.

Comments

@igoratencompass
Copy link

igoratencompass commented May 10, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

0.12.8

Affected Resource(s)

  • aws_backup_vault

Debug Output

Error: error deleting Backup Vault (backup-vault): InvalidRequestException: Backup vault cannot be deleted (contains 1 recovery points)
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "7c3c5f84-4a9d-40fd-a72e-00d929b1c85e"
  },
  Code_: "ERROR_9101",
  Context: "1",
  Message_: "Backup vault cannot be deleted (contains 1 recovery points)"
}

Expected Behavior

Expect to be able to force delete the resource.

Actual Behavior

See error above.

Steps to Reproduce

Create and try to destroy destroy aws_backup_vault resource with existing recovery points.

@ghost ghost added the service/backup Issues and PRs that pertain to the backup service. label May 10, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label May 10, 2020
@ryno75
Copy link
Contributor

ryno75 commented Nov 24, 2020

This.
Please! 😄

I envision this to be an implementation very similar to the S3 "force_destroy" attribute that deletes all bucket objects when a bucket is deleted. Pretty clear example of that implementation in the code for aws_s3_bucket. If I get a little time I'll implement it, but I'm more than happy if someone else does it before me!

@tianqiliu-RBLX
Copy link

Following..

@RachelleAtEncompass
Copy link

Following... 100 votes for this one.

@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 21, 2021
@mattjtodd
Copy link

"Slightly" 😉 dangerous but would be useful to have.

@VladoPortos
Copy link

How to deal with this ? The whole destroy operation just crashes because of this. Cant remove RDS, EC2 ... but I don't care if there are backups or not, if I'm calling destroy and that include backup vault and plans it should all go away...

@VladoPortos
Copy link

I needed to add this as step before terraform destroy:

for ARN in $(aws backup list-recovery-points-by-backup-vault --backup-vault-name "backup_vault" --query 'RecoveryPoints[].RecoveryPointArn' --output text); do aws backup delete-recovery-point --backup-vault-name "backup_vault" --recovery-point-arn "${ARN}"; done

Wish there was a toggle for this inside Terraform.

@quentin9696
Copy link

Hi,

I'm also interest about this feature.
I know it can be dangerous, but since we can lock a backup, it can be secure on production stuff

@HiGein
Copy link

HiGein commented Jun 13, 2022

Also interested in that.

@apushnov
Copy link

I'm also interested in that.

@CMarriaga
Copy link

Hi everyone, I might have found a workaround for this while the issue is closed.

First we create a script, in my case in the file location ./scripts/delete_vault_backups.sh such as:

existing_arns=$(aws backup list-recovery-points-by-backup-vault --backup-vault-name "$1" --region "$2" --query 'RecoveryPoints[].RecoveryPointArn' --output text)
existing_arns_amount=$(echo $existing_arns | wc -w)

for arn in $existing_arns; do 
  echo "deleting ${arn} ..."
  aws backup delete-recovery-point --backup-vault-name "$1" --region "$2" --recovery-point-arn "${arn}"
done

while [[ $existing_arns_amount -gt 0 ]] ; 
  do
  sleep 3
  existing_arns_amount=$(aws backup list-recovery-points-by-backup-vault --backup-vault-name "$1" --region "$2" --query 'RecoveryPoints[].RecoveryPointArn' --output text | wc -w)
done

Then, in our Terraform we add a "local-exec" provisioner on the aws_backup_vault resource such as

resource "aws_backup_vault" "this" {
  #...
  provisioner "local-exec" {
    command = format(
      "bash ./scripts/delete_vault_backups.sh %s %s",
      self.name,
      split(":", self.arn)[3]
    )
    when = destroy
  }
}

This will make sure that all Vault Recovery Points are delete before the aws_backup_vault resource is deleted

@volenpopov
Copy link

@CMarriaga thanks for the workaround!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/backup Issues and PRs that pertain to the backup service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.