I have a Serverless Aurora MySQL cluster of which I take daily automated snapshots using the backup retention option via console. This works as expected and I get my snapshot daily. The snapshot type is cluster (vs instance). I am able to browse to a snapshot and follow the online restore process. This works as expected. My cluster snapshot is restored to a new cluster and it has one instance in it with all my data up to when the snapshot was taken. Great.
The manual approach is workable, but I have a requirement to automate the point in time restore process for various reasons. I understand the ansible amazon.aws.rds_instance module is not compatible with cluster type snapshot restores. The documentation is clear that amazon.aws.rds_cluster should be used, but creates an empty cluster. The docs mention it still requires a CreateDBInstance call to complete the process. Here is where the wheels come off.
Using amazon.aws.rds_cluster I can create an empty cluster from a cluster snapshot. I then proceed that call with amazon.aws.rds_instance specifying the new cluster's identifier. I spools up an instance, but it's a fresh, empty instance and not my point in time data - contrasted to the result I get from the AWS console.
I've gone through the Ansible docs for this but cannot find a way to mimic the console result with Ansible. There is a vague reference to a known issue related to the CLI - but this is from 2016, surely I'm missing something obvious and its not still an issue. The AWS forum topic linked in that SO post has been archived.
https://docs.ansible.com/ansible/latest/collections/amazon/aws/rds_instance_module.html https://docs.ansible.com/ansible/latest/collections/amazon/aws/rds_cluster_module.html
The docs state that an explicit create-db-instance call is required when using the CLI and you specify which cluster it belongs to. I cannot figure out how to instruct it, using Ansible, to restore the snapshot data instead of creating and attaching a new instance. I've tried with source: snapshot in the instance creation section but AWS fails to find a snapshot of id snap_id of type instance snapshot. This makes sense because it's a cluster snapshot. The amazon.aws.rds_cluster module has no options to specify instances on creation which lines up with the documentation.
- name: Restore cluster from source snapshot
amazon.aws.rds_cluster:
engine: aurora-mysql
master_username: "admin"
master_user_password: "{{ rds_admin_pass }}"
region: "{{ rds_loc }}"
cluster_id: "{{ cluster_id }}"
snapshot_identifier: "{{ snap_id }}"
db_subnet_group_name: "rds-ec2-db-subnet-group-1"
- name: Restore DB from snapshot
amazon.aws.rds_instance:
region: "{{ rds_loc }}"
engine: aurora-mysql
db_instance_identifier: "{{ rds_id }}"
db_cluster_identifier: "{{ cluster_id }}"
db_instance_class: "db.t3.medium"
snapshot_identifier: "{{ snap_id }}"
db_subnet_group_name: "rds-ec2-db-subnet-group-1"
state: present
Is what I'm trying to achieve here possible with Ansible? I have found a few Terraform examples that follow the same flow, but have not yet tried them. I am partial to Ansible.