
    Vh                     T   d Z dZdZ	 ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ  ej*                  d      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&e'd"k(  r e&        yy# e$ r Y w xY w)#a[K  
---
module: rds_cluster
version_added: 5.0.0
short_description: rds_cluster module
description:
  - Create, modify, and delete RDS clusters.
  - This module was originally added to C(community.aws) in release 3.2.0.
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.tags
  - amazon.aws.boto3
author:
  - Sloane Hertel (@s-hertel)
  - Alina Buzachis (@alinabuzachis)
options:
  # General module options
    state:
        description:
          - Whether the snapshot should exist or not.
          - V(started) and V(stopped) can only be used with aurora clusters.
          - Support for V(started) and V(stopped) was added in release 6.3.0.
        choices: ['present', 'absent', 'started', 'stopped']
        default: 'present'
        type: str
    creation_source:
        description: Which source to use if creating from a template (an existing cluster, S3 bucket, or snapshot).
        choices: ['snapshot', 's3', 'cluster']
        type: str
    force_update_password:
        description:
          - Set to V(true) to update your cluster password with O(master_user_password).
          - Since comparing passwords to determine if it needs to be updated is not possible this is set to V(false) by default to allow idempotence.
        type: bool
        default: false
    promote:
        description: Set to V(true) to promote a read replica cluster.
        type: bool
        default: false
    purge_cloudwatch_logs_exports:
        description:
          - Whether or not to disable Cloudwatch logs enabled for the DB cluster that are not provided in O(enable_cloudwatch_logs_exports).
            Set O(enable_cloudwatch_logs_exports) to an empty list to disable all.
        type: bool
        default: true
    purge_security_groups:
        description:
          - Set to V(false) to retain any enabled security groups that aren't specified in the task and are associated with the cluster.
          - Can be applied to O(vpc_security_group_ids)
        type: bool
        default: true
    wait:
        description: Whether to wait for the cluster to be available or deleted.
        type: bool
        default: true
    # Options that have a corresponding boto3 parameter
    apply_immediately:
        description:
          - A value that specifies whether modifying a cluster with O(new_db_cluster_identifier) and O(master_user_password)
            should be applied as soon as possible, regardless of the O(preferred_maintenance_window) setting. If V(false), changes
            are applied during the next maintenance window.
        type: bool
        default: false
    availability_zones:
        description:
          - A list of EC2 Availability Zones that instances in the DB cluster can be created in.
            May be used when creating a cluster or when restoring from S3 or a snapshot.
        aliases:
          - zones
          - az
        type: list
        elements: str
    backtrack_to:
        description:
          - The timestamp of the time to backtrack the DB cluster to in ISO 8601 format, such as "2017-07-08T18:00Z".
        type: str
    backtrack_window:
        description:
          - The target backtrack window, in seconds. To disable backtracking, set this value to V(0).
          - If specified, this value must be set to a number from V(0) to V(259,200) (72 hours).
        type: int
    backup_retention_period:
        description:
          - The number of days for which automated backups are retained (must be within V(1) to V(35)).
            May be used when creating a new cluster, when restoring from S3, or when modifying a cluster.
        type: int
        default: 1
    character_set_name:
        description:
          - The character set to associate with the DB cluster.
        type: str
    database_name:
        description:
          - The name for your database. If a name is not provided Amazon RDS will not create a database.
        aliases:
          - db_name
        type: str
    db_cluster_identifier:
        description:
          - The DB cluster (lowercase) identifier. The identifier must contain from 1 to 63 letters, numbers, or
            hyphens and the first character must be a letter and may not end in a hyphen or contain consecutive hyphens.
        aliases:
          - cluster_id
          - id
          - cluster_name
        type: str
        required: true
    db_cluster_parameter_group_name:
        description:
          - The name of the DB cluster parameter group to associate with this DB cluster.
            If this argument is omitted when creating a cluster, the default DB cluster parameter group for the specified DB engine and version is used.
        type: str
    db_subnet_group_name:
        description:
          - A DB subnet group to associate with this DB cluster if not using the default.
        type: str
    enable_cloudwatch_logs_exports:
        description:
          - A list of log types that need to be enabled for exporting to CloudWatch Logs.
          - Engine aurora-mysql supports V(audit), V(error), V(general) and V(slowquery).
          - Engine aurora-postgresql supports V(postgresql).
        type: list
        elements: str
    deletion_protection:
        description:
          -  A value that indicates whether the DB cluster has deletion protection enabled.
             The database can't be deleted when deletion protection is enabled.
             By default, deletion protection is disabled.
        type: bool
    global_cluster_identifier:
        description:
          -  The global cluster ID of an Aurora cluster that becomes the primary cluster in the new global database cluster.
        type: str
    enable_http_endpoint:
        description:
          -  A value that indicates whether to enable the HTTP endpoint for an Aurora Serverless DB cluster.
             By default, the HTTP endpoint is disabled.
        type: bool
    copy_tags_to_snapshot:
        description:
          - Indicates whether to copy all tags from the DB cluster to snapshots of the DB cluster.
            The default is not to copy them.
        type: bool
    domain:
        description:
          - The Active Directory directory ID to create the DB cluster in.
        type: str
    domain_iam_role_name:
        description:
          - Specify the name of the IAM role to be used when making API calls to the Directory Service.
        type: str
    enable_global_write_forwarding:
        description:
          - A value that indicates whether to enable this DB cluster to forward write operations to the primary cluster of an Aurora global database.
            By default, write operations are not allowed on Aurora DB clusters that are secondary clusters in an Aurora global database.
          - This value can be only set on Aurora DB clusters that are members of an Aurora global database.
        type: bool
    db_cluster_instance_class:
        description:
          - The compute and memory capacity of each DB instance in the Multi-AZ DB cluster, for example V(db.m6gd.xlarge).
          - Not all DB instance classes are available in all Amazon Web Services Regions, or for all database engines.
          - For the full list of DB instance classes and availability for your engine visit
            U(https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html).
          - This setting is required to create a Multi-AZ DB cluster.
        type: str
        version_added: 5.5.0
    enable_iam_database_authentication:
        description:
          - Enable mapping of AWS Identity and Access Management (IAM) accounts to database accounts.
            If this option is omitted when creating the cluster, Amazon RDS sets this to C(false).
        type: bool
    allocated_storage:
        description:
          - The amount of storage in gibibytes (GiB) to allocate to each DB instance in the Multi-AZ DB cluster.
          - This setting is required to create a Multi-AZ DB cluster.
        type: int
        version_added: 5.5.0
    storage_type:
        description:
          - Specifies the storage type to be associated with the DB cluster.
          - This setting is required to create a Multi-AZ DB cluster.
          - For multi-AZ DB clusters, O(storage_type) defaults to V(io1) and a value for the O(iops) parameter is required.
          - For Aurora DB clusters, O(storage_type) defaults to V(aurora) standard.
          - For mysql and postgres DB clusters, O(storage_type) defaults to V(io1).
          - Support for V(aurora) and V(aurora-iopt1) was added in release 8.2.0.
        type: str
        choices:
          - io1
          - aurora
          - aurora-iopt1
        version_added: 5.5.0
    iops:
        description:
          - The amount of Provisioned IOPS (input/output operations per second) to be initially allocated for each DB instance in the Multi-AZ DB cluster.
          - This setting is required to create a Multi-AZ DB cluster
          - Must be a multiple between .5 and 50 of the storage amount for the DB cluster.
        type: int
        version_added: 5.5.0
    engine:
        description:
          - The name of the database engine to be used for this DB cluster. This is required to create a cluster.
          - The combinaison of I(engine) and I(engine_mode) may not be supported.
          - "See AWS documentation for details:
            L(Amazon RDS Documentation,https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html)."
          - When O(engine=mysql), O(allocated_storage), O(iops) and O(db_cluster_instance_class) must also be specified.
          - When I(engine=postgres), O(allocated_storage), O(iops) and O(db_cluster_instance_class) must also be specified.
          - Support for V(postgres) and V(mysql) was added in amazon.aws 5.5.0.
        choices:
          - aurora
          - aurora-mysql
          - aurora-postgresql
          - mysql
          - postgres
        type: str
    engine_mode:
        description:
          - The DB engine mode of the DB cluster. The combination of O(engine) and O(engine_mode) may not be supported.
          - "See AWS documentation for details:
            L(Amazon RDS Documentation,https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html)."
        choices:
          - provisioned
          - serverless
          - parallelquery
          - global
          - multimaster
        type: str
        version_added: 5.5.0
    engine_version:
        description:
          - The version number of the database engine to use.
          - For Aurora MySQL that could be V(5.6.10a), V(5.7.12).
          - Aurora PostgreSQL example, V(9.6.3).
        type: str
    final_snapshot_identifier:
        description:
          - The DB cluster snapshot identifier of the new DB cluster snapshot created when O(skip_final_snapshot=false).
        type: str
    force_backtrack:
        description:
          - A boolean to indicate if the DB cluster should be forced to backtrack when binary logging is enabled.
            Otherwise, an error occurs when binary logging is enabled.
        type: bool
    kms_key_id:
        description:
          - The AWS KMS key identifier (the ARN, unless you are creating a cluster in the same account that owns the
            KMS key, in which case the KMS key alias may be used).
          - If O(replication_source_identifier) specifies an encrypted source Amazon RDS will use the key used toe encrypt the source.
          - If O(storage_encrypted=true) and and O(replication_source_identifier) is not provided, the default encryption key is used.
        type: str
    master_user_password:
        description:
          - An 8-41 character password for the master database user.
          - The password can contain any printable ASCII character except V(/), V("), or V(@).
          - To modify the password use O(force_update_password). Use O(apply_immediately) to change
            the password immediately, otherwise it is updated during the next maintenance window.
        aliases:
          - password
        type: str
    master_username:
        description:
          - The name of the master user for the DB cluster. Must be 1-16 letters or numbers and begin with a letter.
        aliases:
          - username
        type: str
    new_db_cluster_identifier:
        description:
          - The new DB cluster (lowercase) identifier for the DB cluster when renaming a DB cluster.
          - The identifier must contain from 1 to 63 letters, numbers, or hyphens and the first character must be a
            letter and may not end in a hyphen or contain consecutive hyphens.
          - Use O(apply_immediately) to rename immediately, otherwise it is updated during the next maintenance window.
        aliases:
          - new_cluster_id
          - new_id
          - new_cluster_name
        type: str
    option_group_name:
        description:
          - The option group to associate with the DB cluster.
        type: str
    port:
        description:
          - The port number on which the instances in the DB cluster accept connections. If not specified, Amazon RDS
            defaults this to V(3306) if the O(engine) is V(aurora) and V(5432) if the O(engine) is V(aurora-postgresql).
        type: int
    preferred_backup_window:
        description:
          - The daily time range (in UTC) of at least 30 minutes, during which automated backups are created if automated backups are
            enabled using O(backup_retention_period). The option must be in the format of "hh24:mi-hh24:mi" and not conflict with
            O(preferred_maintenance_window).
        aliases:
          - backup_window
        type: str
    preferred_maintenance_window:
        description:
          - The weekly time range (in UTC) of at least 30 minutes, during which system maintenance can occur. The option must
            be in the format "ddd:hh24:mi-ddd:hh24:mi" where ddd is one of Mon, Tue, Wed, Thu, Fri, Sat, Sun.
        aliases:
          - maintenance_window
        type: str
    remove_from_global_db:
        description:
          - If set to V(true), the cluster will be removed from global DB.
          - Parameters O(global_cluster_identifier), O(db_cluster_identifier) must be specified when O(remove_from_global_db=true).
        type: bool
        required: false
        version_added: 6.5.0
    replication_source_identifier:
        description:
          - The Amazon Resource Name (ARN) of the source DB instance or DB cluster if this DB cluster is created as a Read Replica.
        aliases:
          - replication_src_id
        type: str
    restore_to_time:
        description:
          - The UTC date and time to restore the DB cluster to. Must be in the format "2015-03-07T23:45:00Z".
          - If this is not provided while restoring a cluster, O(use_latest_restorable_time) must be.
            May not be specified if O(restore_type) is copy-on-write.
        type: str
    restore_type:
        description:
          - The type of restore to be performed. If not provided, Amazon RDS uses full-copy.
        choices:
          - full-copy
          - copy-on-write
        type: str
    role_arn:
        description:
          - The Amazon Resource Name (ARN) of the IAM role to associate with the Aurora DB cluster, for example
            "arn:aws:iam::123456789012:role/AuroraAccessRole"
        type: str
    s3_bucket_name:
        description:
          - The name of the Amazon S3 bucket that contains the data used to create the Amazon Aurora DB cluster.
        type: str
    s3_ingestion_role_arn:
        description:
          - The Amazon Resource Name (ARN) of the AWS Identity and Access Management (IAM) role that authorizes Amazon RDS to access
            the Amazon S3 bucket on your behalf.
        type: str
    s3_prefix:
        description:
          - The prefix for all of the file names that contain the data used to create the Amazon Aurora DB cluster.
          - If you do not specify a SourceS3Prefix value, then the Amazon Aurora DB cluster is created by using all of the files in the Amazon S3 bucket.
        type: str
    serverless_v2_scaling_configuration:
        description:
          - Contains the scaling configuration of an Aurora Serverless v2 DB cluster.
        type: dict
        suboptions:
          min_capacity:
            description:
              - The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster.
              - ACU values can be specified in in half-step increments, such as V(8), V(8.5), V(9), and so on.
              - The smallest possible value is V(0.5).
            type: float
          max_capacity:
            description:
              - The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster.
              - ACU values can be specified in in half-step increments, such as V(40), V(40.5), V(41), and so on.
              - The largest possible value is V(128).
            type: float
        version_added: 7.3.0
    skip_final_snapshot:
        description:
          - Whether a final DB cluster snapshot is created before the DB cluster is deleted.
          - If this is V(false), O(final_snapshot_identifier) must be provided.
        type: bool
        default: false
    snapshot_identifier:
        description:
          - The identifier for the DB snapshot or DB cluster snapshot to restore from.
          - You can use either the name or the ARN to specify a DB cluster snapshot. However, you can use only the ARN to specify a DB snapshot.
        type: str
    source_db_cluster_identifier:
        description:
          - The identifier of the source DB cluster from which to restore.
        type: str
    source_engine:
        description:
          - The identifier for the database engine that was backed up to create the files stored in the Amazon S3 bucket.
        choices:
          - mysql
        type: str
    source_engine_version:
        description:
          - The version of the database that the backup files were created from.
        type: str
    source_region:
        description:
          - The ID of the region that contains the source for the DB cluster.
        type: str
    storage_encrypted:
        description:
          - Whether the DB cluster is encrypted.
        type: bool
    use_earliest_time_on_point_in_time_unavailable:
        description:
          - If O(backtrack_to) is set to a timestamp earlier than the earliest backtrack time, this value backtracks the DB cluster to
            the earliest possible backtrack time. Otherwise, an error occurs.
        type: bool
    use_latest_restorable_time:
        description:
          - Whether to restore the DB cluster to the latest restorable backup time. Only one of O(use_latest_restorable_time)
            and O(restore_to_time) may be provided.
        type: bool
    vpc_security_group_ids:
        description:
          - A list of EC2 VPC security groups to associate with the DB cluster.
        type: list
        elements: str
a8  
# Note: These examples do not set authentication details, see the AWS Guide for details.
- name: Create minimal Aurora cluster in default VPC and default subnet group
  amazon.aws.rds_cluster:
    cluster_id: "{{ cluster_id }}"
    engine: "aurora"
    password: "{{ password }}"
    username: "{{ username }}"

- name: Add a new security group without purge
  amazon.aws.rds_cluster:
    id: "{{ cluster_id }}"
    state: present
    vpc_security_group_ids:
      - sg-0be17ba10c9286b0b
    purge_security_groups: false

- name: Modify password
  amazon.aws.rds_cluster:
    id: "{{ cluster_id }}"
    state: present
    password: "{{ new_password }}"
    force_update_password: true
    apply_immediately: true

- name: Rename the cluster
  amazon.aws.rds_cluster:
    engine: aurora
    password: "{{ password }}"
    username: "{{ username }}"
    cluster_id: "cluster-{{ resource_prefix }}"
    new_cluster_id: "cluster-{{ resource_prefix }}-renamed"
    apply_immediately: true

- name: Delete Aurora cluster without creating a final snapshot
  amazon.aws.rds_cluster:
    engine: aurora
    password: "{{ password }}"
    username: "{{ username }}"
    cluster_id: "{{ cluster_id }}"
    skip_final_snapshot: true
    tags:
      Name: "cluster-{{ resource_prefix }}"
      Created_By: "Ansible_rds_cluster_integration_test"
    state: absent

- name: Restore cluster from source snapshot
  amazon.aws.rds_cluster:
    engine: aurora
    password: "{{ password }}"
    username: "{{ username }}"
    cluster_id: "cluster-{{ resource_prefix }}-restored"
    snapshot_identifier: "cluster-{{ resource_prefix }}-snapshot"

- name: Create an Aurora PostgreSQL cluster and attach an intance
  amazon.aws.rds_cluster:
    state: present
    engine: aurora-postgresql
    engine_mode: provisioned
    cluster_id: '{{ cluster_id }}'
    username: '{{ username }}'
    password: '{{ password }}'

- name: Attach a new instance to the cluster
  amazon.aws.rds_instance:
    id: '{{ instance_id }}'
    cluster_id: '{{ cluster_id }}'
    engine: aurora-postgresql
    state: present
    db_instance_class: 'db.t3.medium'

- name: Remove a cluster from global DB (do not delete)
  amazon.aws.rds_cluster:
    db_cluster_identifier: '{{ cluster_id }}'
    global_cluster_identifier: '{{ global_cluster_id }}'
    remove_from_global_db: true

- name: Remove a cluster from global DB and Delete without creating a final snapshot
  amazon.aws.rds_cluster:
    engine: aurora
    password: "{{ password }}"
    username: "{{ username }}"
    cluster_id: "{{ cluster_id }}"
    skip_final_snapshot: true
    remove_from_global_db: true
    wait: true
    state: absent

- name: Update cluster port and WAIT for remove secondary DB cluster from global DB to complete
  amazon.aws.rds_cluster:
    db_cluster_identifier: "{{ secondary_cluster_name }}"
    global_cluster_identifier: "{{ global_cluster_name }}"
    remove_from_global_db: true
    state: present
    port: 3389
    region: "{{ secondary_cluster_region }}"

- name: Update cluster port and DO NOT WAIT for remove secondary DB cluster from global DB to complete
  amazon.aws.rds_cluster:
    db_cluster_identifier: "{{ secondary_cluster_name }}"
    global_cluster_identifier: "{{ global_cluster_name }}"
    remove_from_global_db: true
    state: present
    port: 3389
    region: "{{ secondary_cluster_region }}"
    wait: false
a  
activity_stream_status:
  description: The status of the database activity stream.
  returned: always
  type: str
  sample: "stopped"
allocated_storage:
  description:
    - The allocated storage size in gigabytes. Since aurora storage size is not fixed this is
      always 1 for aurora database engines.
  returned: always
  type: int
  sample: 1
associated_roles:
  description:
    - A list of dictionaries of the AWS Identity and Access Management (IAM) roles that are associated
      with the DB cluster. Each dictionary contains the role_arn and the status of the role.
  returned: always
  type: list
  sample: []
auto_minor_version_upgrade:
  description: Specifies whether minor engine upgrades are applied automatically to the DB cluster during the maintenance window.
  returned: always
  type: bool
  sample: true
availability_zones:
  description: The list of availability zones that instances in the DB cluster can be created in.
  returned: always
  type: list
  sample:
  - us-east-1c
  - us-east-1a
  - us-east-1e
backup_retention_period:
  description: The number of days for which automatic DB snapshots are retained.
  returned: always
  type: int
  sample: 1
changed:
  description: If the RDS cluster has changed.
  returned: always
  type: bool
  sample: true
cluster_create_time:
  description: The time in UTC when the DB cluster was created.
  returned: always
  type: str
  sample: "2018-06-29T14:08:58.491000+00:00"
copy_tags_to_snapshot:
  description:
    - Specifies whether tags are copied from the DB cluster to snapshots of the DB cluster.
  returned: always
  type: bool
  sample: false
cross_account_clone:
  description:
    - Specifies whether the DB cluster is a clone of a DB cluster owned by a different Amazon Web Services account.
  returned: always
  type: bool
  sample: false
db_cluster_arn:
  description: The Amazon Resource Name (ARN) for the DB cluster.
  returned: always
  type: str
  sample: arn:aws:rds:us-east-1:123456789012:cluster:rds-cluster-demo
db_cluster_identifier:
  description: The lowercase user-supplied DB cluster identifier.
  returned: always
  type: str
  sample: "rds-cluster-demo"
db_cluster_members:
  description:
    - A list of dictionaries containing information about the instances in the cluster.
      Each dictionary contains the db_instance_identifier, is_cluster_writer (bool),
      db_cluster_parameter_group_status, and promotion_tier (int).
  returned: always
  type: list
  sample: []
db_cluster_parameter_group:
  description: The parameter group associated with the DB cluster.
  returned: always
  type: str
  sample: "default.aurora5.6"
db_cluster_resource_id:
  description: The AWS Region-unique, immutable identifier for the DB cluster.
  returned: always
  type: str
  sample: "cluster-D2MEQDN3BQNXDF74K6DQJTHASU"
db_subnet_group:
  description: The name of the subnet group associated with the DB Cluster.
  returned: always
  type: str
  sample: "default"
deletion_protection:
  description:
    - Indicates if the DB cluster has deletion protection enabled.
      The database can't be deleted when deletion protection is enabled.
  returned: always
  type: bool
  sample: false
domain_memberships:
  description:
    - The Active Directory Domain membership records associated with the DB cluster.
  returned: always
  type: list
  sample: []
earliest_restorable_time:
  description: The earliest time to which a database can be restored with point-in-time restore.
  returned: always
  type: str
  sample: "2018-06-29T14:09:34.797000+00:00"
endpoint:
  description: The connection endpoint for the primary instance of the DB cluster.
  returned: always
  type: str
  sample: "rds-cluster-demo.cluster-cvlrtwiennww.us-east-1.rds.amazonaws.com"
engine:
  description: The database engine of the DB cluster.
  returned: always
  type: str
  sample: "aurora"
engine_mode:
  description: The DB engine mode of the DB cluster.
  returned: always
  type: str
  sample: "provisioned"
engine_version:
  description: The database engine version.
  returned: always
  type: str
  sample: "5.6.10a"
hosted_zone_id:
  description: The ID that Amazon Route 53 assigns when you create a hosted zone.
  returned: always
  type: str
  sample: "Z2R2ITUGPM61AM"
http_endpoint_enabled:
  description:
    - A value that indicates whether the HTTP endpoint for an Aurora Serverless DB cluster is enabled.
  returned: always
  type: bool
  sample: false
iam_database_authentication_enabled:
  description: Whether IAM accounts may be mapped to database accounts.
  returned: always
  type: bool
  sample: false
latest_restorable_time:
  description: The latest time to which a database can be restored with point-in-time restore.
  returned: always
  type: str
  sample: "2018-06-29T14:09:34.797000+00:00"
master_username:
  description: The master username for the DB cluster.
  returned: always
  type: str
  sample: "username"
multi_az:
  description: Whether the DB cluster has instances in multiple availability zones.
  returned: always
  type: bool
  sample: false
port:
  description: The port that the database engine is listening on.
  returned: always
  type: int
  sample: 3306
preferred_backup_window:
  description: The UTC weekly time range during which system maintenance can occur.
  returned: always
  type: str
  sample: "10:18-10:48"
preferred_maintenance_window:
  description: The UTC weekly time range during which system maintenance can occur.
  returned: always
  type: str
  sample: "tue:03:23-tue:03:53"
read_replica_identifiers:
  description: A list of read replica ID strings associated with the DB cluster.
  returned: always
  type: list
  sample: []
reader_endpoint:
  description: The reader endpoint for the DB cluster.
  returned: always
  type: str
  sample: "rds-cluster-demo.cluster-ro-cvlrtwiennww.us-east-1.rds.amazonaws.com"
serverless_v2_scaling_configuration:
  description: The scaling configuration for an Aurora Serverless v2 DB cluster.
  returned: when configured
  type: dict
  sample: {
      "max_capacity": 4.5,
      "min_capacity": 2.5
  }
  version_added: 7.3.0
status:
  description: The status of the DB cluster.
  returned: always
  type: str
  sample: "available"
storage_encrypted:
  description: Whether the DB cluster is storage encrypted.
  returned: always
  type: bool
  sample: false
tag_list:
  description: A list of tags consisting of key-value pairs.
  returned: always
  type: list
  elements: dict
  sample: [
    {
      "key": "Created_By",
      "value": "Ansible_rds_cluster_integration_test"
    }
  ]
tags:
  description: A dictionary of key value pairs.
  returned: always
  type: dict
  sample: {
    "Name": "rds-cluster-demo"
  }
vpc_security_groups:
  description: A list of the DB cluster's security groups and their status.
  returned: always
  type: complex
  contains:
    status:
      description: Status of the security group.
      returned: always
      type: str
      sample: "active"
    vpc_security_group_id:
      description: Security group of the cluster.
      returned: always
      type: str
      sample: "sg-12345678"
    N)camel_dict_to_snake_dict)is_boto3_error_code)AnsibleAWSModule)arg_spec_to_rds_params)call_method)ensure_tags)get_tags)wait_for_cluster_status)AWSRetry)ansible_dict_to_boto3_tag_list
   retriesc                      	 t         j                  d      } |j                  di | j                         d   d   S # t	        d      $ r i cY S w xY w)Ndescribe_db_clusters
