From a9eca598cca9b87a6b5322be10ee534ed74f27d9 Mon Sep 17 00:00:00 2001 From: Taeho Park Date: Fri, 28 Jul 2023 15:57:41 -0400 Subject: [PATCH 01/41] add create global cluster role --- .../README.md | 53 +++++++++++++++++++ .../defaults/main.yml | 1 + .../tasks/main.yml | 52 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 roles/create_global_cluster_with_rds_cluster/README.md create mode 100644 roles/create_global_cluster_with_rds_cluster/defaults/main.yml create mode 100644 roles/create_global_cluster_with_rds_cluster/tasks/main.yml diff --git a/roles/create_global_cluster_with_rds_cluster/README.md b/roles/create_global_cluster_with_rds_cluster/README.md new file mode 100644 index 00000000..cdd3c83f --- /dev/null +++ b/roles/create_global_cluster_with_rds_cluster/README.md @@ -0,0 +1,53 @@ +create_global_cluster_with_rds_cluster +========= + +A role to create aurora global cluster with two different region rds clusters. + +Requirements +------------ + +AWS credentials with valid permission. + +Role Variables +-------------- +* **global_cluster_identifier** - Name of the Aurora global cluster. **Required** +* **cluster_id** - Name of the primary cluster. **Required** +* **username** - Username of the rds clusters. **Required** +* **password** - Password of the rds clusters. **Required** +* **engine** - Engine of the global and rds clusters. **Required** +* **db_instance_class** - A DB instance class type and size. **Required** +* **region_src** - The primary cluster region. **Required** +* **region_dest** - The secondary cluster region. **Required** + +Dependencies +------------ + +- role: [aws_setup_credentials](../aws_setup_credentials/README.md) + +Example Playbook +---------------- +--- +- name: Playbook for move objects between buckets using cloud.aws_ops.move_objects_between_buckets role + hosts: localhost + gather_facts: false + tasks: + - name: Move one object between buckets + ansible.builtin.include_role: + name: cloud.aws_ops.move_objects_between_buckets + vars: + global_cluster_identifier: global_cluster_name + cluster_id: cluster_name + username: username + password: password123 + engine: aurora-postgresql + db_subnet_group_name: subnet_group_name + db_instance_class: db.r5.large + region_primary: us-east-2 + region_secondary: us-east-1 + instance_id: instance_id_name + +License +------- + +GNU General Public License v3.0 or later + diff --git a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml new file mode 100644 index 00000000..73b314ff --- /dev/null +++ b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml @@ -0,0 +1 @@ +--- \ No newline at end of file diff --git a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml new file mode 100644 index 00000000..32e826ea --- /dev/null +++ b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml @@ -0,0 +1,52 @@ +--- +- name: Run 'create_global_cluster_with_rds_cluster' role + module_defaults: + group/aws: "{{ aws_role_credentials }}" + + block: + - name: Create global db + amazon.cloud.rds_global_cluster: + global_cluster_identifier: "{{ global_cluster_identifier }}" + engine: "{{ engine }}" + + # Create first rds cluster + - name: Create primary rds cluster that connects with global db + amazon.aws.rds_cluster: + cluster_id: "{{ cluster_id }}" + engine: "{{ engine }}" + engine_mode: provisioned + username: "{{ username }}" + password: "{{ password }}" + region: "{{ region_primary }}" + db_subnet_group_name: "{{ db_subnet_group_name | default(omit) }}" + global_cluster_identifier: "{{ global_cluster_identifier }}" + + - name: Create a rds instance that connects with primary rds cluster + amazon.aws.rds_instance: + cluster_id: "{{ cluster_id }}" + db_instance_identifier: "{{ instance_id }}" + engine: "{{ engine }}" + db_instance_class: "{{ db_instance_class }}" + + # Obtain information about primary cluster + - name: Get info on primary cluster + amazon.aws.rds_cluster_info: + db_cluster_identifier: '{{ cluster_id }}' + register: _result_cluster_info + + - name: Set the ARN of the primary DB cluster + set_fact: + src_db_cluster_arn: '{{ _result_cluster_info.clusters[0].db_cluster_arn }}' + + # Error: doesn't have binlogs enabled + - name: Create secondary rds cluster that connects with global db + amazon.aws.rds_cluster: + id: '{{ cluster_id }}-replica' + state: present + replication_source_identifier: '{{ src_db_cluster_arn }}' + engine: '{{ engine }}' + region: '{{ region_secondary }}' + tags: + Name: '{{ cluster_id }}' + Created_by: Ansible rds_cluster tests + wait: yes From 2ebf606e2b7727e3658a3238de8e8dc97f14cdfc Mon Sep 17 00:00:00 2001 From: Taeho Park Date: Mon, 31 Jul 2023 17:21:27 -0400 Subject: [PATCH 02/41] added test cases --- .../README.md | 1 + .../defaults/main.yml | 3 +- .../meta/main.yml | 3 ++ .../tasks/main.yml | 20 +++---- .../aliases | 3 ++ .../defaults/main.yml | 13 +++++ .../tasks/main.yml | 53 +++++++++++++++++++ 7 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 roles/create_global_cluster_with_rds_cluster/meta/main.yml create mode 100644 tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases create mode 100644 tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml create mode 100644 tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml diff --git a/roles/create_global_cluster_with_rds_cluster/README.md b/roles/create_global_cluster_with_rds_cluster/README.md index cdd3c83f..188badc4 100644 --- a/roles/create_global_cluster_with_rds_cluster/README.md +++ b/roles/create_global_cluster_with_rds_cluster/README.md @@ -18,6 +18,7 @@ Role Variables * **db_instance_class** - A DB instance class type and size. **Required** * **region_src** - The primary cluster region. **Required** * **region_dest** - The secondary cluster region. **Required** +* **db_subnet_group_name** - The name of subnet group. Dependencies ------------ diff --git a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml index 73b314ff..caab6d70 100644 --- a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml +++ b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml @@ -1 +1,2 @@ ---- \ No newline at end of file +--- +# defaults file for roles/create_global_cluster_with_rds_cluster \ No newline at end of file diff --git a/roles/create_global_cluster_with_rds_cluster/meta/main.yml b/roles/create_global_cluster_with_rds_cluster/meta/main.yml new file mode 100644 index 00000000..90cc9d0d --- /dev/null +++ b/roles/create_global_cluster_with_rds_cluster/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: cloud.aws_ops.aws_setup_credentials \ No newline at end of file diff --git a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml index 32e826ea..32aaaada 100644 --- a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml +++ b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml @@ -1,16 +1,18 @@ --- - name: Run 'create_global_cluster_with_rds_cluster' role module_defaults: - group/aws: "{{ aws_role_credentials }}" + group/aws: "{{ aws_setup_credentials__output }}" - block: - - name: Create global db + block: + # Error: unable to locate credentials + - name: Create global DB cluster amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ global_cluster_identifier }}" engine: "{{ engine }}" + region: "{{ region_primary }}" - # Create first rds cluster - - name: Create primary rds cluster that connects with global db + # Create first RDS cluster + - name: Create primary RDS cluster that connects with global db amazon.aws.rds_cluster: cluster_id: "{{ cluster_id }}" engine: "{{ engine }}" @@ -21,7 +23,7 @@ db_subnet_group_name: "{{ db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ global_cluster_identifier }}" - - name: Create a rds instance that connects with primary rds cluster + - name: Create a RDS instance that connects with primary RDS cluster amazon.aws.rds_instance: cluster_id: "{{ cluster_id }}" db_instance_identifier: "{{ instance_id }}" @@ -34,12 +36,12 @@ db_cluster_identifier: '{{ cluster_id }}' register: _result_cluster_info - - name: Set the ARN of the primary DB cluster + - name: Set the ARN of the primary RDS cluster set_fact: src_db_cluster_arn: '{{ _result_cluster_info.clusters[0].db_cluster_arn }}' - # Error: doesn't have binlogs enabled - - name: Create secondary rds cluster that connects with global db + # Replicating primary cluster + - name: Create secondary RDS cluster that connects with global DB cluster amazon.aws.rds_cluster: id: '{{ cluster_id }}-replica' state: present diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases new file mode 100644 index 00000000..cbb19a1d --- /dev/null +++ b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases @@ -0,0 +1,3 @@ +cloud/aws +role/create_global_cluster_with_rds_cluster +time=3m diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml new file mode 100644 index 00000000..09e37475 --- /dev/null +++ b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml @@ -0,0 +1,13 @@ +--- +test_cluster_id: ansible-test-cluster-{{ tiny_prefix }} +test_username: testrdsusername +test_password: test-rds_password +test_engine: aurora-mysql +test_instance_id: ansible-test-instance-{{ tiny_prefix }} +test_global_cluster_identifier: ansible-test-global-{{ tiny_prefix }} +test_allocated_storage: 20 +test_max_allocated_storage: 22 +test_db_instance_class: db.r5.large +test_region_src: us-east-1 +test_region_dest: us-east-1 +aws_security_token: '{{ security_token | default(omit) }}' \ No newline at end of file diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml new file mode 100644 index 00000000..d2171632 --- /dev/null +++ b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml @@ -0,0 +1,53 @@ +--- +- name: Integration tests for 'create_global_cluster_with_rds_cluster' role + module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + + block: + - name: create global db + ansible.builtin.include_role: + name: cloud.aws_ops.create_global_cluster_with_rds_cluster + vars: + global_cluster_identifier: "{{ test_global_cluster_identifier }}" + cluster_id: "{{ test_cluster_id }}" + username: "{{ test_username }}" + password: "{{ test_password }}" + engine: "{{ test_engine }}" + db_instance_class: "{{ test_db_instance_class }}" + region_primary: "{{ test_region_src }}" + region_secondary: "{{ test_region_dest }}" + instance_id: "{{ test_instance_id }}" + + always: + - name: Delete secondary rds cluster (replica) + amazon.aws.rds_cluster: + name: "{{ test_cluster_id }}-replica" + state: absent + force: true + ignore_errors: true + + - name: Delete primary rds instance + amazon.aws.rds_instance: + name: "{{ test_instance_id }}" + state: absent + force: true + ignore_errors: true + + - name: Delete primary rds cluster + amazon.aws.s3_bucket: + name: "{{ test_cluster_id }}" + state: absent + force: true + ignore_errors: true + + - name: Delete Aurora global cluster + amazon.aws.s3_bucket: + name: "{{ test_global_cluster_identifier }}" + state: absent + force: true + ignore_errors: true + From c401f73408205065e33ad363875e14aaa5f72aa8 Mon Sep 17 00:00:00 2001 From: Taeho Park Date: Fri, 4 Aug 2023 10:04:05 -0400 Subject: [PATCH 03/41] fixed some issues --- galaxy.yml | 1 + .../defaults/main.yml | 2 +- .../tasks/main.yml | 46 +++++++++---------- .../tasks/main.yml | 23 ++++++++++ 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/galaxy.yml b/galaxy.yml index d74fe5af..509ff62e 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -19,6 +19,7 @@ tags: dependencies: amazon.aws: '>=5.1.0' community.aws: '>=5.0.0' + amazon.cloud: '>=0.4.0' version: 1.0.3 build_ignore: - .DS_Store diff --git a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml index caab6d70..1ab6d94a 100644 --- a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml +++ b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml @@ -1,2 +1,2 @@ --- -# defaults file for roles/create_global_cluster_with_rds_cluster \ No newline at end of file +# defaults file for roles/create_global_cluster_with_rds_cluster diff --git a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml index 32aaaada..bc0ee7b2 100644 --- a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml +++ b/roles/create_global_cluster_with_rds_cluster/tasks/main.yml @@ -4,14 +4,14 @@ group/aws: "{{ aws_setup_credentials__output }}" block: - # Error: unable to locate credentials - - name: Create global DB cluster + # Create Aurora glboal DB cluster + - name: Create Aurora global DB cluster amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ global_cluster_identifier }}" engine: "{{ engine }}" region: "{{ region_primary }}" - # Create first RDS cluster + # Create primary RDS cluster and instance - name: Create primary RDS cluster that connects with global db amazon.aws.rds_cluster: cluster_id: "{{ cluster_id }}" @@ -22,6 +22,7 @@ region: "{{ region_primary }}" db_subnet_group_name: "{{ db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ global_cluster_identifier }}" + register: primary_cluster - name: Create a RDS instance that connects with primary RDS cluster amazon.aws.rds_instance: @@ -29,26 +30,23 @@ db_instance_identifier: "{{ instance_id }}" engine: "{{ engine }}" db_instance_class: "{{ db_instance_class }}" + + + - name: Create a RDS instance that connects with primary RDS cluster + amazon.aws.rds_instance: + cluster_id: "{{ cluster_id }}" + db_instance_identifier: "{{ instance_id }}-two" + engine: "{{ engine }}" + db_instance_class: "{{ db_instance_class }}" - # Obtain information about primary cluster - - name: Get info on primary cluster - amazon.aws.rds_cluster_info: - db_cluster_identifier: '{{ cluster_id }}' - register: _result_cluster_info - - - name: Set the ARN of the primary RDS cluster - set_fact: - src_db_cluster_arn: '{{ _result_cluster_info.clusters[0].db_cluster_arn }}' - - # Replicating primary cluster - - name: Create secondary RDS cluster that connects with global DB cluster + # Replicating primary cluster and instance + - name: Create primary RDS cluster that connects with global db amazon.aws.rds_cluster: - id: '{{ cluster_id }}-replica' - state: present - replication_source_identifier: '{{ src_db_cluster_arn }}' - engine: '{{ engine }}' - region: '{{ region_secondary }}' - tags: - Name: '{{ cluster_id }}' - Created_by: Ansible rds_cluster tests - wait: yes + cluster_id: "{{ cluster_id }}-replica" + engine: "{{ engine }}" + engine_mode: provisioned + username: "{{ username }}" + password: "{{ password }}" + region: "{{ region_secondary }}" + global_cluster_identifier: "{{ global_cluster_identifier }}" + diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml index d2171632..c8070c0a 100644 --- a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml @@ -1,6 +1,11 @@ --- - name: Integration tests for 'create_global_cluster_with_rds_cluster' role module_defaults: + group/amazon.cloud.aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" group/aws: aws_access_key: "{{ aws_access_key }}" aws_secret_key: "{{ aws_secret_key }}" @@ -21,6 +26,24 @@ region_primary: "{{ test_region_src }}" region_secondary: "{{ test_region_dest }}" instance_id: "{{ test_instance_id }}" + + - name: Get primary DB cluster information + amazon.aws.rds_cluster_info: + cluster_id: "{{ test_cluster_id }}" + register: test_cluster_info + + - name: Get secondary DB cluster information + amazon.aws.rds_cluster_info: + cluster_id: "{{ test_cluster_id }}-replica" + region: "{{ test_region_dest }}" + register: test_cluster_repli_info + + - name: Check primary cluster is replicated + assert: + that: + - test_cluster_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}" + - test_cluster_repli_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}-replica" + - test_cluster_info.clusters[0].read_replica_identifiers[0] == test_cluster_repli_info.clusters[0].db_cluster_arn always: - name: Delete secondary rds cluster (replica) From 963bfb2788ce897cd9fa10d1f3b088b2e2c3d0b6 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 10 Aug 2023 13:13:22 -0700 Subject: [PATCH 04/41] rename role, minor fixes --- .../defaults/main.yml | 2 -- .../meta/main.yml | 3 --- .../README.md | 6 ++---- roles/create_rds_global_cluster/defaults/main.yml | 2 ++ roles/create_rds_global_cluster/meta/main.yml | 3 +++ .../tasks/main.yml | 2 +- .../aliases | 3 --- .../targets/test_create_rds_global_cluster/aliases | 3 +++ .../defaults/main.yml | 2 +- .../tasks/main.yml | 13 ++++++------- 10 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 roles/create_global_cluster_with_rds_cluster/defaults/main.yml delete mode 100644 roles/create_global_cluster_with_rds_cluster/meta/main.yml rename roles/{create_global_cluster_with_rds_cluster => create_rds_global_cluster}/README.md (92%) create mode 100644 roles/create_rds_global_cluster/defaults/main.yml create mode 100644 roles/create_rds_global_cluster/meta/main.yml rename roles/{create_global_cluster_with_rds_cluster => create_rds_global_cluster}/tasks/main.yml (97%) delete mode 100644 tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases create mode 100644 tests/integration/targets/test_create_rds_global_cluster/aliases rename tests/integration/targets/{test_create_global_cluster_with_rds_cluster => test_create_rds_global_cluster}/defaults/main.yml (87%) rename tests/integration/targets/{test_create_global_cluster_with_rds_cluster => test_create_rds_global_cluster}/tasks/main.yml (93%) diff --git a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml b/roles/create_global_cluster_with_rds_cluster/defaults/main.yml deleted file mode 100644 index 1ab6d94a..00000000 --- a/roles/create_global_cluster_with_rds_cluster/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# defaults file for roles/create_global_cluster_with_rds_cluster diff --git a/roles/create_global_cluster_with_rds_cluster/meta/main.yml b/roles/create_global_cluster_with_rds_cluster/meta/main.yml deleted file mode 100644 index 90cc9d0d..00000000 --- a/roles/create_global_cluster_with_rds_cluster/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - role: cloud.aws_ops.aws_setup_credentials \ No newline at end of file diff --git a/roles/create_global_cluster_with_rds_cluster/README.md b/roles/create_rds_global_cluster/README.md similarity index 92% rename from roles/create_global_cluster_with_rds_cluster/README.md rename to roles/create_rds_global_cluster/README.md index 188badc4..12e0810d 100644 --- a/roles/create_global_cluster_with_rds_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -1,7 +1,7 @@ -create_global_cluster_with_rds_cluster +create_rds_global_cluster ========= -A role to create aurora global cluster with two different region rds clusters. +A role to create aurora-postgresql global cluster with two different region rds clusters. Requirements ------------ @@ -49,6 +49,4 @@ Example Playbook License ------- - GNU General Public License v3.0 or later - diff --git a/roles/create_rds_global_cluster/defaults/main.yml b/roles/create_rds_global_cluster/defaults/main.yml new file mode 100644 index 00000000..87e5916b --- /dev/null +++ b/roles/create_rds_global_cluster/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for roles/create_rds_global_cluster diff --git a/roles/create_rds_global_cluster/meta/main.yml b/roles/create_rds_global_cluster/meta/main.yml new file mode 100644 index 00000000..e8b3ab42 --- /dev/null +++ b/roles/create_rds_global_cluster/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: cloud.aws_ops.aws_setup_credentials diff --git a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml b/roles/create_rds_global_cluster/tasks/main.yml similarity index 97% rename from roles/create_global_cluster_with_rds_cluster/tasks/main.yml rename to roles/create_rds_global_cluster/tasks/main.yml index bc0ee7b2..ecd3029b 100644 --- a/roles/create_global_cluster_with_rds_cluster/tasks/main.yml +++ b/roles/create_rds_global_cluster/tasks/main.yml @@ -1,5 +1,5 @@ --- -- name: Run 'create_global_cluster_with_rds_cluster' role +- name: Run 'create_rds_global_cluster' role module_defaults: group/aws: "{{ aws_setup_credentials__output }}" diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases b/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases deleted file mode 100644 index cbb19a1d..00000000 --- a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/aliases +++ /dev/null @@ -1,3 +0,0 @@ -cloud/aws -role/create_global_cluster_with_rds_cluster -time=3m diff --git a/tests/integration/targets/test_create_rds_global_cluster/aliases b/tests/integration/targets/test_create_rds_global_cluster/aliases new file mode 100644 index 00000000..1825c036 --- /dev/null +++ b/tests/integration/targets/test_create_rds_global_cluster/aliases @@ -0,0 +1,3 @@ +cloud/aws +role/create_rds_global_cluster +time=3m diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml similarity index 87% rename from tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml rename to tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml index 09e37475..c40c1c99 100644 --- a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/defaults/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml @@ -10,4 +10,4 @@ test_max_allocated_storage: 22 test_db_instance_class: db.r5.large test_region_src: us-east-1 test_region_dest: us-east-1 -aws_security_token: '{{ security_token | default(omit) }}' \ No newline at end of file +aws_security_token: '{{ security_token | default(omit) }}' diff --git a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml similarity index 93% rename from tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml rename to tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index c8070c0a..488fa164 100644 --- a/tests/integration/targets/test_create_global_cluster_with_rds_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -1,5 +1,5 @@ --- -- name: Integration tests for 'create_global_cluster_with_rds_cluster' role +- name: Integration tests for 'create_rds_global_cluster' role module_defaults: group/amazon.cloud.aws: aws_access_key: "{{ aws_access_key }}" @@ -15,7 +15,7 @@ block: - name: create global db ansible.builtin.include_role: - name: cloud.aws_ops.create_global_cluster_with_rds_cluster + name: cloud.aws_ops.create_rds_global_cluster vars: global_cluster_identifier: "{{ test_global_cluster_identifier }}" cluster_id: "{{ test_cluster_id }}" @@ -26,7 +26,7 @@ region_primary: "{{ test_region_src }}" region_secondary: "{{ test_region_dest }}" instance_id: "{{ test_instance_id }}" - + - name: Get primary DB cluster information amazon.aws.rds_cluster_info: cluster_id: "{{ test_cluster_id }}" @@ -37,7 +37,7 @@ cluster_id: "{{ test_cluster_id }}-replica" region: "{{ test_region_dest }}" register: test_cluster_repli_info - + - name: Check primary cluster is replicated assert: that: @@ -59,18 +59,17 @@ state: absent force: true ignore_errors: true - + - name: Delete primary rds cluster amazon.aws.s3_bucket: name: "{{ test_cluster_id }}" state: absent force: true ignore_errors: true - + - name: Delete Aurora global cluster amazon.aws.s3_bucket: name: "{{ test_global_cluster_identifier }}" state: absent force: true ignore_errors: true - From 218c94bb400d40f1b482b42cbc6c0340bc6b33e1 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 11 Aug 2023 16:46:10 -0700 Subject: [PATCH 05/41] restructure create_rds_global_cluster role --- roles/create_rds_global_cluster/README.md | 48 +++++------- .../create_rds_global_cluster/tasks/main.yml | 78 +++++++++---------- 2 files changed, 57 insertions(+), 69 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 12e0810d..ff7ccfcb 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -1,7 +1,7 @@ create_rds_global_cluster ========= -A role to create aurora-postgresql global cluster with two different region rds clusters. +A role to create Amazon Aurora postgresql global cluster with two different region rds clusters. Requirements ------------ @@ -10,15 +10,24 @@ AWS credentials with valid permission. Role Variables -------------- -* **global_cluster_identifier** - Name of the Aurora global cluster. **Required** -* **cluster_id** - Name of the primary cluster. **Required** -* **username** - Username of the rds clusters. **Required** -* **password** - Password of the rds clusters. **Required** -* **engine** - Engine of the global and rds clusters. **Required** -* **db_instance_class** - A DB instance class type and size. **Required** -* **region_src** - The primary cluster region. **Required** -* **region_dest** - The secondary cluster region. **Required** -* **db_subnet_group_name** - The name of subnet group. +**Global cluster variables** +create_rds_global_cluster_global_cluster_name - Name of the Amazon Aurora global cluster. **required** +create_rds_global_cluster_enigne - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. +create_rds_global_cluster_engine_version - Engine version of the Amazon Aurora global and rds clusters. +create_rds_global_cluster_instance_class - Instance class of instance in primary and replica cluster. **required** +create_rds_global_cluster_username - Username of the rds clusters. **required** +create_rds_global_cluster_password - Password of the rds clusters. **required** + +**Primary cluster parameters** +create_rds_global_cluster_primary_cluster_name - Name of the primary cluster. Default is $create_rds_global_cluster_global_cluster_name. +create_rds_global_cluster_primary_cluster_region - Region of the primary cluster. **required** +create_rds_global_cluster_primary_cluster_instance_name - Name of the instance in primary cluster. **required** + +**Replica cluster parameters** +create_rds_global_cluster_replica_cluster_name - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. +create_rds_global_cluster_replica_cluster_region - Region of the replica (secondary) cluster. **required** +create_rds_global_cluster_replica_cluster_instance_name - Name of the instance in secondary cluster. **required** +create_rds_global_cluster_replica_enable_global_write_forwarding - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Dependencies ------------ @@ -27,25 +36,6 @@ Dependencies Example Playbook ---------------- ---- -- name: Playbook for move objects between buckets using cloud.aws_ops.move_objects_between_buckets role - hosts: localhost - gather_facts: false - tasks: - - name: Move one object between buckets - ansible.builtin.include_role: - name: cloud.aws_ops.move_objects_between_buckets - vars: - global_cluster_identifier: global_cluster_name - cluster_id: cluster_name - username: username - password: password123 - engine: aurora-postgresql - db_subnet_group_name: subnet_group_name - db_instance_class: db.r5.large - region_primary: us-east-2 - region_secondary: us-east-1 - instance_id: instance_id_name License ------- diff --git a/roles/create_rds_global_cluster/tasks/main.yml b/roles/create_rds_global_cluster/tasks/main.yml index ecd3029b..47b0e593 100644 --- a/roles/create_rds_global_cluster/tasks/main.yml +++ b/roles/create_rds_global_cluster/tasks/main.yml @@ -3,50 +3,48 @@ module_defaults: group/aws: "{{ aws_setup_credentials__output }}" - block: - # Create Aurora glboal DB cluster - - name: Create Aurora global DB cluster + block: + - name: Create rds global database amazon.cloud.rds_global_cluster: - global_cluster_identifier: "{{ global_cluster_identifier }}" - engine: "{{ engine }}" - region: "{{ region_primary }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + state: present - # Create primary RDS cluster and instance - - name: Create primary RDS cluster that connects with global db + - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: - cluster_id: "{{ cluster_id }}" - engine: "{{ engine }}" - engine_mode: provisioned - username: "{{ username }}" - password: "{{ password }}" - region: "{{ region_primary }}" - db_subnet_group_name: "{{ db_subnet_group_name | default(omit) }}" - global_cluster_identifier: "{{ global_cluster_identifier }}" - register: primary_cluster - - - name: Create a RDS instance that connects with primary RDS cluster - amazon.aws.rds_instance: - cluster_id: "{{ cluster_id }}" - db_instance_identifier: "{{ instance_id }}" - engine: "{{ engine }}" - db_instance_class: "{{ db_instance_class }}" - - - - name: Create a RDS instance that connects with primary RDS cluster + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + username: "{{ create_rds_global_cluster_username }}" + password: "{{ create_rds_global_cluster_password }}" + db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + ignore_errors: true + + - name: Create an instance connected to primary cluster amazon.aws.rds_instance: - cluster_id: "{{ cluster_id }}" - db_instance_identifier: "{{ instance_id }}-two" - engine: "{{ engine }}" - db_instance_class: "{{ db_instance_class }}" + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" #what cluster instance should be in + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - # Replicating primary cluster and instance - - name: Create primary RDS cluster that connects with global db + - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: - cluster_id: "{{ cluster_id }}-replica" - engine: "{{ engine }}" - engine_mode: provisioned - username: "{{ username }}" - password: "{{ password }}" - region: "{{ region_secondary }}" - global_cluster_identifier: "{{ global_cluster_identifier }}" + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" + enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(False) }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + - name: Create an instance connected to secondary cluster + amazon.aws.rds_instance: + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" #what cluster instance should be in + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" \ No newline at end of file From d120444fe148e7fe10a443dba5c68923de8e65d3 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 11 Aug 2023 16:49:47 -0700 Subject: [PATCH 06/41] update readme --- roles/create_rds_global_cluster/README.md | 37 ++++++++++--------- .../create_rds_global_cluster/tasks/main.yml | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index ff7ccfcb..fa11fd06 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -1,7 +1,8 @@ create_rds_global_cluster ========= -A role to create Amazon Aurora postgresql global cluster with two different region rds clusters. +A role to create Amazon Aurora global cluster with two different region rds clusters. +Creates a Aurora Postgresql global cluster by default. Requirements ------------ @@ -11,23 +12,23 @@ AWS credentials with valid permission. Role Variables -------------- **Global cluster variables** -create_rds_global_cluster_global_cluster_name - Name of the Amazon Aurora global cluster. **required** -create_rds_global_cluster_enigne - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. -create_rds_global_cluster_engine_version - Engine version of the Amazon Aurora global and rds clusters. -create_rds_global_cluster_instance_class - Instance class of instance in primary and replica cluster. **required** -create_rds_global_cluster_username - Username of the rds clusters. **required** -create_rds_global_cluster_password - Password of the rds clusters. **required** - -**Primary cluster parameters** -create_rds_global_cluster_primary_cluster_name - Name of the primary cluster. Default is $create_rds_global_cluster_global_cluster_name. -create_rds_global_cluster_primary_cluster_region - Region of the primary cluster. **required** -create_rds_global_cluster_primary_cluster_instance_name - Name of the instance in primary cluster. **required** - -**Replica cluster parameters** -create_rds_global_cluster_replica_cluster_name - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. -create_rds_global_cluster_replica_cluster_region - Region of the replica (secondary) cluster. **required** -create_rds_global_cluster_replica_cluster_instance_name - Name of the instance in secondary cluster. **required** -create_rds_global_cluster_replica_enable_global_write_forwarding - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. +- **create_rds_global_cluster_global_cluster_name** - Name of the Amazon Aurora global cluster. **required** +- **create_rds_global_cluster_enigne** - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. +- **create_rds_global_cluster_engine_version** - Engine version of the Amazon Aurora global and rds clusters. +- **create_rds_global_cluster_instance_class** - Instance class of instance in primary and replica cluster. **required** +- **create_rds_global_cluster_username** - Username of the rds clusters. **required** +- **create_rds_global_cluster_password** - Password of the rds clusters. **required** + +**Primary cluster variables** +- **create_rds_global_cluster_primary_cluster_name** - Name of the primary cluster. Default is $create_rds_global_cluster_global_cluster_name. +- **create_rds_global_cluster_primary_cluster_region** - Region of the primary cluster. **required** +- **create_rds_global_cluster_primary_cluster_instance_name** - Name of the instance in primary cluster. **required** + +**Replica cluster variables** +- **create_rds_global_cluster_replica_cluster_name** - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. +- **create_rds_global_cluster_replica_cluster_region** - Region of the replica (secondary) cluster. **required** +- **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** +- **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Dependencies ------------ diff --git a/roles/create_rds_global_cluster/tasks/main.yml b/roles/create_rds_global_cluster/tasks/main.yml index 47b0e593..733ce804 100644 --- a/roles/create_rds_global_cluster/tasks/main.yml +++ b/roles/create_rds_global_cluster/tasks/main.yml @@ -47,4 +47,4 @@ db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_enigne }}" - db_instance_class: "{{ create_rds_global_cluster_instance_class }}" \ No newline at end of file + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" From ea16e0397c83fbe55ef756fce6a77e3f4e6c32a0 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 11 Aug 2023 16:54:32 -0700 Subject: [PATCH 07/41] update readme --- roles/create_rds_global_cluster/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index fa11fd06..12b0b96d 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -2,7 +2,13 @@ create_rds_global_cluster ========= A role to create Amazon Aurora global cluster with two different region rds clusters. -Creates a Aurora Postgresql global cluster by default. + +Creates following resources +1. Global Cluster - Amazon Aurora Postgresql. +2. Primary Cluster - Primary cluster in specified region (create_rds_global_cluster_primary_cluster_region). +3. Primary Cluster Instance - Instance in the primary cluster. +4. Replica (secondary) Cluster - Secondary cluster in specified region (create_rds_global_cluster_replica_cluster_region). +5. Replica Cluster Instance - Instance in the replica cluster. Requirements ------------ From 1d19c6ba6f2a3d28e9a48eabaab9b475498dbeca Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 14 Aug 2023 17:08:08 -0700 Subject: [PATCH 08/41] updates to tests --- roles/create_rds_global_cluster/README.md | 3 +- .../tasks/create.yml | 50 +++++++ .../tasks/delete.yml | 1 + .../create_rds_global_cluster/tasks/main.yml | 46 +------ .../defaults/main.yml | 28 ++-- .../tasks/main.yml | 130 ++++++++++-------- 6 files changed, 150 insertions(+), 108 deletions(-) create mode 100644 roles/create_rds_global_cluster/tasks/create.yml create mode 100644 roles/create_rds_global_cluster/tasks/delete.yml diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 12b0b96d..8bb8b890 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -34,7 +34,8 @@ Role Variables - **create_rds_global_cluster_replica_cluster_name** - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. - **create_rds_global_cluster_replica_cluster_region** - Region of the replica (secondary) cluster. **required** - **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** -- **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. +- **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Supported only while creating new cluster. Choices include 'true', 'false, 'yes', 'no'. +- **create_rds_global_cluster_operation** - Choices include 'create' and 'delete' to create or delete the resources. Dependencies ------------ diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml new file mode 100644 index 00000000..9eaa6c5b --- /dev/null +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -0,0 +1,50 @@ +--- +- name: Run 'create_rds_global_cluster' role + module_defaults: + group/aws: "{{ aws_setup_credentials__output }}" + + block: + - name: Create rds global database + amazon.cloud.rds_global_cluster: + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + state: present + + - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + username: "{{ create_rds_global_cluster_username }}" + password: "{{ create_rds_global_cluster_password }}" + db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + ignore_errors: true + + - name: Create an instance connected to primary cluster + amazon.aws.rds_instance: + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" # what cluster instance should be in + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" + + - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" + enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(False) }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + + - name: Create an instance connected to secondary cluster + amazon.aws.rds_instance: + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" # what cluster instance should be in + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + engine: "{{ create_rds_global_cluster_enigne }}" + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" \ No newline at end of file diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -0,0 +1 @@ +--- diff --git a/roles/create_rds_global_cluster/tasks/main.yml b/roles/create_rds_global_cluster/tasks/main.yml index 733ce804..a099ba7a 100644 --- a/roles/create_rds_global_cluster/tasks/main.yml +++ b/roles/create_rds_global_cluster/tasks/main.yml @@ -4,47 +4,5 @@ group/aws: "{{ aws_setup_credentials__output }}" block: - - name: Create rds global database - amazon.cloud.rds_global_cluster: - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" - state: present - - - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" - amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name - region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" - username: "{{ create_rds_global_cluster_username }}" - password: "{{ create_rds_global_cluster_password }}" - db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - ignore_errors: true - - - name: Create an instance connected to primary cluster - amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" #what cluster instance should be in - db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" - db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - - - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" - amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name - region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" - db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(False) }}" - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - - - name: Create an instance connected to secondary cluster - amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" #what cluster instance should be in - db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" - db_instance_class: "{{ create_rds_global_cluster_instance_class }}" + - name: Include file + ansible.builtin.include_tasks: "{{ create_rds_global_cluster_operation }}.yml" diff --git a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml index c40c1c99..b09cae8b 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml @@ -1,13 +1,23 @@ --- -test_cluster_id: ansible-test-cluster-{{ tiny_prefix }} +test_enigne: aurora-mysql +test_engine_version: 5.7 +test_instance_class: db.r5.large test_username: testrdsusername test_password: test-rds_password -test_engine: aurora-mysql -test_instance_id: ansible-test-instance-{{ tiny_prefix }} -test_global_cluster_identifier: ansible-test-global-{{ tiny_prefix }} -test_allocated_storage: 20 -test_max_allocated_storage: 22 -test_db_instance_class: db.r5.large -test_region_src: us-east-1 -test_region_dest: us-east-1 +test_primary_cluster_subnet_group_name: '' + +# Global cluster parameters ================================ +test_global_cluster_name: ansible-test-global-{{ tiny_prefix }} + +# Primary cluster parameters ================================ +test_primary_cluster_name: ansible-test-primary-{{ tiny_prefix }} +test_primary_cluster_region: us-east-1 +test_primary_cluster_instance_name: ansible-test-instance-primary-{{ tiny_prefix }} + +# Replica cluster parameters ================================ +test_replica_cluster_name: ansible-test-replica-{{ tiny_prefix }} +test_replica_cluster_region: us-west-2 +test_replica_enable_global_write_forwarding: 'true' +test_replica_cluster_instance_name: ansible-test-instance-replica-{{ tiny_prefix }} + aws_security_token: '{{ security_token | default(omit) }}' diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 488fa164..99b5c25a 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -12,64 +12,86 @@ security_token: "{{ security_token | default(omit) }}" region: "{{ aws_region }}" - block: - - name: create global db - ansible.builtin.include_role: - name: cloud.aws_ops.create_rds_global_cluster - vars: - global_cluster_identifier: "{{ test_global_cluster_identifier }}" - cluster_id: "{{ test_cluster_id }}" - username: "{{ test_username }}" - password: "{{ test_password }}" - engine: "{{ test_engine }}" - db_instance_class: "{{ test_db_instance_class }}" - region_primary: "{{ test_region_src }}" - region_secondary: "{{ test_region_dest }}" - instance_id: "{{ test_instance_id }}" + # Due to CI limitations, it is not possible to create a replica in another region + # and with AWS limitations we cannot create a replica cluster in same region as primary cluster i.e. us-east-1 - - name: Get primary DB cluster information - amazon.aws.rds_cluster_info: - cluster_id: "{{ test_cluster_id }}" - register: test_cluster_info + # block: + # - name: create global db + # ansible.builtin.include_role: + # name: cloud.aws_ops.create_rds_global_cluster + # vars: + # create_rds_global_cluster_operation: create + # create_rds_global_cluster_enigne: "{{ test_enigne }}" + # create_rds_global_cluster_engine_version: "{{ test_engine_version }}" + # create_rds_global_cluster_instance_class: "{{ test_instance_class }}" + # create_rds_global_cluster_username: "{{ test_username }}" + # create_rds_global_cluster_password: "{{ test_password }}" + # create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" + # create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" + # create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" + # create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" + # create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" + # create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" + # create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + # create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" - - name: Get secondary DB cluster information - amazon.aws.rds_cluster_info: - cluster_id: "{{ test_cluster_id }}-replica" - region: "{{ test_region_dest }}" - register: test_cluster_repli_info + # - name: Get Global DB information + # amazon.aws.rds_cluster_info: + # cluster_id: "{{ test_global_cluster_name }}" + # register: global_cluster_info - - name: Check primary cluster is replicated - assert: - that: - - test_cluster_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}" - - test_cluster_repli_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}-replica" - - test_cluster_info.clusters[0].read_replica_identifiers[0] == test_cluster_repli_info.clusters[0].db_cluster_arn + # - name: Get primary DB cluster information + # amazon.aws.rds_cluster_info: + # cluster_id: "{{ test_primary_cluster_name }}" + # register: primary_cluster_info - always: - - name: Delete secondary rds cluster (replica) - amazon.aws.rds_cluster: - name: "{{ test_cluster_id }}-replica" - state: absent - force: true - ignore_errors: true + # - name: Get secondary DB cluster information + # amazon.aws.rds_cluster_info: + # cluster_id: "{{ test_replica_cluster_name }}" + # region: "{{ test_replica_cluster_region }}" + # register: replica_cluster_info - - name: Delete primary rds instance - amazon.aws.rds_instance: - name: "{{ test_instance_id }}" - state: absent - force: true - ignore_errors: true + # - name: Check primary cluster is replicated + # assert: + # that: + # - test_cluster_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}" + # - test_cluster_repli_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}-replica" + # - test_cluster_info.clusters[0].read_replica_identifiers[0] == test_cluster_repli_info.clusters[0].db_cluster_arn - - name: Delete primary rds cluster - amazon.aws.s3_bucket: - name: "{{ test_cluster_id }}" - state: absent - force: true - ignore_errors: true + # always: - - name: Delete Aurora global cluster - amazon.aws.s3_bucket: - name: "{{ test_global_cluster_identifier }}" - state: absent - force: true - ignore_errors: true + # - name: Delete secondary rds cluster instance (replica) + # amazon.aws.rds_instance: + # name: "{{ test_replica_cluster_instance_name }}" + # state: absent + # force: true + # ignore_errors: true + + # - name: Delete secondary rds cluster (replica) + # amazon.aws.rds_cluster: + # name: "{{ test_replica_cluster_name }}" + # region: "{{ test_replica_cluster_region }}" + # state: absent + # force: true + # ignore_errors: true + + # - name: Delete primary rds cluster instance + # amazon.aws.rds_instance: + # name: "{{ test_primary_cluster_instance_name }}" + # state: absent + # force: true + # ignore_errors: true + + # - name: Delete primary rds cluster + # amazon.aws.rds_cluster: + # name: "{{ test_primary_cluster_name }}" + # state: absent + # force: true + # ignore_errors: true + + # - name: Delete Aurora global cluster + # amazon.aws.rds_cluster: + # name: "{{ test_global_cluster_identifier }}" + # state: absent + # force: true + # ignore_errors: true From 7c02c818774744a21c074dc35f4b925e42a51e22 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 14 Aug 2023 17:11:57 -0700 Subject: [PATCH 09/41] add newline at EOF --- roles/create_rds_global_cluster/tasks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 9eaa6c5b..c47cf450 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -47,4 +47,4 @@ db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_enigne }}" - db_instance_class: "{{ create_rds_global_cluster_instance_class }}" \ No newline at end of file + db_instance_class: "{{ create_rds_global_cluster_instance_class }}" From e8a23dcb16e64615ab283efa7d1e74d6381efe61 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 16 Aug 2023 00:00:46 -0700 Subject: [PATCH 10/41] update tests --- roles/create_rds_global_cluster/README.md | 2 +- .../tasks/create.yml | 1 - .../tasks/main.yml | 151 ++++++++++-------- 3 files changed, 81 insertions(+), 73 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 8bb8b890..1447ddd8 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -19,7 +19,7 @@ Role Variables -------------- **Global cluster variables** - **create_rds_global_cluster_global_cluster_name** - Name of the Amazon Aurora global cluster. **required** -- **create_rds_global_cluster_enigne** - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. +- **create_rds_global_cluster_engine** - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. - **create_rds_global_cluster_engine_version** - Engine version of the Amazon Aurora global and rds clusters. - **create_rds_global_cluster_instance_class** - Instance class of instance in primary and replica cluster. **required** - **create_rds_global_cluster_username** - Username of the rds clusters. **required** diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index c47cf450..f8d1c345 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -38,7 +38,6 @@ engine: "{{ create_rds_global_cluster_enigne }}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(False) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to - name: Create an instance connected to secondary cluster diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 99b5c25a..f8333626 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -14,84 +14,93 @@ # Due to CI limitations, it is not possible to create a replica in another region # and with AWS limitations we cannot create a replica cluster in same region as primary cluster i.e. us-east-1 + # can be run on team account + block: + - name: create global db + ansible.builtin.include_role: + name: cloud.aws_ops.create_rds_global_cluster + vars: + create_rds_global_cluster_operation: create + create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine_version: "{{ test_engine_version }}" + create_rds_global_cluster_instance_class: "{{ test_instance_class }}" + create_rds_global_cluster_username: "{{ test_username }}" + create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" + create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" + create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" + create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" + create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" + create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" + create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" - # block: - # - name: create global db - # ansible.builtin.include_role: - # name: cloud.aws_ops.create_rds_global_cluster - # vars: - # create_rds_global_cluster_operation: create - # create_rds_global_cluster_enigne: "{{ test_enigne }}" - # create_rds_global_cluster_engine_version: "{{ test_engine_version }}" - # create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - # create_rds_global_cluster_username: "{{ test_username }}" - # create_rds_global_cluster_password: "{{ test_password }}" - # create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" - # create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" - # create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" - # create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" - # create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" - # create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" - # create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" - # create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" + - name: Get Global DB information + amazon.cloud.rds_global_cluster: + global_cluster_identifier: "{{ test_global_cluster_name }}" + state: describe + register: global_cluster_info - # - name: Get Global DB information - # amazon.aws.rds_cluster_info: - # cluster_id: "{{ test_global_cluster_name }}" - # register: global_cluster_info + - name: Get primary DB cluster information + amazon.aws.rds_cluster_info: + cluster_id: "{{ test_primary_cluster_name }}" + region: "{{ test_primary_cluster_region }}" + register: primary_cluster_info - # - name: Get primary DB cluster information - # amazon.aws.rds_cluster_info: - # cluster_id: "{{ test_primary_cluster_name }}" - # register: primary_cluster_info + - name: Get secondary DB cluster information + amazon.aws.rds_cluster_info: + cluster_id: "{{ test_replica_cluster_name }}" + region: "{{ test_replica_cluster_region }}" + register: replica_cluster_info - # - name: Get secondary DB cluster information - # amazon.aws.rds_cluster_info: - # cluster_id: "{{ test_replica_cluster_name }}" - # region: "{{ test_replica_cluster_region }}" - # register: replica_cluster_info - - # - name: Check primary cluster is replicated - # assert: - # that: - # - test_cluster_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}" - # - test_cluster_repli_info.clusters[0].db_cluster_identifier == "{{ test_cluster_id }}-replica" - # - test_cluster_info.clusters[0].read_replica_identifiers[0] == test_cluster_repli_info.clusters[0].db_cluster_arn + - name: Verify resources are created successfully + assert: + that: + - global_cluster_info.result.identifier == "{{ test_global_cluster_name }}" + - global_cluster_info.result.properties.source_db_cluster_identifier == primary_cluster_info.clusters[0].db_cluster_arn + - primary_cluster_info.clusters[0].db_cluster_identifier == "{{ test_primary_cluster_name }}" + - "'{{ test_primary_cluster_region }}' in primary_cluster_info.clusters[0].availability_zones[0]" + - replica_cluster_info.clusters[0].db_cluster_identifier == "{{ test_replica_cluster_name }}" + - "'{{ test_replica_cluster_region }}' in replica_cluster_info.clusters[0].availability_zones[0]" + - replica_cluster_info.clusters[0].replication_source_identifier == primary_cluster_info.clusters[0].db_cluster_arn - # always: + always: - # - name: Delete secondary rds cluster instance (replica) - # amazon.aws.rds_instance: - # name: "{{ test_replica_cluster_instance_name }}" - # state: absent - # force: true - # ignore_errors: true + - name: Delete secondary rds cluster instance (replica) + amazon.aws.rds_instance: + db_instance_identifier: "{{ test_replica_cluster_instance_name }}" + region: "{{ test_replica_cluster_region }}" + skip_final_snapshot: true + state: absent + ignore_errors: true - # - name: Delete secondary rds cluster (replica) - # amazon.aws.rds_cluster: - # name: "{{ test_replica_cluster_name }}" - # region: "{{ test_replica_cluster_region }}" - # state: absent - # force: true - # ignore_errors: true + # disabled: does not work currently, error - cluster is part of global db, remove from global db to delete + # - name: Delete secondary rds cluster (replica) + # amazon.aws.rds_cluster: + # db_cluster_identifier: "{{ test_replica_cluster_name }}" + # region: "{{ test_replica_cluster_region }}" + # skip_final_snapshot: true + # state: absent + # ignore_errors: true - # - name: Delete primary rds cluster instance - # amazon.aws.rds_instance: - # name: "{{ test_primary_cluster_instance_name }}" - # state: absent - # force: true - # ignore_errors: true + - name: Delete primary rds cluster instance + amazon.aws.rds_instance: + db_instance_identifier: "{{ test_primary_cluster_instance_name }}" + region: "{{ test_primary_cluster_region }}" + skip_final_snapshot: true + state: absent + ignore_errors: true - # - name: Delete primary rds cluster - # amazon.aws.rds_cluster: - # name: "{{ test_primary_cluster_name }}" - # state: absent - # force: true - # ignore_errors: true + - name: Delete primary rds cluster + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ test_primary_cluster_name }}" + region: "{{ test_primary_cluster_region }}" + skip_final_snapshot: true + state: absent + ignore_errors: true - # - name: Delete Aurora global cluster - # amazon.aws.rds_cluster: - # name: "{{ test_global_cluster_identifier }}" - # state: absent - # force: true - # ignore_errors: true + - name: Delete Aurora global cluster + amazon.cloud.rds_global_cluster: + global_cluster_identifier: "{{ test_global_cluster_name }}" + state: absent + ignore_errors: true From 8ab2d34a48eb736571fbc5cde8788b25d0443114 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 29 Aug 2023 12:23:23 -0700 Subject: [PATCH 11/41] add example playbook to readme --- roles/create_rds_global_cluster/README.md | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 1447ddd8..71a68717 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -44,6 +44,31 @@ Dependencies Example Playbook ---------------- +``` +--- +- name: Playbook for demonstrating use of cloud.aws_ops.create_rds_global_cluster role + hosts: localhost + gather_facts: false + tasks: + - name: Create global db, primary cluster with instance & replica cluster with instance + ansible.builtin.include_role: + name: cloud.aws_ops.create_rds_global_cluster + vars: + create_rds_global_cluster_operation: create + create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine_version: "{{ test_engine_version }}" + create_rds_global_cluster_instance_class: "{{ test_instance_class }}" + create_rds_global_cluster_username: "{{ test_username }}" + create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" + create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" + create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" + create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" + create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" + create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" + create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" +``` License ------- From 408a659ca72b3bcad696dd3b585037e3bd227e12 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 29 Sep 2023 18:05:37 -0700 Subject: [PATCH 12/41] add code to handle deleting created infra --- .../tasks/create.yml | 3 +- .../tasks/delete.yml | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index f8d1c345..e210634b 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -1,5 +1,5 @@ --- -- name: Run 'create_rds_global_cluster' role +- name: Run 'create_rds_global_cluster' role create operations module_defaults: group/aws: "{{ aws_setup_credentials__output }}" @@ -9,6 +9,7 @@ global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index ed97d539..80cdb560 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -1 +1,78 @@ --- +- name: Run 'create_rds_global_cluster' role delete operations + module_defaults: + group/aws: "{{ aws_setup_credentials__output }}" + + block: + - name: Get replica cluster info + amazon.aws.rds_cluster_info: + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + register: _result_replica_cluster_info + + - name: If replica cluster exists + block: + - name: Delete instance attached to replica cluster if present + amazon.aws.rds_instance: + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + skip_final_snapshot: true + wait: false + state: absent + when: _result_replica_cluster_info.clusters[0].db_cluster_members | length >= 1 + + - name: Delete replica cluster without creating a final snapshot + amazon.aws.rds_cluster: + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" + region: "{{ create_rds_global_cluster_replica_cluster_region }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + remove_from_global_db: true + skip_final_snapshot: True + state: absent + when: _result_replica_cluster_info.clusters | length != 0 + + - name: Get primary cluster info + amazon.aws.rds_cluster_info: + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + register: _result_primary_cluster_info + + - name: If primary cluster exists + block: + - name: Delete instance attached to primary cluster if present + amazon.aws.rds_instance: + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + skip_final_snapshot: true + wait: false + state: absent + when: _result_primary_cluster_info.clusters[0].db_cluster_members | length >= 1 + + - name: Delete primary cluster without creating a final snapshot + amazon.aws.rds_cluster: + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + remove_from_global_db: true + skip_final_snapshot: True + state: absent + when: _result_primary_cluster_info.clusters | length != 0 + + - name: Delete the global cluster + amazon.cloud.rds_global_cluster: + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" + region: "{{ create_rds_global_cluster_primary_cluster_region }}" + state: absent + register: _result_global_cluster_delete + + - name: Print success or failure + debug: + msg: + - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deleted successfully' + when: _result_global_cluster_delete is not failed + + - name: Print success or failure + debug: + msg: + - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deletion failed' + when: _result_global_cluster_delete is failed From 79490b13d267b5f49b2eb65a6326536427d9f60f Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 29 Sep 2023 18:15:06 -0700 Subject: [PATCH 13/41] add example for `delete` --- roles/create_rds_global_cluster/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 71a68717..e16fc951 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -35,6 +35,7 @@ Role Variables - **create_rds_global_cluster_replica_cluster_region** - Region of the replica (secondary) cluster. **required** - **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** - **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Supported only while creating new cluster. Choices include 'true', 'false, 'yes', 'no'. + - **create_rds_global_cluster_operation** - Choices include 'create' and 'delete' to create or delete the resources. Dependencies @@ -68,6 +69,25 @@ Example Playbook create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" + + - name: Delete global db, primary cluster with instance & replica cluster with instance + ansible.builtin.include_role: + name: cloud.aws_ops.create_rds_global_cluster + vars: + create_rds_global_cluster_operation: delete + create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine_version: "{{ test_engine_version }}" + create_rds_global_cluster_instance_class: "{{ test_instance_class }}" + create_rds_global_cluster_username: "{{ test_username }}" + create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" + create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" + create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" + create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" + create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" + create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" + create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" ``` License From 97e4c3b49abb0dd92185f9a502fae3b5270185f1 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Fri, 29 Sep 2023 18:17:42 -0700 Subject: [PATCH 14/41] fix tests --- .../tasks/main.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index f8333626..5aaa6beb 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -74,14 +74,15 @@ state: absent ignore_errors: true - # disabled: does not work currently, error - cluster is part of global db, remove from global db to delete - # - name: Delete secondary rds cluster (replica) - # amazon.aws.rds_cluster: - # db_cluster_identifier: "{{ test_replica_cluster_name }}" - # region: "{{ test_replica_cluster_region }}" - # skip_final_snapshot: true - # state: absent - # ignore_errors: true + - name: Delete secondary rds cluster (replica) + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ test_replica_cluster_name }}" + region: "{{ test_replica_cluster_region }}" + remove_from_global_db: true + global_cluster_identifier: "{{ test_global_cluster_name }}" + skip_final_snapshot: true + state: absent + ignore_errors: true - name: Delete primary rds cluster instance amazon.aws.rds_instance: From daba80ebfeaffea00aad91605444fec3d6db067d Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 2 Oct 2023 18:05:07 -0700 Subject: [PATCH 15/41] global cluster engine fix --- roles/create_rds_global_cluster/README.md | 4 +++- roles/create_rds_global_cluster/tasks/create.yml | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index e16fc951..26312352 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -4,12 +4,14 @@ create_rds_global_cluster A role to create Amazon Aurora global cluster with two different region rds clusters. Creates following resources -1. Global Cluster - Amazon Aurora Postgresql. +1. Global Cluster - Amazon Aurora Postgresql or Amazon Aurora MySql cluster. If `create_rds_global_cluster_engine` not provided, Defaults to Amazon Aurora Postgresql. 2. Primary Cluster - Primary cluster in specified region (create_rds_global_cluster_primary_cluster_region). 3. Primary Cluster Instance - Instance in the primary cluster. 4. Replica (secondary) Cluster - Secondary cluster in specified region (create_rds_global_cluster_replica_cluster_region). 5. Replica Cluster Instance - Instance in the replica cluster. +Please refer `Role Variables` for varialbes and usage. + Requirements ------------ diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index e210634b..c5080cb7 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -16,27 +16,26 @@ amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" username: "{{ create_rds_global_cluster_username }}" password: "{{ create_rds_global_cluster_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to - ignore_errors: true - name: Create an instance connected to primary cluster amazon.aws.rds_instance: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to @@ -46,5 +45,5 @@ db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne }}" + engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" From ff3206c27c698fd225b818099c87cf149dac7349 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 2 Oct 2023 22:56:38 -0700 Subject: [PATCH 16/41] minor fixes --- roles/create_rds_global_cluster/tasks/delete.yml | 3 --- .../targets/test_create_rds_global_cluster/tasks/main.yml | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 80cdb560..218532c3 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -19,7 +19,6 @@ skip_final_snapshot: true wait: false state: absent - when: _result_replica_cluster_info.clusters[0].db_cluster_members | length >= 1 - name: Delete replica cluster without creating a final snapshot amazon.aws.rds_cluster: @@ -46,14 +45,12 @@ skip_final_snapshot: true wait: false state: absent - when: _result_primary_cluster_info.clusters[0].db_cluster_members | length >= 1 - name: Delete primary cluster without creating a final snapshot amazon.aws.rds_cluster: cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - remove_from_global_db: true skip_final_snapshot: True state: absent when: _result_primary_cluster_info.clusters | length != 0 diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 5aaa6beb..21b78e0e 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -38,6 +38,7 @@ - name: Get Global DB information amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ test_global_cluster_name }}" + region: "{{ test_primary_cluster_region }}" state: describe register: global_cluster_info @@ -103,5 +104,6 @@ - name: Delete Aurora global cluster amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ test_global_cluster_name }}" + region: "{{ test_primary_cluster_region }}" state: absent ignore_errors: true From 541082d80f0694b1f1a608b6f40505144211cf01 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 2 Oct 2023 23:59:57 -0700 Subject: [PATCH 17/41] replace manual cleanup tasks with role specific deletion task --- .../tasks/main.yml | 58 ++++++------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 21b78e0e..9f41ab88 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -67,43 +67,21 @@ always: - - name: Delete secondary rds cluster instance (replica) - amazon.aws.rds_instance: - db_instance_identifier: "{{ test_replica_cluster_instance_name }}" - region: "{{ test_replica_cluster_region }}" - skip_final_snapshot: true - state: absent - ignore_errors: true - - - name: Delete secondary rds cluster (replica) - amazon.aws.rds_cluster: - db_cluster_identifier: "{{ test_replica_cluster_name }}" - region: "{{ test_replica_cluster_region }}" - remove_from_global_db: true - global_cluster_identifier: "{{ test_global_cluster_name }}" - skip_final_snapshot: true - state: absent - ignore_errors: true - - - name: Delete primary rds cluster instance - amazon.aws.rds_instance: - db_instance_identifier: "{{ test_primary_cluster_instance_name }}" - region: "{{ test_primary_cluster_region }}" - skip_final_snapshot: true - state: absent - ignore_errors: true - - - name: Delete primary rds cluster - amazon.aws.rds_cluster: - db_cluster_identifier: "{{ test_primary_cluster_name }}" - region: "{{ test_primary_cluster_region }}" - skip_final_snapshot: true - state: absent - ignore_errors: true - - - name: Delete Aurora global cluster - amazon.cloud.rds_global_cluster: - global_cluster_identifier: "{{ test_global_cluster_name }}" - region: "{{ test_primary_cluster_region }}" - state: absent - ignore_errors: true + - name: create global db + ansible.builtin.include_role: + name: cloud.aws_ops.create_rds_global_cluster + vars: + create_rds_global_cluster_operation: delete + create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine_version: "{{ test_engine_version }}" + create_rds_global_cluster_instance_class: "{{ test_instance_class }}" + create_rds_global_cluster_username: "{{ test_username }}" + create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" + create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" + create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" + create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" + create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" + create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" + create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" From 8ba1e02620f7f435bedbd605f328d4892610818c Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 3 Oct 2023 00:03:37 -0700 Subject: [PATCH 18/41] minor fixes --- roles/create_rds_global_cluster/README.md | 4 ++-- roles/create_rds_global_cluster/tasks/create.yml | 10 +++++----- .../test_create_rds_global_cluster/defaults/main.yml | 4 ++-- .../test_create_rds_global_cluster/tasks/main.yml | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 26312352..c337257c 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -58,7 +58,7 @@ Example Playbook name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: create - create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" create_rds_global_cluster_username: "{{ test_username }}" @@ -77,7 +77,7 @@ Example Playbook name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: delete - create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" create_rds_global_cluster_username: "{{ test_username }}" diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index c5080cb7..8033fadd 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -7,7 +7,7 @@ - name: Create rds global database amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present @@ -16,7 +16,7 @@ amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" username: "{{ create_rds_global_cluster_username }}" password: "{{ create_rds_global_cluster_password }}" @@ -28,14 +28,14 @@ db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to @@ -45,5 +45,5 @@ db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_enigne | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml index b09cae8b..d337da53 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml @@ -1,5 +1,5 @@ --- -test_enigne: aurora-mysql +test_engine: aurora-mysql test_engine_version: 5.7 test_instance_class: db.r5.large test_username: testrdsusername @@ -11,7 +11,7 @@ test_global_cluster_name: ansible-test-global-{{ tiny_prefix }} # Primary cluster parameters ================================ test_primary_cluster_name: ansible-test-primary-{{ tiny_prefix }} -test_primary_cluster_region: us-east-1 +test_primary_cluster_region: eu-central-1 test_primary_cluster_instance_name: ansible-test-instance-primary-{{ tiny_prefix }} # Replica cluster parameters ================================ diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 9f41ab88..3f71045c 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -21,7 +21,7 @@ name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: create - create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" create_rds_global_cluster_username: "{{ test_username }}" @@ -67,12 +67,12 @@ always: - - name: create global db + - name: delete global db and other role infrastructure ansible.builtin.include_role: name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: delete - create_rds_global_cluster_enigne: "{{ test_enigne }}" + create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" create_rds_global_cluster_username: "{{ test_username }}" From 64138b3ee35e2392bb6d5228caa5fa93bda84f2c Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 3 Oct 2023 11:59:26 -0700 Subject: [PATCH 19/41] make engine_version mandatory --- roles/create_rds_global_cluster/tasks/create.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 8033fadd..7fe9e048 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -8,7 +8,7 @@ amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + engine_version: "{{ create_rds_global_cluster_engine_version }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present @@ -17,7 +17,7 @@ db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + engine_version: "{{ create_rds_global_cluster_engine_version }}" username: "{{ create_rds_global_cluster_username }}" password: "{{ create_rds_global_cluster_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" @@ -36,7 +36,7 @@ db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" - engine_version: "{{ create_rds_global_cluster_engine_version | default(omit) }}" + engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to From 5819fd543b9f9f7a74ca24480a71697a51c2833c Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 3 Oct 2023 14:40:16 -0700 Subject: [PATCH 20/41] add support for db_name, enable_global_write_forwarding --- roles/create_rds_global_cluster/README.md | 2 ++ roles/create_rds_global_cluster/tasks/create.yml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index c337257c..8e7d709f 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -31,12 +31,14 @@ Role Variables - **create_rds_global_cluster_primary_cluster_name** - Name of the primary cluster. Default is $create_rds_global_cluster_global_cluster_name. - **create_rds_global_cluster_primary_cluster_region** - Region of the primary cluster. **required** - **create_rds_global_cluster_primary_cluster_instance_name** - Name of the instance in primary cluster. **required** +- **create_rds_global_cluster_primary_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. **Replica cluster variables** - **create_rds_global_cluster_replica_cluster_name** - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. - **create_rds_global_cluster_replica_cluster_region** - Region of the replica (secondary) cluster. **required** - **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** - **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Supported only while creating new cluster. Choices include 'true', 'false, 'yes', 'no'. +- **create_rds_global_cluster_replica_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. - **create_rds_global_cluster_operation** - Choices include 'create' and 'delete' to create or delete the resources. diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 7fe9e048..fc287aa5 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -22,6 +22,7 @@ password: "{{ create_rds_global_cluster_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" - name: Create an instance connected to primary cluster amazon.aws.rds_instance: @@ -39,6 +40,8 @@ engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + database_name: "{{ create_rds_global_cluster_replica_cluster_db_name | default(omit) }}" + enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(omit) }}" - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: From 5308bf808ba0d1fa1c446f6f39fd4cf2685fd950 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 3 Oct 2023 17:06:53 -0700 Subject: [PATCH 21/41] minor fixes, rename username, password to master_username, master_user_password --- roles/create_rds_global_cluster/README.md | 12 ++++++------ roles/create_rds_global_cluster/tasks/create.yml | 5 ++--- .../test_create_rds_global_cluster/tasks/main.yml | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 8e7d709f..c3507dde 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -24,8 +24,8 @@ Role Variables - **create_rds_global_cluster_engine** - Engine of the Amazon Aurora global and rds clusters. Default is aurora-postgresql. - **create_rds_global_cluster_engine_version** - Engine version of the Amazon Aurora global and rds clusters. - **create_rds_global_cluster_instance_class** - Instance class of instance in primary and replica cluster. **required** -- **create_rds_global_cluster_username** - Username of the rds clusters. **required** -- **create_rds_global_cluster_password** - Password of the rds clusters. **required** +- **create_rds_global_cluster_master_username** - Username of the rds clusters master user. **required** +- **create_rds_global_cluster_master_user_password** - Password of the rds clusters master user. **required** **Primary cluster variables** - **create_rds_global_cluster_primary_cluster_name** - Name of the primary cluster. Default is $create_rds_global_cluster_global_cluster_name. @@ -63,8 +63,8 @@ Example Playbook create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_username: "{{ test_username }}" - create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_master_username: "{{ test_username }}" + create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" @@ -82,8 +82,8 @@ Example Playbook create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_username: "{{ test_username }}" - create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_master_username: "{{ test_username }}" + create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index fc287aa5..6b55df40 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -18,8 +18,8 @@ region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" - username: "{{ create_rds_global_cluster_username }}" - password: "{{ create_rds_global_cluster_password }}" + master_username: "{{ create_rds_global_cluster_master_username }}" + master_user_password: "{{ create_rds_global_cluster_master_user_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" @@ -40,7 +40,6 @@ engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to - database_name: "{{ create_rds_global_cluster_replica_cluster_db_name | default(omit) }}" enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(omit) }}" - name: Create an instance connected to secondary cluster diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 3f71045c..157fffb2 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -24,8 +24,8 @@ create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_username: "{{ test_username }}" - create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_master_username: "{{ test_username }}" + create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" @@ -75,8 +75,8 @@ create_rds_global_cluster_engine: "{{ test_engine }}" create_rds_global_cluster_engine_version: "{{ test_engine_version }}" create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_username: "{{ test_username }}" - create_rds_global_cluster_password: "{{ test_password }}" + create_rds_global_cluster_master_username: "{{ test_username }}" + create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" From 106fcbf77ace4887c232746455e88665efe23a09 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 3 Oct 2023 23:07:12 -0700 Subject: [PATCH 22/41] add support for vpc_security_group_ids --- roles/create_rds_global_cluster/README.md | 2 ++ roles/create_rds_global_cluster/tasks/create.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index c3507dde..3dfdd69b 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -32,6 +32,7 @@ Role Variables - **create_rds_global_cluster_primary_cluster_region** - Region of the primary cluster. **required** - **create_rds_global_cluster_primary_cluster_instance_name** - Name of the instance in primary cluster. **required** - **create_rds_global_cluster_primary_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. +- **create_rds_global_cluster_primary_cluster_vpc_security_group_ids** - A list of EC2 VPC security groups to associate with the primary DB cluster. **Replica cluster variables** - **create_rds_global_cluster_replica_cluster_name** - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. @@ -39,6 +40,7 @@ Role Variables - **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** - **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Supported only while creating new cluster. Choices include 'true', 'false, 'yes', 'no'. - **create_rds_global_cluster_replica_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. +- **create_rds_global_cluster_replica_cluster_vpc_security_group_ids** - A list of EC2 VPC security groups to associate with the replica DB cluster. - **create_rds_global_cluster_operation** - Choices include 'create' and 'delete' to create or delete the resources. diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 6b55df40..03f8ad24 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -23,6 +23,7 @@ db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" + vpc_security_group_ids: "{{ create_rds_global_cluster_primary_cluster_vpc_security_group_ids| default(omit) }}" - name: Create an instance connected to primary cluster amazon.aws.rds_instance: @@ -41,6 +42,7 @@ db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(omit) }}" + vpc_security_group_ids: "{{ create_rds_global_cluster_replica_cluster_vpc_security_group_ids| default(omit) }}" - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: From 21b2a8e8188fd774240c7b503d9fb04023889e1b Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 4 Oct 2023 11:24:25 -0700 Subject: [PATCH 23/41] make linter happy --- roles/create_rds_global_cluster/tasks/create.yml | 16 ++++++++-------- roles/create_rds_global_cluster/tasks/delete.yml | 13 +++++++------ .../tasks/main.yml | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 03f8ad24..a832547f 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -7,21 +7,21 @@ - name: Create rds global database amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" # aka cluster_name region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" master_user_password: "{{ create_rds_global_cluster_master_user_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" vpc_security_group_ids: "{{ create_rds_global_cluster_primary_cluster_vpc_security_group_ids| default(omit) }}" @@ -30,14 +30,14 @@ db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" #aka cluster_name + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" # aka cluster_name region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to @@ -49,5 +49,5 @@ db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" # what cluster instance should be in db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 218532c3..74f9a9ab 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -11,6 +11,7 @@ register: _result_replica_cluster_info - name: If replica cluster exists + when: _result_replica_cluster_info.clusters | length != 0 block: - name: Delete instance attached to replica cluster if present amazon.aws.rds_instance: @@ -28,7 +29,6 @@ remove_from_global_db: true skip_final_snapshot: True state: absent - when: _result_replica_cluster_info.clusters | length != 0 - name: Get primary cluster info amazon.aws.rds_cluster_info: @@ -37,6 +37,7 @@ register: _result_primary_cluster_info - name: If primary cluster exists + when: _result_primary_cluster_info.clusters | length != 0 block: - name: Delete instance attached to primary cluster if present amazon.aws.rds_instance: @@ -53,7 +54,7 @@ global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" skip_final_snapshot: True state: absent - when: _result_primary_cluster_info.clusters | length != 0 + - name: Delete the global cluster amazon.cloud.rds_global_cluster: @@ -62,14 +63,14 @@ state: absent register: _result_global_cluster_delete - - name: Print success or failure - debug: + - name: Print success + ansible.builtin.debug: msg: - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deleted successfully' when: _result_global_cluster_delete is not failed - - name: Print success or failure - debug: + - name: Print failure + ansible.builtin.debug: msg: - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deletion failed' when: _result_global_cluster_delete is failed diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 157fffb2..465054f9 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -16,7 +16,7 @@ # and with AWS limitations we cannot create a replica cluster in same region as primary cluster i.e. us-east-1 # can be run on team account block: - - name: create global db + - name: Create global db ansible.builtin.include_role: name: cloud.aws_ops.create_rds_global_cluster vars: @@ -67,7 +67,7 @@ always: - - name: delete global db and other role infrastructure + - name: Delete global db and other role infrastructure ansible.builtin.include_role: name: cloud.aws_ops.create_rds_global_cluster vars: From 7bce7cfadf4275531ed92aeefaa3e6b83c987e2c Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 9 Oct 2023 16:53:43 -0700 Subject: [PATCH 24/41] README fixes --- roles/create_rds_global_cluster/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 3dfdd69b..10338264 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -10,7 +10,7 @@ Creates following resources 4. Replica (secondary) Cluster - Secondary cluster in specified region (create_rds_global_cluster_replica_cluster_region). 5. Replica Cluster Instance - Instance in the replica cluster. -Please refer `Role Variables` for varialbes and usage. +Please refer `Role Variables` for variables and usage. Requirements ------------ @@ -33,13 +33,13 @@ Role Variables - **create_rds_global_cluster_primary_cluster_instance_name** - Name of the instance in primary cluster. **required** - **create_rds_global_cluster_primary_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. - **create_rds_global_cluster_primary_cluster_vpc_security_group_ids** - A list of EC2 VPC security groups to associate with the primary DB cluster. +- **create_rds_global_cluster_db_subnet_group_name** - A DB subnet group to associate with this DB cluster if not using the default. **Replica cluster variables** - **create_rds_global_cluster_replica_cluster_name** - Name of the replica (secondary) cluster. Default is create_rds_global_cluster_global_cluster_name. - **create_rds_global_cluster_replica_cluster_region** - Region of the replica (secondary) cluster. **required** - **create_rds_global_cluster_replica_cluster_instance_name** - Name of the instance in secondary cluster. **required** - **create_rds_global_cluster_replica_enable_global_write_forwarding** - Whether to enable replica cluster to forward write operations to the primary cluster of an Amazon Aurora global database. Default is False. Supported only while creating new cluster. Choices include 'true', 'false, 'yes', 'no'. -- **create_rds_global_cluster_replica_cluster_db_name** - The name for your database of up to 64 alphanumeric characters. If not provided, database is not created in the cluster. - **create_rds_global_cluster_replica_cluster_vpc_security_group_ids** - A list of EC2 VPC security groups to associate with the replica DB cluster. - **create_rds_global_cluster_operation** - Choices include 'create' and 'delete' to create or delete the resources. @@ -81,11 +81,6 @@ Example Playbook name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: delete - create_rds_global_cluster_engine: "{{ test_engine }}" - create_rds_global_cluster_engine_version: "{{ test_engine_version }}" - create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_master_username: "{{ test_username }}" - create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" @@ -93,7 +88,6 @@ Example Playbook create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" - create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" ``` License From 28aa4919c66627bd4272a7c70f15d794109ec046 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 10 Oct 2023 11:05:37 -0700 Subject: [PATCH 25/41] remove extra vars in delete operation --- .../targets/test_create_rds_global_cluster/tasks/main.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index 465054f9..c6c17bb3 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -72,11 +72,6 @@ name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: delete - create_rds_global_cluster_engine: "{{ test_engine }}" - create_rds_global_cluster_engine_version: "{{ test_engine_version }}" - create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_master_username: "{{ test_username }}" - create_rds_global_cluster_master_user_password: "{{ test_password }}" create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" @@ -84,4 +79,3 @@ create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" - create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" From 102b9b8807f4fda8d67fa350ea45fd78b68d0555 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 10 Oct 2023 11:50:48 -0700 Subject: [PATCH 26/41] remove comments --- roles/create_rds_global_cluster/tasks/create.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index a832547f..ea03f5c0 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -14,20 +14,20 @@ - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" # aka cluster_name + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" master_user_password: "{{ create_rds_global_cluster_master_user_password }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" vpc_security_group_ids: "{{ create_rds_global_cluster_primary_cluster_vpc_security_group_ids| default(omit) }}" - name: Create an instance connected to primary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" # what cluster instance should be in + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" @@ -35,18 +35,18 @@ - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" # aka cluster_name + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" - global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" # what global db cluster should be associated to + global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(omit) }}" vpc_security_group_ids: "{{ create_rds_global_cluster_replica_cluster_vpc_security_group_ids| default(omit) }}" - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" # what cluster instance should be in + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" From afe1dab1941dc9b114ace94023da94077c0c8305 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 10 Oct 2023 14:07:38 -0700 Subject: [PATCH 27/41] add changelogs fragment --- changelogs/fragments/create_rds_global_cluster_role.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/create_rds_global_cluster_role.yml diff --git a/changelogs/fragments/create_rds_global_cluster_role.yml b/changelogs/fragments/create_rds_global_cluster_role.yml new file mode 100644 index 00000000..7013b9b0 --- /dev/null +++ b/changelogs/fragments/create_rds_global_cluster_role.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - create_rds_global_cluster- new role to create aurora global cluster with a primary and a replica cluster in different regions. From fcaef263e0860f7283ff90fab6856b63a21f6b2c Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 10 Oct 2023 14:15:33 -0700 Subject: [PATCH 28/41] update readme --- README.md | 1 + changelogs/fragments/create_rds_global_cluster_role.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f8b624d4..b8e69f79 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Name | Description [cloud.aws_ops.awsconfig_apigateway_with_lambda_integration](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/awsconfig_apigateway_with_lambda_integration/README.md)|A role to create/delete an API gateway with lambda function integration. [cloud.aws_ops.manage_transit_gateway](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/manage_transit_gateway/README.md)|A role to create/delete transit_gateway with vpc and vpn attachments. [cloud.aws_ops.deploy_flask_app](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/deploy_flask_app/README.md)|A role to deploy a flask web application on AWS. +[cloud.aws_ops.create_rds_global_cluster](https://github.com/ansible-collections/cloud.aws_ops/blob/main/roles/create_rds_global_cluster/README.md)|A role to create, delete aurora global cluster with a primary cluster and a replica cluster in different regions. ### Playbooks Name | Description diff --git a/changelogs/fragments/create_rds_global_cluster_role.yml b/changelogs/fragments/create_rds_global_cluster_role.yml index 7013b9b0..bb33813b 100644 --- a/changelogs/fragments/create_rds_global_cluster_role.yml +++ b/changelogs/fragments/create_rds_global_cluster_role.yml @@ -1,3 +1,3 @@ --- minor_changes: - - create_rds_global_cluster- new role to create aurora global cluster with a primary and a replica cluster in different regions. + - create_rds_global_cluster - new role to create aurora global cluster with a primary and a replica cluster in different regions. From 66bf5489e59b080b2737e3a8496ba4559816c020 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 11 Oct 2023 09:17:20 -0700 Subject: [PATCH 29/41] linter fixes --- roles/create_rds_global_cluster/tasks/create.yml | 10 +++++----- roles/create_rds_global_cluster/tasks/delete.yml | 14 +++++++------- .../targets/test_create_rds_global_cluster/aliases | 5 ++++- .../test_create_rds_global_cluster/tasks/main.yml | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index ea03f5c0..1a916325 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -7,7 +7,7 @@ - name: Create rds global database amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present @@ -16,7 +16,7 @@ amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" master_user_password: "{{ create_rds_global_cluster_master_user_password }}" @@ -30,14 +30,14 @@ db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" @@ -49,5 +49,5 @@ db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql')}}" + engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 74f9a9ab..e9e764a9 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -8,10 +8,10 @@ amazon.aws.rds_cluster_info: cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - register: _result_replica_cluster_info + register: create_rds_global_cluster_replica_cluster_info - name: If replica cluster exists - when: _result_replica_cluster_info.clusters | length != 0 + when: create_rds_global_cluster_replica_cluster_info.clusters | length != 0 block: - name: Delete instance attached to replica cluster if present amazon.aws.rds_instance: @@ -34,10 +34,10 @@ amazon.aws.rds_cluster_info: cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - register: _result_primary_cluster_info + register: create_rds_global_cluster_primary_cluster_info - name: If primary cluster exists - when: _result_primary_cluster_info.clusters | length != 0 + when: create_rds_global_cluster_primary_cluster_info.clusters | length != 0 block: - name: Delete instance attached to primary cluster if present amazon.aws.rds_instance: @@ -61,16 +61,16 @@ global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: absent - register: _result_global_cluster_delete + register: create_rds_global_cluster_global_cluster_delete - name: Print success ansible.builtin.debug: msg: - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deleted successfully' - when: _result_global_cluster_delete is not failed + when: create_rds_global_cluster_global_cluster_delete is not failed - name: Print failure ansible.builtin.debug: msg: - 'Global cluster {{ create_rds_global_cluster_global_cluster_name }} deletion failed' - when: _result_global_cluster_delete is failed + when: create_rds_global_cluster_global_cluster_delete is failed diff --git a/tests/integration/targets/test_create_rds_global_cluster/aliases b/tests/integration/targets/test_create_rds_global_cluster/aliases index 1825c036..387cc350 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/aliases +++ b/tests/integration/targets/test_create_rds_global_cluster/aliases @@ -1,3 +1,6 @@ +# reason: missing support for multi-region tests +unsupported + cloud/aws role/create_rds_global_cluster -time=3m +time=10m diff --git a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml index c6c17bb3..9a52a646 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/tasks/main.yml @@ -55,7 +55,7 @@ register: replica_cluster_info - name: Verify resources are created successfully - assert: + ansible.builtin.assert: that: - global_cluster_info.result.identifier == "{{ test_global_cluster_name }}" - global_cluster_info.result.properties.source_db_cluster_identifier == primary_cluster_info.clusters[0].db_cluster_arn From 04f5b37946840bf93a5b02e234836c4027576c59 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 11 Oct 2023 09:22:22 -0700 Subject: [PATCH 30/41] linter fixes --- roles/create_rds_global_cluster/tasks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 1a916325..5354ce69 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -42,7 +42,7 @@ db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" enable_global_write_forwarding: "{{ create_rds_global_cluster_replica_enable_global_write_forwarding | default(omit) }}" - vpc_security_group_ids: "{{ create_rds_global_cluster_replica_cluster_vpc_security_group_ids| default(omit) }}" + vpc_security_group_ids: "{{ create_rds_global_cluster_replica_cluster_vpc_security_group_ids | default(omit) }}" - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: From 46522564c2fce0a851769d3788cefb7ab4b664a5 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 11 Oct 2023 09:27:12 -0700 Subject: [PATCH 31/41] linter fixes --- roles/create_rds_global_cluster/tasks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 5354ce69..f9516df6 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -23,7 +23,7 @@ db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" database_name: "{{ create_rds_global_cluster_primary_cluster_db_name | default(omit) }}" - vpc_security_group_ids: "{{ create_rds_global_cluster_primary_cluster_vpc_security_group_ids| default(omit) }}" + vpc_security_group_ids: "{{ create_rds_global_cluster_primary_cluster_vpc_security_group_ids | default(omit) }}" - name: Create an instance connected to primary cluster amazon.aws.rds_instance: From d4d7ee78f71a13e2454497a29259bd2bcd2c80fe Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 11 Oct 2023 09:29:24 -0700 Subject: [PATCH 32/41] linter fixes --- roles/create_rds_global_cluster/tasks/create.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index f9516df6..3d9f4765 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -12,7 +12,7 @@ region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - - name: Create a primary cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_primary_cluster_region }}" + - name: Create a primary cluster for global database in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" @@ -33,7 +33,7 @@ engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - - name: Create a read replica cluster for global database "{{ create_rds_global_cluster_global_cluster_name }}" in "{{ create_rds_global_cluster_replica_cluster_region }}" + - name: Create a read replica cluster for global database in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" From 3b35b5c120f1304911dd44db3e88f36ae1ea24df Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 11 Oct 2023 12:21:01 -0700 Subject: [PATCH 33/41] update based on review feedback --- roles/create_rds_global_cluster/README.md | 66 +++++++++++-------- .../create_rds_global_cluster/tasks/main.yml | 3 - 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/roles/create_rds_global_cluster/README.md b/roles/create_rds_global_cluster/README.md index 10338264..51f8202b 100644 --- a/roles/create_rds_global_cluster/README.md +++ b/roles/create_rds_global_cluster/README.md @@ -1,21 +1,30 @@ create_rds_global_cluster ========= -A role to create Amazon Aurora global cluster with two different region rds clusters. +A role to create an Amazon Aurora global cluster with two different region rds clusters. -Creates following resources -1. Global Cluster - Amazon Aurora Postgresql or Amazon Aurora MySql cluster. If `create_rds_global_cluster_engine` not provided, Defaults to Amazon Aurora Postgresql. -2. Primary Cluster - Primary cluster in specified region (create_rds_global_cluster_primary_cluster_region). +Creates the following resources: +1. Global Cluster - Amazon Aurora Postgresql or Amazon Aurora MySql cluster. If `create_rds_global_cluster_engine` is not provided, defaults to Amazon Aurora Postgresql. +2. Primary Cluster - Primary cluster in specified region (`create_rds_global_cluster_primary_cluster_region`). 3. Primary Cluster Instance - Instance in the primary cluster. -4. Replica (secondary) Cluster - Secondary cluster in specified region (create_rds_global_cluster_replica_cluster_region). +4. Replica (secondary) Cluster - Secondary cluster in specified region (`create_rds_global_cluster_replica_cluster_region`). 5. Replica Cluster Instance - Instance in the replica cluster. -Please refer `Role Variables` for variables and usage. +Please refer to [Role Variables](#role-variables) for variables and usage. Requirements ------------ -AWS credentials with valid permission. +AWS User Account with the following permissions: + +* rds:CreateGlobalCluster +* rds:DeleteGlobalCluster +* rds:ModifyGlobalCluster +* rds:CreateDBCluster +* rds:DeleteDBCluster +* rds:ModifyDBCluster +* rds:DescribeGlobalClusters +* rds:DescribeDBClusters Role Variables -------------- @@ -62,32 +71,35 @@ Example Playbook name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: create - create_rds_global_cluster_engine: "{{ test_engine }}" - create_rds_global_cluster_engine_version: "{{ test_engine_version }}" - create_rds_global_cluster_instance_class: "{{ test_instance_class }}" - create_rds_global_cluster_master_username: "{{ test_username }}" - create_rds_global_cluster_master_user_password: "{{ test_password }}" - create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" - create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" - create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" - create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" - create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" - create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" - create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" - create_rds_global_cluster_replica_enable_global_write_forwarding: "{{ test_replica_enable_global_write_forwarding }}" + create_rds_global_cluster_engine: aurora-mysql + create_rds_global_cluster_engine_version: 5.7 + create_rds_global_cluster_instance_class: db.r5.large + create_rds_global_cluster_master_username: testusername + create_rds_global_cluster_master_user_password: test-password_rds + create_rds_global_cluster_global_cluster_name: test-cluster-global + create_rds_global_cluster_primary_cluster_name: test-cluster-primary + create_rds_global_cluster_primary_cluster_region: eu-central-1 + create_rds_global_cluster_primary_cluster_instance_name: test-instance-primary + create_rds_global_cluster_replica_cluster_name: test-cluster-replica + create_rds_global_cluster_replica_cluster_region: us-west-2 + create_rds_global_cluster_replica_enable_global_write_forwarding: true + create_rds_global_cluster_replica_cluster_instance_name: test-instance-replica + create_rds_global_cluster_primary_cluster_db_name: MyPrimaryDb + create_rds_global_cluster_primary_cluster_vpc_security_group_ids: [ "sg-03bfd123456789012", "sg-03bfd123456789034"] + create_rds_global_cluster_replica_cluster_vpc_security_group_ids: ["sg-03bfd123456789055"] - name: Delete global db, primary cluster with instance & replica cluster with instance ansible.builtin.include_role: name: cloud.aws_ops.create_rds_global_cluster vars: create_rds_global_cluster_operation: delete - create_rds_global_cluster_global_cluster_name: "{{ test_global_cluster_name }}" - create_rds_global_cluster_primary_cluster_name: "{{ test_primary_cluster_name }}" - create_rds_global_cluster_primary_cluster_region: "{{ test_primary_cluster_region }}" - create_rds_global_cluster_primary_cluster_instance_name: "{{ test_primary_cluster_instance_name }}" - create_rds_global_cluster_replica_cluster_name: "{{ test_replica_cluster_name }}" - create_rds_global_cluster_replica_cluster_region: "{{ test_replica_cluster_region }}" - create_rds_global_cluster_replica_cluster_instance_name: "{{ test_replica_cluster_instance_name }}" + create_rds_global_cluster_global_cluster_name: test-cluster-global + create_rds_global_cluster_primary_cluster_name: test-cluster-primary + create_rds_global_cluster_primary_cluster_region: eu-central-1 + create_rds_global_cluster_primary_cluster_instance_name: test-instance-primary + create_rds_global_cluster_replica_cluster_name: test-cluster-replica + create_rds_global_cluster_replica_cluster_region: us-west-2 + create_rds_global_cluster_replica_cluster_instance_name: test-instance-replica ``` License diff --git a/roles/create_rds_global_cluster/tasks/main.yml b/roles/create_rds_global_cluster/tasks/main.yml index a099ba7a..32970f27 100644 --- a/roles/create_rds_global_cluster/tasks/main.yml +++ b/roles/create_rds_global_cluster/tasks/main.yml @@ -1,8 +1,5 @@ --- - name: Run 'create_rds_global_cluster' role - module_defaults: - group/aws: "{{ aws_setup_credentials__output }}" - block: - name: Include file ansible.builtin.include_tasks: "{{ create_rds_global_cluster_operation }}.yml" From c4dc368145c638df532a08cb5669a5eaf4633c02 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 12 Oct 2023 11:22:42 -0700 Subject: [PATCH 34/41] add module defaults for amazon.cloud --- roles/create_rds_global_cluster/tasks/create.yml | 1 + roles/create_rds_global_cluster/tasks/delete.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 3d9f4765..26f3f7ce 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -2,6 +2,7 @@ - name: Run 'create_rds_global_cluster' role create operations module_defaults: group/aws: "{{ aws_setup_credentials__output }}" + group/amazon.cloud.aws: "{{ aws_setup_credentials__output }}" block: - name: Create rds global database diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index e9e764a9..6316073a 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -2,6 +2,7 @@ - name: Run 'create_rds_global_cluster' role delete operations module_defaults: group/aws: "{{ aws_setup_credentials__output }}" + group/amazon.cloud.aws: "{{ aws_setup_credentials__output }}" block: - name: Get replica cluster info From 791a13835d361b322258f4b9acac2fc410c9ff17 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 16 Oct 2023 14:02:24 -0700 Subject: [PATCH 35/41] add default values --- .../defaults/main.yml | 5 +++++ .../tasks/create.yml | 22 +++++++++---------- .../tasks/delete.yml | 16 +++++++------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/roles/create_rds_global_cluster/defaults/main.yml b/roles/create_rds_global_cluster/defaults/main.yml index 87e5916b..cbf65cf7 100644 --- a/roles/create_rds_global_cluster/defaults/main.yml +++ b/roles/create_rds_global_cluster/defaults/main.yml @@ -1,2 +1,7 @@ --- # defaults file for roles/create_rds_global_cluster +default_engine_version: "aurora-postgresql" +default_primary_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary" +default_replica_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica" +default_primary_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary-instance" +default_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" \ No newline at end of file diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 26f3f7ce..9cb6699b 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -8,16 +8,16 @@ - name: Create rds global database amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" + engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - name: Create a primary cluster for global database in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" + engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" master_user_password: "{{ create_rds_global_cluster_master_user_password }}" @@ -28,17 +28,17 @@ - name: Create an instance connected to primary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" - db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" + engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default('{{ create_rds_global_cluster_global_cluster_name }}') }}" + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" + engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" @@ -47,8 +47,8 @@ - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" - db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default('aurora-postgresql') }}" + engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 6316073a..27299f7f 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -7,7 +7,7 @@ block: - name: Get replica cluster info amazon.aws.rds_cluster_info: - cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" register: create_rds_global_cluster_replica_cluster_info @@ -16,7 +16,7 @@ block: - name: Delete instance attached to replica cluster if present amazon.aws.rds_instance: - db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" skip_final_snapshot: true wait: false @@ -24,16 +24,16 @@ - name: Delete replica cluster without creating a final snapshot amazon.aws.rds_cluster: - cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" region: "{{ create_rds_global_cluster_replica_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" remove_from_global_db: true - skip_final_snapshot: True + skip_final_snapshot: true state: absent - name: Get primary cluster info amazon.aws.rds_cluster_info: - cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" register: create_rds_global_cluster_primary_cluster_info @@ -42,7 +42,7 @@ block: - name: Delete instance attached to primary cluster if present amazon.aws.rds_instance: - db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" skip_final_snapshot: true wait: false @@ -50,10 +50,10 @@ - name: Delete primary cluster without creating a final snapshot amazon.aws.rds_cluster: - cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name)}}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - skip_final_snapshot: True + skip_final_snapshot: true state: absent From d4c3eccabcbeb96431491930929826a7399ad068 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 16 Oct 2023 14:06:06 -0700 Subject: [PATCH 36/41] add default values --- roles/create_rds_global_cluster/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/defaults/main.yml b/roles/create_rds_global_cluster/defaults/main.yml index cbf65cf7..cb9f590f 100644 --- a/roles/create_rds_global_cluster/defaults/main.yml +++ b/roles/create_rds_global_cluster/defaults/main.yml @@ -4,4 +4,4 @@ default_engine_version: "aurora-postgresql" default_primary_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary" default_replica_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica" default_primary_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary-instance" -default_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" \ No newline at end of file +default_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" From 6af9d3c6f322647b7c7743172b0d632de0f7edd9 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 16 Oct 2023 14:09:10 -0700 Subject: [PATCH 37/41] sanity fix --- roles/create_rds_global_cluster/tasks/delete.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 27299f7f..d9f3433b 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -50,7 +50,7 @@ - name: Delete primary cluster without creating a final snapshot amazon.aws.rds_cluster: - cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name)}}" + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" region: "{{ create_rds_global_cluster_primary_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" skip_final_snapshot: true From 91c650565ee3f3005787c49ffb68bfc25e75d34d Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 17 Oct 2023 13:36:24 -0700 Subject: [PATCH 38/41] update role to use `aws_region` instead of `region` --- roles/create_rds_global_cluster/tasks/create.yml | 10 +++++----- roles/create_rds_global_cluster/tasks/delete.yml | 14 +++++++------- .../defaults/main.yml | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 9cb6699b..0cf1260f 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -10,13 +10,13 @@ global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - name: Create a primary cluster for global database in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" @@ -30,14 +30,14 @@ amazon.aws.rds_instance: db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" @@ -49,6 +49,6 @@ amazon.aws.rds_instance: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index d9f3433b..0fb9870a 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -8,7 +8,7 @@ - name: Get replica cluster info amazon.aws.rds_cluster_info: cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" register: create_rds_global_cluster_replica_cluster_info - name: If replica cluster exists @@ -17,7 +17,7 @@ - name: Delete instance attached to replica cluster if present amazon.aws.rds_instance: db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" skip_final_snapshot: true wait: false state: absent @@ -25,7 +25,7 @@ - name: Delete replica cluster without creating a final snapshot amazon.aws.rds_cluster: cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" - region: "{{ create_rds_global_cluster_replica_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" remove_from_global_db: true skip_final_snapshot: true @@ -34,7 +34,7 @@ - name: Get primary cluster info amazon.aws.rds_cluster_info: cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" register: create_rds_global_cluster_primary_cluster_info - name: If primary cluster exists @@ -43,7 +43,7 @@ - name: Delete instance attached to primary cluster if present amazon.aws.rds_instance: db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" skip_final_snapshot: true wait: false state: absent @@ -51,7 +51,7 @@ - name: Delete primary cluster without creating a final snapshot amazon.aws.rds_cluster: cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" skip_final_snapshot: true state: absent @@ -60,7 +60,7 @@ - name: Delete the global cluster amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - region: "{{ create_rds_global_cluster_primary_cluster_region }}" + aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: absent register: create_rds_global_cluster_global_cluster_delete diff --git a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml index d337da53..c09a2482 100644 --- a/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml +++ b/tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml @@ -17,7 +17,7 @@ test_primary_cluster_instance_name: ansible-test-instance-primary-{{ tiny_prefix # Replica cluster parameters ================================ test_replica_cluster_name: ansible-test-replica-{{ tiny_prefix }} test_replica_cluster_region: us-west-2 -test_replica_enable_global_write_forwarding: 'true' +test_replica_enable_global_write_forwarding: true test_replica_cluster_instance_name: ansible-test-instance-replica-{{ tiny_prefix }} aws_security_token: '{{ security_token | default(omit) }}' From 4ce30c816aa3ed464945a653f70dce47a0b45f5f Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 17 Oct 2023 14:05:31 -0700 Subject: [PATCH 39/41] rename default vars to remove default filter use --- .../defaults/main.yml | 10 +++++----- .../tasks/create.yml | 20 +++++++++---------- .../tasks/delete.yml | 12 +++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/roles/create_rds_global_cluster/defaults/main.yml b/roles/create_rds_global_cluster/defaults/main.yml index cb9f590f..51c2e241 100644 --- a/roles/create_rds_global_cluster/defaults/main.yml +++ b/roles/create_rds_global_cluster/defaults/main.yml @@ -1,7 +1,7 @@ --- # defaults file for roles/create_rds_global_cluster -default_engine_version: "aurora-postgresql" -default_primary_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary" -default_replica_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica" -default_primary_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary-instance" -default_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" +create_rds_global_cluster_engine: "aurora-postgresql" +create_rds_global_cluster_primary_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary" +create_rds_global_cluster_replica_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica" +create_rds_global_cluster_primary_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary-instance" +create_rds_global_cluster_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index 0cf1260f..c946ef8b 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -8,16 +8,16 @@ - name: Create rds global database amazon.cloud.rds_global_cluster: global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" - engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" + engine: "{{ create_rds_global_cluster_engine }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" state: present - name: Create a primary cluster for global database in "{{ create_rds_global_cluster_primary_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" + engine: "{{ create_rds_global_cluster_engine }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" master_username: "{{ create_rds_global_cluster_master_username }}" master_user_password: "{{ create_rds_global_cluster_master_user_password }}" @@ -28,17 +28,17 @@ - name: Create an instance connected to primary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" - db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" + db_cluster_identifier: "{{ create_rds_global_cluster_primary_cluster_name }}" + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" + engine: "{{ create_rds_global_cluster_engine }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" - name: Create a read replica cluster for global database in "{{ create_rds_global_cluster_replica_cluster_region }}" amazon.aws.rds_cluster: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" + engine: "{{ create_rds_global_cluster_engine }}" engine_version: "{{ create_rds_global_cluster_engine_version }}" db_subnet_group_name: "{{ create_rds_global_cluster_db_subnet_group_name | default(omit) }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" @@ -47,8 +47,8 @@ - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: - db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" + db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" - engine: "{{ create_rds_global_cluster_engine | default(default_engine_version) }}" + engine: "{{ create_rds_global_cluster_engine }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" diff --git a/roles/create_rds_global_cluster/tasks/delete.yml b/roles/create_rds_global_cluster/tasks/delete.yml index 0fb9870a..fd7e366f 100644 --- a/roles/create_rds_global_cluster/tasks/delete.yml +++ b/roles/create_rds_global_cluster/tasks/delete.yml @@ -7,7 +7,7 @@ block: - name: Get replica cluster info amazon.aws.rds_cluster_info: - cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" register: create_rds_global_cluster_replica_cluster_info @@ -16,7 +16,7 @@ block: - name: Delete instance attached to replica cluster if present amazon.aws.rds_instance: - db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" skip_final_snapshot: true wait: false @@ -24,7 +24,7 @@ - name: Delete replica cluster without creating a final snapshot amazon.aws.rds_cluster: - cluster_id: "{{ create_rds_global_cluster_replica_cluster_name | default(default_replica_cluster_name) }}" + cluster_id: "{{ create_rds_global_cluster_replica_cluster_name }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" remove_from_global_db: true @@ -33,7 +33,7 @@ - name: Get primary cluster info amazon.aws.rds_cluster_info: - cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" register: create_rds_global_cluster_primary_cluster_info @@ -42,7 +42,7 @@ block: - name: Delete instance attached to primary cluster if present amazon.aws.rds_instance: - db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name | default(default_primary_cluster_instance_name) }}" + db_instance_identifier: "{{ create_rds_global_cluster_primary_cluster_instance_name }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" skip_final_snapshot: true wait: false @@ -50,7 +50,7 @@ - name: Delete primary cluster without creating a final snapshot amazon.aws.rds_cluster: - cluster_id: "{{ create_rds_global_cluster_primary_cluster_name | default(default_primary_cluster_name) }}" + cluster_id: "{{ create_rds_global_cluster_primary_cluster_name }}" aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" skip_final_snapshot: true From da8773f891e842bbc76562248f30ce382c4333a5 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 17 Oct 2023 14:06:57 -0700 Subject: [PATCH 40/41] rename default vars to remove default filter use --- roles/create_rds_global_cluster/tasks/create.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/create_rds_global_cluster/tasks/create.yml b/roles/create_rds_global_cluster/tasks/create.yml index c946ef8b..d7f4a171 100644 --- a/roles/create_rds_global_cluster/tasks/create.yml +++ b/roles/create_rds_global_cluster/tasks/create.yml @@ -48,7 +48,7 @@ - name: Create an instance connected to secondary cluster amazon.aws.rds_instance: db_cluster_identifier: "{{ create_rds_global_cluster_replica_cluster_name }}" - db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name | default(default_replica_cluster_instance_name) }}" + db_instance_identifier: "{{ create_rds_global_cluster_replica_cluster_instance_name }}" aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" engine: "{{ create_rds_global_cluster_engine }}" db_instance_class: "{{ create_rds_global_cluster_instance_class }}" From b718282ce042aa87932e113f46315a68366aa044 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 18 Oct 2023 08:08:23 -0700 Subject: [PATCH 41/41] add default value for engine version --- roles/create_rds_global_cluster/defaults/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/create_rds_global_cluster/defaults/main.yml b/roles/create_rds_global_cluster/defaults/main.yml index 51c2e241..d4f18f2c 100644 --- a/roles/create_rds_global_cluster/defaults/main.yml +++ b/roles/create_rds_global_cluster/defaults/main.yml @@ -1,6 +1,7 @@ --- # defaults file for roles/create_rds_global_cluster create_rds_global_cluster_engine: "aurora-postgresql" +create_rds_global_cluster_engine_version: 5.7 create_rds_global_cluster_primary_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary" create_rds_global_cluster_replica_cluster_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica" create_rds_global_cluster_primary_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-primary-instance"