113336d6f1
* Add functions to retrieve the allowed and required parameters for boto3 client methods * Add custom waiter for stopping an RDS DB instance * Add rds_instance module * Add rds_instance integration tests * address requested changes from ryansb * address requested changes from willthames * address requested changes from dmsimard * Fix final snapshots Fix idempotence with already-deleting DB instances Remove unused import from module_utils/aws/core.py Consolidate function to get all boto3 client method parameters and the subset of required parameters * Add some additional rds_instance integration tests * Add some common functions to module_utils/aws/rds * Move common code out of rds_instance * Remove hardcoded engine choices and require the minimum boto3 * Document wait behavior * Provide a list of valid engines in the error message if it is invalid Add supported methods to whitelist Remove AWSRetry around waiter Wait for a less crazy amount of time Remove unused variables * Add a test for an invalid engine option * pep8 * Missed adding a method to the whitelist * Use retries * Fix some little things * Fix more things * Improve error message * Support creating cross-region read replicas * Remove unused imports * Add retry when getting RDS instance * Soft-check required options so module fails properly when options are missing * Fix mariadb parameter version * Fix cross-region read_replica creation and tests * fix modify tests * Fix a modification test * Fix typo * Remove test for option_group_name that exists for this account but may not for others and added as a TODO to do properly
199 lines
6.2 KiB
YAML
199 lines
6.2 KiB
YAML
---
|
|
- 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 mariadb instance
|
|
rds_instance:
|
|
id: "{{ instance_id }}"
|
|
state: present
|
|
engine: mariadb
|
|
username: "{{ username }}"
|
|
password: "{{ password }}"
|
|
db_instance_class: "{{ db_instance_class }}"
|
|
allocated_storage: "{{ allocated_storage }}"
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- "result.db_instance_identifier == '{{ instance_id }}'"
|
|
|
|
- name: Modify the instance name without immediate application
|
|
rds_instance:
|
|
id: "{{ instance_id }}"
|
|
state: present
|
|
new_id: "{{ modified_instance_id }}"
|
|
apply_immediately: False
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- 'result.db_instance_identifier == "{{ instance_id }}"'
|
|
|
|
- name: Immediately apply the pending update
|
|
rds_instance:
|
|
id: "{{ instance_id }}"
|
|
state: present
|
|
new_id: "{{ modified_instance_id }}"
|
|
apply_immediately: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- 'result.db_instance_identifier == "{{ modified_instance_id }}"'
|
|
|
|
- name: Modify the instance immediately
|
|
rds_instance:
|
|
id: '{{ modified_instance_id }}'
|
|
state: present
|
|
new_id: '{{ instance_id }}'
|
|
apply_immediately: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- 'result.db_instance_identifier == "{{ instance_id }}"'
|
|
|
|
- name: Check mode - modify the password
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: present
|
|
password: '{{ password }}'
|
|
force_update_password: True
|
|
apply_immediately: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
check_mode: True
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
|
|
- name: Modify the password
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: present
|
|
password: '{{ password }}'
|
|
force_update_password: True
|
|
apply_immediately: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
|
|
# TODO: test modifying db_subnet_group_name, db_security_groups, db_parameter_group_name, option_group_name,
|
|
# monitoring_role_arn, monitoring_interval, domain, domain_iam_role_name, cloudwatch_logs_export_configuration
|
|
|
|
- name: Modify several attributes
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: present
|
|
allocated_storage: 30
|
|
db_instance_class: "{{ modified_db_instance_class }}"
|
|
backup_retention_period: 2
|
|
preferred_backup_window: "05:00-06:00"
|
|
preferred_maintenance_window: "mon:06:20-mon:06:50"
|
|
engine_version: "10.1.26"
|
|
allow_major_version_upgrade: true
|
|
auto_minor_version_upgrade: false
|
|
port: 1150
|
|
apply_immediately: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- result.pending_modified_values.allocated_storage == 30
|
|
- result.pending_modified_values.port == 1150
|
|
- 'result.pending_modified_values.db_instance_class == "db.t2.medium"'
|
|
- 'result.pending_modified_values.engine_version == "10.1.26"'
|
|
|
|
- name: Idempotence modifying several pending attributes
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: present
|
|
allocated_storage: 30
|
|
db_instance_class: "{{ modified_db_instance_class }}"
|
|
backup_retention_period: 2
|
|
preferred_backup_window: "05:00-06:00"
|
|
preferred_maintenance_window: "mon:06:20-mon:06:50"
|
|
engine_version: "10.1.26"
|
|
allow_major_version_upgrade: true
|
|
auto_minor_version_upgrade: false
|
|
port: 1150
|
|
<<: *aws_connection_info
|
|
register: result
|
|
retries: 30
|
|
delay: 10
|
|
until: result is not failed
|
|
|
|
- assert:
|
|
that:
|
|
- not result.changed
|
|
- '"allocated_storage" in result.pending_modified_values or result.allocated_storage == 30'
|
|
- '"port" in result.pending_modified_values or result.endpoint.port == 1150'
|
|
- '"db_instance_class" in result.pending_modified_values or result.db_instance_class == "db.t2.medium"'
|
|
- '"engine_version" in result.pending_modified_values or result.engine_version == "10.1.26"'
|
|
|
|
- name: Reboot the instance to update the modified values and add tags
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: rebooted
|
|
tags:
|
|
Created_by: Ansible rds_instance tests
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- name: Delete the instance
|
|
rds_instance:
|
|
id: '{{ instance_id }}'
|
|
state: absent
|
|
skip_final_snapshot: True
|
|
<<: *aws_connection_info
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result.changed
|
|
- '"pending_modified_values" not in result'
|
|
|
|
always:
|
|
|
|
- name: Delete the instance
|
|
rds_instance:
|
|
id: '{{ item }}'
|
|
state: absent
|
|
skip_final_snapshot: True
|
|
<<: *aws_connection_info
|
|
loop: ['{{ instance_id }}', '{{ modified_instance_id }}']
|
|
ignore_errors: yes
|