DBClustersr   DBClusterNotFoundFault )clientget_paginatorpaginatebuild_full_resultr   )params	paginators     j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/amazon/aws/plugins/modules/rds_cluster.py_describe_db_clustersr     s[    (()?@	!y!!+F+==?MaPP78 	s   := AAc                 z    |j                  dg       D cg c]  }|d   	 }}| d   }|||vr|| d   dS i S c c}w )NAssociatedRolesRoleArnDBClusterIdentifier)r   r    get)params_dictclusterrolecurrent_role_arnss       r   get_add_role_optionsr'     s[    5<[[ARTV5WXTiXXy!DD(99DY8Z[[I	 Ys   8c                 ^     g d} d   "t         fd|D              }d v r d   |d<   |S i S )N)BacktrackTor    'UseEarliestTimeOnPointInTimeUnavailabler)   c              3   8   K   | ]  }|   	||   f  y wNr   .0kr#   s     r   	<genexpr>z(get_backtrack_options.<locals>.<genexpr>(  s#     Zq{1~?Y;q>*Z   
ForceBacktrackForcedictr#   optionss   ` r   get_backtrack_optionsr8   %  sE    _G=!-ZGZZ{**+;<GGI    c                 P    g dt        fd| j                         D              S )N)(AvailabilityZonesBacktrackWindowBackupRetentionPeriodPreferredBackupWindowCharacterSetNamer    DBClusterParameterGroupNameDBSubnetGroupNameDatabaseNameEnableCloudwatchLogsExportsEnableIAMDatabaseAuthenticationKmsKeyIdEngine
EngineModeEngineVersionPreferredMaintenanceWindowMasterUserPasswordMasterUsernameOptionGroupNamePortReplicationSourceIdentifierSourceRegionStorageEncryptedTagsVpcSecurityGroupIdsrG   ScalingConfigurationDeletionProtectionEnableHttpEndpointCopyTagsToSnapshotDomainDomainIAMRoleNameEnableGlobalWriteForwardingGlobalClusterIdentifierAllocatedStorageDBClusterInstanceClassStorageTypeIopsrG    ServerlessV2ScalingConfigurationc              3   <   K   | ]  \  }}|v s|||f  y wr,   r   r.   r/   vr7   s      r   r0   z%get_create_options.<locals>.<genexpr>[  #     Y41a!w,1=AY   	r5   itemsr6   s    @r   get_create_optionsrg   /  s'    )GV Y;#4#4#6YYYr9   c                 |    g dt        fd| j                         D              }|s|j                  dd        |S )N)ApplyImmediatelyr<   r=   r>   r    r@   rD   rH   rI   rJ   NewDBClusterIdentifierrL   rM   rR   rD   !CloudwatchLogsExportConfigurationrT   rU   rV   rY   rW   rX   r[   r\   r]   r^   rG   r_   c              3   <   K   | ]  \  }}|v s|||f  y wr,   r   ra   s      r   r0   z%get_modify_options.<locals>.<genexpr>}  s%     cTQALUVUb1a&crd   rJ   )r5   rf   pop)r#   force_update_passwordmodify_optionsr7   s      @r   get_modify_optionsrp   ^  s?    G< c[->->-@ccN /6r9   c                 4     g d}t         fd|D              S )N)r    FinalSnapshotIdentifierSkipFinalSnapshotc              3   8   K   | ]  }|   	||   f  y wr,   r   r-   s     r   r0   z%get_delete_options.<locals>.<genexpr>  s#     SA8RKN#Sr1   r4   r6   s   ` r   get_delete_optionsru     s    UGSWSSSr9   c                 P    g dt        fd| j                         D              S )N) r;   r<   r=   r?   r    r@   rA   rB   rC   rD   rF   rH   rE   rJ   rK   rL   rM   r>   rI   S3BucketNameS3IngestionRoleArnS3PrefixSourceEngineSourceEngineVersionrP   rQ   rR   rT   rU   rV   rW   rX   c              3   <   K   | ]  \  }}|v s|||f  y wr,   r   ra   s      r   r0   z)get_restore_s3_options.<locals>.<genexpr>  rc   rd   re   r6   s    @r   get_restore_s3_optionsr}     s'    !GF Y;#4#4#6YYYr9   c                 P    g dt        fd| j                         D              S )N)r;   r<   r    rA   rB   rC   rD   rF   rH   rE   rL   rM   SnapshotIdentifierrQ   rR   r@   rT   rV   rW   rX   c              3   <   K   | ]  \  }}|v s|||f  y wr,   r   ra   s      r   r0   z/get_restore_snapshot_options.<locals>.<genexpr>  rc   rd   re   r6   s    @r   get_restore_snapshot_optionsr     s&    G, Y;#4#4#6YYYr9   c                 P    g dt        fd| j                         D              S )N)r<   r    rA   rC   rD   rE   rL   rM   RestoreToTimeRestoreTypeSourceDBClusterIdentifierrQ   UseLatestRestorableTimerR   rT   rV   rW   rX   c              3   <   K   | ]  \  }}|v s|||f  y wr,   r   ra   s      r   r0   z.get_restore_cluster_options.<locals>.<genexpr>  rc   rd   re   r6   s    @r   get_restore_cluster_optionsr     s&    G( Y;#4#4#6YYYr9   c                 L   t         j                  d   }t         j                  d   }d }d }|dk(  r| r| d   dvrd}d}||fS |dk(  r| r| d   d	vrd
}d}||fS |dk(  r| r| d   dvrd}d}||fS | rd}d}||fS |dk(  rd}d}||fS |dk(  rd}d}||fS |dk(  rd}d}||fS d}d}||fS )Nstatecreation_sourceabsentStatus)deletingdeleteddelete_db_clusterru   started)startingr   	availablestart_db_clusterrp   stopped)stoppingr   stop_db_clustermodify_db_clustersnapshot restore_db_cluster_from_snapshotr   s3restore_db_cluster_from_s3r}   r$   #restore_db_cluster_to_point_in_timer   create_db_clusterrg   moduler   )r$   r   r   method_namemethod_options_names        r   get_rds_method_attribute_namer     sa   MM'"Emm$56OKwx(0GG-K"64 +++3 
)	wx(0TT,K"6, ++++ 
)	wx(0GG+K"6$ +++! -K"6 +++ 
*<K"@ +++ $6K": +++ 	)?K"?
 +++ .K"6+++r9   c           	      R   t         j                  s0	 t        j                  di |  t        t        t         | d   d       y y # t        j
                  j                  t        j
                  j                  f$ r-}t         j                  |d| d    d| d           Y d }~zd }~ww xY w)NzUnable to add role r   z to cluster r    msgcluster_availabler   )
