generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from mandar242/global_cluster
Add create global cluster with rds cluster role
- Loading branch information
Showing
12 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
create_rds_global_cluster | ||
========= | ||
|
||
A role to create an Amazon Aurora global cluster with two different region rds clusters. | ||
|
||
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`). | ||
5. Replica Cluster Instance - Instance in the replica cluster. | ||
|
||
Please refer to [Role Variables](#role-variables) for variables and usage. | ||
|
||
Requirements | ||
------------ | ||
|
||
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 | ||
-------------- | ||
**Global cluster variables** | ||
- **create_rds_global_cluster_global_cluster_name** - Name of the Amazon Aurora global cluster. **required** | ||
- **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_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. | ||
- **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. | ||
- **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_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. | ||
|
||
Dependencies | ||
------------ | ||
|
||
- role: [aws_setup_credentials](../aws_setup_credentials/README.md) | ||
|
||
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_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-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 | ||
------- | ||
GNU General Public License v3.0 or later |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# 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" | ||
create_rds_global_cluster_replica_cluster_instance_name: "{{ create_rds_global_cluster_global_cluster_name }}-replica-instance" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- role: cloud.aws_ops.aws_setup_credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
- 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 | ||
amazon.cloud.rds_global_cluster: | ||
global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" | ||
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 }}" | ||
aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" | ||
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 }}" | ||
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) }}" | ||
|
||
- 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 }}" | ||
aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" | ||
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 }}" | ||
aws_region: "{{ create_rds_global_cluster_replica_cluster_region }}" | ||
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 }}" | ||
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 }}" | ||
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 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
- 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 | ||
amazon.aws.rds_cluster_info: | ||
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 | ||
|
||
- name: If replica cluster exists | ||
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: | ||
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 | ||
state: absent | ||
|
||
- name: Delete replica cluster without creating a final snapshot | ||
amazon.aws.rds_cluster: | ||
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 | ||
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 }}" | ||
aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" | ||
register: create_rds_global_cluster_primary_cluster_info | ||
|
||
- name: If primary cluster exists | ||
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: | ||
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 | ||
state: absent | ||
|
||
- name: Delete primary cluster without creating a final snapshot | ||
amazon.aws.rds_cluster: | ||
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 | ||
state: absent | ||
|
||
|
||
- name: Delete the global cluster | ||
amazon.cloud.rds_global_cluster: | ||
global_cluster_identifier: "{{ create_rds_global_cluster_global_cluster_name }}" | ||
aws_region: "{{ create_rds_global_cluster_primary_cluster_region }}" | ||
state: absent | ||
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: 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: create_rds_global_cluster_global_cluster_delete is failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Run 'create_rds_global_cluster' role | ||
block: | ||
- name: Include file | ||
ansible.builtin.include_tasks: "{{ create_rds_global_cluster_operation }}.yml" |
6 changes: 6 additions & 0 deletions
6
tests/integration/targets/test_create_rds_global_cluster/aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# reason: missing support for multi-region tests | ||
unsupported | ||
|
||
cloud/aws | ||
role/create_rds_global_cluster | ||
time=10m |
23 changes: 23 additions & 0 deletions
23
tests/integration/targets/test_create_rds_global_cluster/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
test_engine: aurora-mysql | ||
test_engine_version: 5.7 | ||
test_instance_class: db.r5.large | ||
test_username: testrdsusername | ||
test_password: test-rds_password | ||
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: eu-central-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) }}' |
Oops, something went wrong.