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

resource/aws_db_instance: Replicated automated backups as a source for the option restore_to_point_in_time #21851

Closed
jonasoneves opened this issue Nov 19, 2021 · 5 comments · Fixed by #23086
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/rds Issues and PRs that pertain to the rds service.
Milestone

Comments

@jonasoneves
Copy link

jonasoneves commented Nov 19, 2021

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

Description

The AWS RDS API action RestoreDBInstanceToPointInTime supports the request parameter SourceDBInstanceAutomatedBackupsArn, which is currently not a valid option in the terraform aws provider. This allows restoring backups replicated from a different region.

New or Affected Resource(s)

  • aws_db_instance

Potential Terraform Configuration

resource "aws_db_instance" "default" {
  ...
  restore_to_point_in_time = {
    source_db_instance_automated_backups_arn = "arn:aws:rds:us-east-1:001122334455:auto-backup:ab-aabbc9ababababal1ljsadlasj83shfaskdqors"
    use_latest_restorable_time               = true
  } 
}

References

@jonasoneves jonasoneves added the enhancement Requests to existing resources that expand the functionality or scope. label Nov 19, 2021
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/rds Issues and PRs that pertain to the rds service. labels Nov 19, 2021
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Nov 19, 2021
@mzazon
Copy link

mzazon commented Nov 24, 2021

@jonasoneves Were you able to find a solution to restore an automated backup in another region?

@jonasoneves
Copy link
Author

jonasoneves commented Nov 29, 2021

@mzazon I've been generating a script to run the restore via AWS cli commands with the terraform resource local_file, which then import the new RDS to terraform automatically. It lives in the same module as the RDS instance (so it can get variables like rds-identifier, security-groups, etc.)

resource "local_file" "this" {
  content  = <<SCRIPT
#!/bin/bash

export AWS_DEFAULT_REGION=${var.region} 
export AWS_DEFAULT_OUTPUT=text

AUTO_BACKUP_ARN=$(aws rds describe-db-instance-automated-backups \
    --db-instance-identifier ${var.db_identifier} \
    --query DBInstanceAutomatedBackups[*].DBInstanceAutomatedBackupsArn)

aws rds restore-db-instance-to-point-in-time \
    --db-subnet-group-name ${var.subnet_group} \
    --multi-az \
    --source-db-instance-automated-backups-arn "$AUTO_BACKUP_ARN" \
    --target-db-instance-identifier ${var.db_identifier} \
    --use-latest-restorable-time \
    --vpc-security-group-ids ${join(",", var.security_group_ids)}

echo -e "\nImporting new RDS instance to terraform state..."
terraform import module.rds.module.db_instance.aws_db_instance.this[0] ${var.db_identifier}
SCRIPT
  filename = "restore-backup.sh"
}

@mzazon
Copy link

mzazon commented Nov 29, 2021

@jonasoneves great solution, thank you! we are doing similar although a bit more manual. I may take a stab at creating a pull request for this parameter if I have time this week.

@github-actions
Copy link

This functionality has been released in v4.6.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented May 7, 2022

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 May 7, 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/rds Issues and PRs that pertain to the rds service.
Projects
None yet
3 participants