r   
check_moder   add_role_to_db_clusterbotocore
exceptionsBotoCoreErrorClientErrorfail_json_awsr
   r   es     r   add_roler     s    	))3F3
 	 7L0MObc  ##1183F3F3R3RS 	  ,VI->,?|FShLiKjk !  	s   A 7B&9#B!!B&c                 F   t         j                  s0	 t        j                  di |  t        t        t         | d   d       y y # t        j
                  j                  t        j
                  j                  f$ r'}t         j                  |d| d           Y d }~td }~ww xY w)NzUnable to backtrack cluster r    r   r   r   )
r   r   r   backtrack_db_clusterr   r   r   r   r   r
   r   s     r   backtrack_clusterr     s    	h''1&1 	 7L0MObc  ##1183F3F3R3RS 	h  *FvNcGdFe(f gg	hs   A 7B 9BB c                     	 t        |       S # t        j                  j                  t        j                  j                  f$ r!}t
        j                  |d       Y d }~y d }~ww xY w)N)r    zFailed to describe DB clustersr   )r   r   r   r   r   r   r   )db_cluster_idr   s     r   get_clusterr     sY    F$GG--x/B/B/N/NO FQ$DEEFs    7A&A!!A&c                    i }| j                  d      }| j                  d      }| j                  dd       }|g g d}t        |      }t        |d         }t        t        |j	                  |                  |d<   t
        j                  d   r&t        t        |j	                  |                  |d<   |d   s|d   r||d	<   | j                  d
