| 1 |
--- |
| 2 |
- name: Rds_instance / replica integration tests |
| 3 |
|
| 4 |
module_defaults: |
| 5 |
group/aws: |
| 6 |
access_key: "{{ aws_access_key }}" |
| 7 |
secret_key: "{{ aws_secret_key }}" |
| 8 |
session_token: "{{ security_token | default(omit) }}" |
| 9 |
region: "{{ aws_region }}" |
| 10 |
|
| 11 |
block: |
| 12 |
- name: Set the two regions for the source DB and the replica |
| 13 |
ansible.builtin.set_fact: |
| 14 |
region_src: "{{ aws_region }}" |
| 15 |
region_dest: "{{ aws_region }}" |
| 16 |
|
| 17 |
- name: Ensure the resource doesn't exist |
| 18 |
amazon.aws.rds_instance: |
| 19 |
id: "{{ instance_id }}" |
| 20 |
state: absent |
| 21 |
skip_final_snapshot: true |
| 22 |
region: "{{ region_src }}" |
| 23 |
register: result |
| 24 |
|
| 25 |
- ansible.builtin.assert: |
| 26 |
that: |
| 27 |
- not result.changed |
| 28 |
ignore_errors: true |
| 29 |
|
| 30 |
- name: Create a source DB instance |
| 31 |
amazon.aws.rds_instance: |
| 32 |
id: "{{ instance_id }}" |
| 33 |
state: present |
| 34 |
engine: mysql |
| 35 |
backup_retention_period: 1 |
| 36 |
username: "{{ username }}" |
| 37 |
password: "{{ password }}" |
| 38 |
db_instance_class: "{{ db_instance_class }}" |
| 39 |
allocated_storage: "{{ allocated_storage }}" |
| 40 |
region: "{{ region_src }}" |
| 41 |
tags: |
| 42 |
Name: "{{ instance_id }}" |
| 43 |
Created_by: Ansible rds_instance tests |
| 44 |
register: source_db |
| 45 |
|
| 46 |
- ansible.builtin.assert: |
| 47 |
that: |
| 48 |
- source_db.changed |
| 49 |
- source_db.db_instance_identifier == instance_id |
| 50 |
|
| 51 |
# ------------------------------------------------------------------------------------------ |
| 52 |
|
| 53 |
- name: Create a read replica in a different region - check_mode |
| 54 |
amazon.aws.rds_instance: |
| 55 |
id: "{{ instance_id }}-replica" |
| 56 |
state: present |
| 57 |
source_db_instance_identifier: "{{ instance_id }}" |
| 58 |
engine: mysql |
| 59 |
username: "{{ username }}" |
| 60 |
password: "{{ password }}" |
| 61 |
read_replica: true |
| 62 |
db_instance_class: "{{ db_instance_class }}" |
| 63 |
allocated_storage: "{{ allocated_storage }}" |
| 64 |
region: "{{ region_dest }}" |
| 65 |
tags: |
| 66 |
Name: "{{ instance_id }}" |
| 67 |
Created_by: Ansible rds_instance tests |
| 68 |
wait: true |
| 69 |
register: result |
| 70 |
check_mode: true |
| 71 |
|
| 72 |
- ansible.builtin.assert: |
| 73 |
that: |
| 74 |
- result.changed |
| 75 |
|
| 76 |
- name: Create a read replica in a different region |
| 77 |
amazon.aws.rds_instance: |
| 78 |
id: "{{ instance_id }}-replica" |
| 79 |
state: present |
| 80 |
source_db_instance_identifier: "{{ instance_id }}" |
| 81 |
engine: mysql |
| 82 |
username: "{{ username }}" |
| 83 |
password: "{{ password }}" |
| 84 |
read_replica: true |
| 85 |
db_instance_class: "{{ db_instance_class }}" |
| 86 |
allocated_storage: "{{ allocated_storage }}" |
| 87 |
region: "{{ region_dest }}" |
| 88 |
tags: |
| 89 |
Name: "{{ instance_id }}" |
| 90 |
Created_by: Ansible rds_instance tests |
| 91 |
wait: true |
| 92 |
register: result |
| 93 |
|
| 94 |
- ansible.builtin.assert: |
| 95 |
that: |
| 96 |
- result.changed |
| 97 |
- result.db_instance_identifier == instance_id +'-replica' |
| 98 |
- result.tags | length == 2 |
| 99 |
- result.tags.Name == instance_id |
| 100 |
- result.tags.Created_by == 'Ansible rds_instance tests' |
| 101 |
|
| 102 |
- name: Test idempotence with a read replica - check_mode |
| 103 |
amazon.aws.rds_instance: |
| 104 |
id: "{{ instance_id }}-replica" |
| 105 |
state: present |
| 106 |
source_db_instance_identifier: "{{ instance_id }}" |
| 107 |
engine: mysql |
| 108 |
username: "{{ username }}" |
| 109 |
password: "{{ password }}" |
| 110 |
db_instance_class: "{{ db_instance_class }}" |
| 111 |
allocated_storage: "{{ allocated_storage }}" |
| 112 |
region: "{{ region_dest }}" |
| 113 |
tags: |
| 114 |
Name: "{{ instance_id }}" |
| 115 |
Created_by: Ansible rds_instance tests |
| 116 |
register: result |
| 117 |
check_mode: true |
| 118 |
|
| 119 |
- ansible.builtin.assert: |
| 120 |
that: |
| 121 |
- not result.changed |
| 122 |
|
| 123 |
- name: Test idempotence with a read replica |
| 124 |
amazon.aws.rds_instance: |
| 125 |
id: "{{ instance_id }}-replica" |
| 126 |
state: present |
| 127 |
source_db_instance_identifier: "{{ instance_id }}" |
| 128 |
engine: mysql |
| 129 |
username: "{{ username }}" |
| 130 |
password: "{{ password }}" |
| 131 |
db_instance_class: "{{ db_instance_class }}" |
| 132 |
allocated_storage: "{{ allocated_storage }}" |
| 133 |
region: "{{ region_dest }}" |
| 134 |
tags: |
| 135 |
Name: "{{ instance_id }}" |
| 136 |
Created_by: Ansible rds_instance tests |
| 137 |
register: result |
| 138 |
|
| 139 |
- ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- not result.changed |
| 142 |
|
| 143 |
- name: Test idempotence with read_replica=True |
| 144 |
amazon.aws.rds_instance: |
| 145 |
id: "{{ instance_id }}-replica" |
| 146 |
state: present |
| 147 |
read_replica: true |
| 148 |
source_db_instance_identifier: "{{ instance_id }}" |
| 149 |
engine: mysql |
| 150 |
username: "{{ username }}" |
| 151 |
password: "{{ password }}" |
| 152 |
db_instance_class: "{{ db_instance_class }}" |
| 153 |
allocated_storage: "{{ allocated_storage }}" |
| 154 |
region: "{{ region_dest }}" |
| 155 |
tags: |
| 156 |
Name: "{{ instance_id }}" |
| 157 |
Created_by: Ansible rds_instance tests |
| 158 |
register: result |
| 159 |
|
| 160 |
- ansible.builtin.assert: |
| 161 |
that: |
| 162 |
- not result.changed |
| 163 |
|
| 164 |
# ------------------------------------------------------------------------------------------ |
| 165 |
|
| 166 |
- name: Promote the read replica - check_mode |
| 167 |
amazon.aws.rds_instance: |
| 168 |
id: "{{ instance_id }}-replica" |
| 169 |
state: present |
| 170 |
read_replica: false |
| 171 |
region: "{{ region_dest }}" |
| 172 |
register: result |
| 173 |
check_mode: true |
| 174 |
|
| 175 |
- ansible.builtin.assert: |
| 176 |
that: |
| 177 |
- result.changed |
| 178 |
|
| 179 |
- name: Promote the read replica |
| 180 |
amazon.aws.rds_instance: |
| 181 |
id: "{{ instance_id }}-replica" |
| 182 |
state: present |
| 183 |
read_replica: false |
| 184 |
region: "{{ region_dest }}" |
| 185 |
register: result |
| 186 |
|
| 187 |
- ansible.builtin.assert: |
| 188 |
that: |
| 189 |
- result.changed |
| 190 |
|
| 191 |
- name: Test idempotence - check_mode |
| 192 |
amazon.aws.rds_instance: |
| 193 |
id: "{{ instance_id }}-replica" |
| 194 |
state: present |
| 195 |
read_replica: false |
| 196 |
region: "{{ region_dest }}" |
| 197 |
register: result |
| 198 |
check_mode: true |
| 199 |
|
| 200 |
- ansible.builtin.assert: |
| 201 |
that: |
| 202 |
- not result.changed |
| 203 |
|
| 204 |
- name: Test idempotence |
| 205 |
amazon.aws.rds_instance: |
| 206 |
id: "{{ instance_id }}-replica" |
| 207 |
state: present |
| 208 |
read_replica: false |
| 209 |
region: "{{ region_dest }}" |
| 210 |
register: result |
| 211 |
|
| 212 |
- ansible.builtin.assert: |
| 213 |
that: |
| 214 |
- not result.changed |
| 215 |
|
| 216 |
always: |
| 217 |
- name: Remove the DB instance |
| 218 |
amazon.aws.rds_instance: |
| 219 |
id: "{{ instance_id }}" |
| 220 |
state: absent |
| 221 |
skip_final_snapshot: true |
| 222 |
region: "{{ region_src }}" |
| 223 |
wait: false |
| 224 |
ignore_errors: true |
| 225 |
|
| 226 |
- name: Remove the DB replica |
| 227 |
amazon.aws.rds_instance: |
| 228 |
id: "{{ instance_id }}-replica" |
| 229 |
state: absent |
| 230 |
skip_final_snapshot: true |
| 231 |
region: "{{ region_dest }}" |
| 232 |
wait: false |
| 233 |
ignore_errors: true |