From 60c76be03c85c3e40f2e5ec1a9d87ac182e3edab Mon Sep 17 00:00:00 2001 From: Will Thames Date: Thu, 25 Jul 2019 23:49:08 +1000 Subject: [PATCH] rds_instance: add point-in-time instance restore test (#59411) --- .../testing_policies/database-policy.json | 1 + .../targets/rds_instance/tasks/main.yml | 4 +- .../rds_instance/tasks/test_read_replica.yml | 8 +- .../tasks/test_restore_instance.yml | 95 +++++++++++++++++++ 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 test/integration/targets/rds_instance/tasks/test_restore_instance.yml diff --git a/hacking/aws_config/testing_policies/database-policy.json b/hacking/aws_config/testing_policies/database-policy.json index f4c824ae21d..fb5ad477ad7 100644 --- a/hacking/aws_config/testing_policies/database-policy.json +++ b/hacking/aws_config/testing_policies/database-policy.json @@ -34,6 +34,7 @@ "rds:PromoteReadReplica", "rds:RebootDBInstance", "rds:RemoveTagsFromResource", + "rds:RestoreDBInstanceToPointInTime", "rds:StartDBInstance", "rds:StopDBInstance" ], diff --git a/test/integration/targets/rds_instance/tasks/main.yml b/test/integration/targets/rds_instance/tasks/main.yml index 8f905095739..3aa77146988 100644 --- a/test/integration/targets/rds_instance/tasks/main.yml +++ b/test/integration/targets/rds_instance/tasks/main.yml @@ -21,7 +21,7 @@ tags: read_replica - include: ./test_vpc_security_groups.yml tags: vpc_security_groups - - #- include: ./test_restore_instance.yml # TODO: point-in-time, snapshot, s3 + - include: ./test_restore_instance.yml # TODO: snapshot, s3 + tags: restore # TODO: uncomment after adding rds_cluster module #- include: ./test_aurora.yml diff --git a/test/integration/targets/rds_instance/tasks/test_read_replica.yml b/test/integration/targets/rds_instance/tasks/test_read_replica.yml index bdd80c0daf0..157fd10597e 100644 --- a/test/integration/targets/rds_instance/tasks/test_read_replica.yml +++ b/test/integration/targets/rds_instance/tasks/test_read_replica.yml @@ -51,7 +51,7 @@ rds_instance: id: "{{ instance_id }}-replica" state: present - source_db_instance_identifier: "{{ source_db.db_instance_arn }}" + source_db_instance_identifier: "{{ instance_id }}" engine: mysql username: "{{ username }}" password: "{{ password }}" @@ -66,7 +66,7 @@ rds_instance: id: "{{ instance_id }}-replica" state: present - source_db_instance_identifier: "{{ source_db.db_instance_arn }}" + source_db_instance_identifier: "{{ instance_id }}" engine: mysql username: "{{ username }}" password: "{{ password }}" @@ -85,7 +85,7 @@ id: "{{ instance_id }}-replica" state: present read_replica: True - source_db_instance_identifier: "{{ source_db.db_instance_arn }}" + source_db_instance_identifier: "{{ instance_id }}" engine: mysql username: "{{ username }}" password: "{{ password }}" @@ -130,6 +130,7 @@ skip_final_snapshot: True region: "{{ region_src }}" <<: *aws_connection_info + ignore_errors: yes - name: Remove the DB replica rds_instance: @@ -138,3 +139,4 @@ skip_final_snapshot: True region: "{{ region_dest }}" <<: *aws_connection_info + ignore_errors: yes diff --git a/test/integration/targets/rds_instance/tasks/test_restore_instance.yml b/test/integration/targets/rds_instance/tasks/test_restore_instance.yml new file mode 100644 index 00000000000..b40e487dd81 --- /dev/null +++ b/test/integration/targets/rds_instance/tasks/test_restore_instance.yml @@ -0,0 +1,95 @@ +--- + - block: + + - name: set up aws connection info + set_fact: + aws_connection_info: &aws_connection_info + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token }}" + region: "{{ aws_region }}" + no_log: yes + + - name: Ensure the resource doesn't exist + rds_instance: + id: "{{ instance_id }}" + state: absent + skip_final_snapshot: True + <<: *aws_connection_info + register: result + + - assert: + that: + - not result.changed + ignore_errors: yes + + - name: Create a source DB instance + rds_instance: + id: "{{ instance_id }}" + state: present + engine: mysql + backup_retention_period: 1 + username: "{{ username }}" + password: "{{ password }}" + db_instance_class: "{{ db_instance_class }}" + allocated_storage: "{{ allocated_storage }}" + <<: *aws_connection_info + register: source_db + + - assert: + that: + - source_db.changed + - "source_db.db_instance_identifier == '{{ instance_id }}'" + + - name: Create a point in time DB instance + rds_instance: + id: "{{ instance_id }}-point-in-time" + state: present + source_db_instance_identifier: "{{ instance_id }}" + creation_source: instance + engine: mysql + username: "{{ username }}" + password: "{{ password }}" + db_instance_class: "{{ db_instance_class }}" + allocated_storage: "{{ allocated_storage }}" + use_latest_restorable_time: True + <<: *aws_connection_info + register: result + + - name: Test idempotence with a point in time replica + rds_instance: + id: "{{ instance_id }}-point-in-time" + state: present + source_db_instance_identifier: "{{ instance_id }}" + creation_source: instance + engine: mysql + username: "{{ username }}" + password: "{{ password }}" + db_instance_class: "{{ db_instance_class }}" + allocated_storage: "{{ allocated_storage }}" + restore_time: "{{ result.latest_restorable_time }}" + <<: *aws_connection_info + register: result + + - assert: + that: + - not result.changed + + always: + + - name: Remove the DB instance + rds_instance: + id: "{{ instance_id }}" + state: absent + skip_final_snapshot: True + <<: *aws_connection_info + ignore_errors: yes + + + - name: Remove the point in time restored DB + rds_instance: + id: "{{ instance_id }}-point-in-time" + state: absent + skip_final_snapshot: True + <<: *aws_connection_info + ignore_errors: yes