d       }	|	r|	|d
<   | j                  dd       }
|
r|
|d   k7  r|
|d<   | j                  dd       }|r||d   D cg c]  }|d   	 c}vr||d<   | j                  dd       }|rwg }t        |      }t        |d   D cg c]  }|d   	 c}      }t
        j                  d   rt        t        |            }n||z
  rt        t        ||z              }|r||d<   | j                  dd       }|r||d   k7  r||d<   | D ]x  }|dk(  r	| |   ||<   |dv rP| j                  d      | j                  d      t        fd|j                  dg       D              s| |   ||<   e| |   ||   k7  sq| |   ||<   z |r||d<   |||d<   t
        j                  d   dk(  r#|d   dv rt
        j                  d       i }||d<   t
        j                  d   d k(  r#|d   dv rt
        j                  d!       i }||d<   |S c c}w c c}w )"Nri   r    rC   )EnableLogTypesDisableLogTypesEnabledCloudwatchLogsExportsr   purge_cloudwatch_logs_exportsr   rk   rJ   rj   rL   DBClusterOptionGroupMembershipsDBClusterOptionGroupNamerR   VpcSecurityGroupsVpcSecurityGroupIdpurge_security_groupsr@   DBClusterParameterGroupr]   )rW   rX   rW   rX   c              3   r   K   | ].  }|j                  d       k(  xr |j                  d      k(   0 yw)rW   IAMRoleNameNr!   )r.   dn_domainn_domain_iam_role_names     r   r0   z+changing_cluster_options.<locals>.<genexpr>l  s>       AEE(O+^0F!%%P]J^0^^s   47DomainMembershipsr   r   rF   mysqlpostgresz.Only aurora clusters can use the state startedr   z.Only aurora clusters can use the state stopped)
rm   setsortedlist
differencer   r   r"   any	fail_json)modify_paramscurrent_clusterchanging_paramsapply_immediatelyr   enable_cloudwatch_logs_export%desired_cloudwatch_logs_configurationprovided_cloudwatch_logscurrent_cloudwatch_logs_exportpasswordnew_cluster_idoption_groupgvpc_sgsdesired_vpc_sgsprovided_vpc_sgssgcurrent_vpc_sgs"desired_db_cluster_parameter_groupparamr   r   s                       @@r   changing_cluster_optionsr   "  s   O%))*<=!%%&;<M$1$5$56SUY$Z!$0CEZ\0]-#&'D#E ),_=[-\)]&BH)445STUC
-.>? ==89GM3>>?WXYH12CD 22BC45FGChO?@  !5t<H08,-"&&'?FN.O<Q,RR4B01 $$%6=L/>?`/a-*+
$%-  .:)* 5t<Gw</ReBfgBr"67gh==01$T*:%;<O/1"(.>.P)Q"R5DO12)6):):;XZ^)_&)-AZ1[[=_O9: :M!%25%9OE" 33$((2H%2%6%67J%K" (,,-@"E  *7u)=&?5#99%25%9OE"1:4 1>-.(2CO./}}W*8$(==MN1>-.}}W*8$(==MN1>-.K- hs   KK"c           
      N   d}| sJ|j                  d      t        |d         |d<   t        t        t        | t        |      |             d}nt        |      r!t        t        t        t        |             d}n t        |      |t        j                  d         }t        ||       }|rt        t        t        ||       d}t        j                  d   Xt        t        t        | d         }|t        t        t        | d   |t        j                  d   t        j                  d         z  }t        ||       }|rt        t        t        |       d}t        j                  d	   r=| j                  d
      r,t        t        t        ddt        j                  d   i       d}|S )NFrQ   Trn   )rn   tagsDBClusterArn
purge_tagspromoterN   promote_read_replica_db_clusterr    db_cluster_identifier)
parameters)r"   r   r   r   r   evalr8   r   r   r   r	   r   r'   r   )	r$   r   r   r   changedmodifiable_optionsro   existing_tagsadd_role_paramss	            r   ensure_presentr     sy   G>>&!-!?
6@R!SJvFFK1J6I1J:1VW ,ff.CJ.OPG!:&9!:&--@W2X" 66H'RNFFKH}}V$0 (9P Q;N+!MM&)MM,/  +:w?O1}}YGKK0M$N--v}}=T/UV		
 Nr9   c           	      >   t         j                  j                  d      }t         j                  j                  d      }| d   }t         j                  ry	 t        j                  ||       d
| v rt        t        t         |d       t         j                  j                  d      rt        t        t         |d       y# t        j                  j                  t        j                  j                  f$ r(}t         j                  |d| d| d	       Y d }~d }~ww xY w)Nglobal_cluster_identifierr   r   T)DbClusterIdentifierrZ   zFailed to remove cluster z from global DB cluster .r   GlobalWriteForwardingStatusdb_cluster_promotingwaitr   )r   r   r"   r   r   remove_from_global_clusterr   r   r   r   r   r
   )r$   global_cluster_idr   db_cluster_arnr   s        r   handle_remove_from_global_dbr     s    ))*EFMM%%&=>M^,N
))nfw)x %/?UV }} ?RS --x/B/B/N/NO 
.}o=UVgUhhij 	 	
 	

s   B= =7D4DDc                  \   t        t        g dd      t        dg d      t        dd	      t        dd	      t        dd
	      t        dd
	      t        dd
	      t        dd
	            } t        di dt        dd	      dt        ddddg      dt               dt        d      dt        dd	      dt               dt        dg      dt        d
g d      dt               d t               d!t        dd"      d#t        d      d$t               d%t        d      d&t        d      d't               d(t               d)t        d      d*t        d      d+t        d      d,t        g d-.      d/t        g d0.      d1t               d2t        d      d3t        dg d4      d5t        d      d6t               d7t        d      d8t               d9t        d:gd
;      d<t        d=g      d>t        g d?      d@t               dAt        d      dBt        dCg      dDt        dEg      dFt        d      dGt        dHg      dIt               dJt        dKdLg.      dMt               dNt               dOt               dPt               dQt        dRt        t        dS      t        dS      T      U      dVt        dd	      dWt               dXt               dYt        dZg.      d[t               d\t               d]t        d      d^t        dRd_g`      dat        d      dbt        d      dct        dd"      | j                         g dd}t        | dedfdWd,ggdedg|gdFd
d$dgggg dhdbdIggd
i      at	        j
                  djk      }	 t        j                  dl|m      at        j                  j                  d,      rt        j                  d,   dpv rt        j                  dq   dk(  rt        j                  j                  d2      r>t        j                  j                  d5      rt        j                  j                  d*      s+t        j                  drt        j                  d,    ds       n2t        j                  j                  d3      sdtt        j                  d3<   t        j                  j                  d,      rWt        j                  d,   duv rBt        j                  s2t        j                  j                  d3      rdvt        j                  d3<   t        j                  j                  d3      r`t        j                  d3   dwv rKt        j                  j                  d,      duvr*t        j                  dxt        j                  d3    dy       t        j                  d   j!                         t        j                  d<   t#        t        j                  d         }t        j                  d>   rt        j                  d>   j!                         t        j                  d><   t#        t        j                  d>         r*t        j                  dzt        j                  d>    d{       |s*t        j                  dzt        j                  d>    d|       t        j                  dq   d}k(  r>t        j                  dV   du r)t        j                  d6   t        j                  d~o       d}t%        t        fdt        j                  D                    }t'        |      \  }}|rq|dk(  r[|r1t        j                  j                  dF      r|d   duv rt)        |      }t+        t        t        | t-        |      |             d
}n|t/        ||||      z  }t        j                  s:t        j                  d>   r't        j                  d   rt        j                  d>   }	nt        j                  d   }	|	rWt#        |	      rLt        j                  j                  dF      r-|d   duv r|rt1        t        t        |	d       |t)        |      z  }t3        t#        |	            }
|
rt5        t        t        |
d         |
d^<   t        j6                  dd|i|
 y # t        j                  j                  t        j                  j                  f$ r"}t        j                  |dno       Y d }~Sd }~ww xY w)N)presentr   r   r   r   )choicesdefaultstr)r   r   r$   )typer  boolF)r  r  T)r   r   rn   r   r   r   r   r   r   availability_zonesr   zonesaz)r  elementsaliasesbacktrack_tobacktrack_windowint)r  backup_retention_period   character_set_namedatabase_namedb_name)r
  r   )
cluster_ididcluster_name)requiredr
  db_cluster_parameter_group_namedb_subnet_group_nameenable_cloudwatch_logs_exports)r  r	  deletion_protectionr   enable_http_endpointcopy_tags_to_snapshotdomaindomain_iam_role_nameenable_global_write_forwardingdb_cluster_instance_class"enable_iam_database_authenticationengine)auroraaurora-mysqlaurora-postgresqlr   r   )r  engine_mode)provisioned
serverlessparallelqueryglobalmultimasterengine_versionallocated_storagestorage_type)io1r#  aurora-iopt1iopsfinal_snapshot_identifierforce_backtrack
kms_key_idmaster_user_passwordr   )r
  no_logmaster_usernameusernamenew_db_cluster_identifier)r   new_idnew_cluster_nameoption_group_nameportpreferred_backup_windowbackup_windowpreferred_maintenance_windowmaintenance_windowremove_from_global_dbreplication_source_identifierreplication_src_idrestore_to_timerestore_typez	full-copyzcopy-on-writerole_arns3_bucket_names3_ingestion_role_arn	s3_prefix#serverless_v2_scaling_configurationr5   float)min_capacitymax_capacity)r  r7   skip_final_snapshotsnapshot_identifiersource_db_cluster_identifiersource_enginer   source_engine_versionsource_regionstorage_encryptedr   resource_tags)r  r
  .use_earliest_time_on_point_in_time_unavailableuse_latest_restorable_timevpc_security_group_ids)rH  r"  r7  r5  rR  rS  rI  r   r   r   )rH  rQ  rP  )argument_specrequired_ifmutually_exclusivesupports_check_moder   r   rds)retry_decoratorzFailed to connect to AWS.r   r   r   zWhen engine=zH allocated_storage, iops and db_cluster_instance_class must be specifiedr/  )r#  r$  r%  r#  )r#  r0  zstorage_type=zS is only supported for aurora engines 'aurora', 'aurora-mysql', 'aurora-postgresql'zA new cluster ID z# was provided but it already existsz: was provided but the cluster to be renamed does not existr   z\skip_final_snapshot is False but all of the following are missing: final_snapshot_identifierc              3   R   K   | ]  }|v s|t         j                  |   f   y wr,   r   )r.   r/   parameter_optionss     r   r0   zmain.<locals>.<genexpr>z  s(     ,tq]^bs]saq1A-B,ts   	''r   rF   r   r   r   r   )r5   updater   r   r   jittered_backoffr   r   r   r   r   r   r   r"   r   r   lowerr   r   r   r   r   r   r   r
   r   r	   	exit_json)arg_specrequired_by_s3_creation_sourcer_  r   r$   r   r   r   r   r  resultra  s              @r   mainri    s    FPYZ%1NO">&%0&*&EVT2vt,"=	H  ?FE:?Vegt_U? V? 5)	?
 !%% ;?  6? I;/? #D:^_? )-? "V? (,%'H? !f-? #'&? "v.? #/?  v!?" "V#?$ (,'8%?& #'E"2'?( ,0V+<)?* `a+?, !hi-?. v/?0 E*1?2 u.OP3?4 u5?6 #'&7?8 &)9?: 6;?< ":,tD=?> j\2??@ #'/_"`A?B &C?D uE?F !%o-> ?G?H &*3G2H%II?J #/K?L '+4H3I&JM?N O?P ;"@AQ?R S?T vU?V #fW?X &Y?Z -1!w/!w/-
[?h !fe<i?j !Fk?l &*Vm?n G9-o?p #fq?r fs?t F+u?v v'89w?x 8<7Hy?z $(V#4{?|  $%@}?@ OO%&&" 
-BH,MN&DE$d-HJa,bc
 V)+<=
 !F //;OAuoF }}"v}}X'>BW'W==!Y.!!"56MM%%f-MM%%&AB  "6==#:";  <D  E
 }}((849FMM.1}}"v}}X'>Bq'q  V]]%6%6~%F,4FMM.)}}(V]]>-JNh-h==X&.]]n =>  ?R  S .4]];R-S-Y-Y-[FMM)*&--(?@AG}}015;]]C^5_5e5e5g12v}}%@AB#FMM2M$N#OOrs #FMM2M$N#O  PJ  K
 	g(*MM/0E9MM56>n 	 	
 G',tFMM,t(tuJ'DW'M$K$--6==,,-DE8$(WW:7CG5NT:M5Nz5Z[G~gz;H[\\G/J!KPVP]P]^qPr]]#>?
]]#:;
k*-&--2C2CD[2\8 OO'
DWX/88%k*&=>F!&&&9I2JKv
/W//i ++X-@-@-N-NO AQ$?@@As   <c 7d+	d&&d+__main__)(DOCUMENTATIONEXAMPLESRETURNr   ImportError0ansible.module_utils.common.dict_transformationsr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   ;ansible_collections.amazon.aws.plugins.module_utils.modulesr   7ansible_collections.amazon.aws.plugins.module_utils.rdsr   r   r   r	   r
   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   rc  r   r'   r8   rg   rp   ru   r}   r   r   r   r   r   r   r   r   r   ri  __name__r   r9   r   <module>rv     s   [zjXo
b	 V \ X Z O O L [ P f 2& ',Z^"JT
$ZNZ4Z0#,LddFfR.b6A0H zF o  		s   B B'&B'