
    Vh                     h   d Z dZdZddlZddlZddlm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 ddlmZ ddlmZ ddlmZ ddlm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)$a3  
---
module: opensearch
short_description: Creates OpenSearch or ElasticSearch domain
description:
  - Creates or modify a Amazon OpenSearch Service domain.
version_added: 4.0.0
author:
  - "Sebastien Rosset (@sebastien-rosset)"
options:
  state:
    description:
      - Creates or modifies an existing OpenSearch domain.
      - Deletes an OpenSearch domain.
    required: false
    type: str
    choices: ['present', 'absent']
    default: present
  domain_name:
    description:
      - The name of the Amazon OpenSearch/ElasticSearch Service domain.
      - Domain names are unique across the domains owned by an account within an AWS region.
    required: true
    type: str
  engine_version:
    description:
      ->
        The engine version to use. For example, 'ElasticSearch_7.10' or 'OpenSearch_1.1'.
      ->
        If the currently running version is not equal to I(engine_version),
        a cluster upgrade is triggered.
      ->
        It may not be possible to upgrade directly from the currently running version
        to I(engine_version). In that case, the upgrade is performed incrementally by
        upgrading to the highest compatible version, then repeat the operation until
        the cluster is running at the target version.
      ->
        The upgrade operation fails if there is no path from current version to I(engine_version).
      ->
        See OpenSearch documentation for upgrade compatibility.
    required: false
    type: str
  allow_intermediate_upgrades:
    description:
      - >
        If true, allow OpenSearch domain to be upgraded through one or more intermediate versions.
      - >
        If false, do not allow OpenSearch domain to be upgraded through intermediate versions.
        The upgrade operation fails if it's not possible to ugrade to I(engine_version) directly.
    required: false
    type: bool
    default: true
  cluster_config:
    description:
      - Parameters for the cluster configuration of an OpenSearch Service domain.
    type: dict
    suboptions:
      instance_type:
        description:
          - Type of the instances to use for the domain.
        required: false
        type: str
      instance_count:
        description:
          - Number of instances for the domain.
        required: false
        type: int
      zone_awareness:
        description:
          - A boolean value to indicate whether zone awareness is enabled.
        required: false
        type: bool
      availability_zone_count:
        description:
          - >
            An integer value to indicate the number of availability zones for a domain when zone awareness is enabled.
            This should be equal to number of subnets if VPC endpoints is enabled.
        required: false
        type: int
      dedicated_master:
        description:
          - A boolean value to indicate whether a dedicated master node is enabled.
        required: false
        type: bool
      dedicated_master_instance_type:
        description:
          - The instance type for a dedicated master node.
        required: false
        type: str
      dedicated_master_instance_count:
        description:
          - Total number of dedicated master nodes, active and on standby, for the domain.
        required: false
        type: int
      warm_enabled:
        description:
          - True to enable UltraWarm storage.
        required: false
        type: bool
      warm_type:
        description:
          - The instance type for the OpenSearch domain's warm nodes.
        required: false
        type: str
      warm_count:
        description:
          - The number of UltraWarm nodes in the domain.
        required: false
        type: int
      cold_storage_options:
        description:
          - Specifies the ColdStorageOptions config for a Domain.
        type: dict
        suboptions:
          enabled:
            description:
              - True to enable cold storage. Supported on Elasticsearch 7.9 or above.
            required: false
            type: bool
  ebs_options:
    description:
      - Parameters to configure EBS-based storage for an OpenSearch Service domain.
    type: dict
    suboptions:
      ebs_enabled:
        description:
          - Specifies whether EBS-based storage is enabled.
        required: false
        type: bool
      volume_type:
        description:
          - Specifies the volume type for EBS-based storage. "standard"|"gp2"|"io1"
        required: false
        type: str
      volume_size:
        description:
          - Integer to specify the size of an EBS volume.
        required: false
        type: int
      iops:
        description:
          - The IOPD for a Provisioned IOPS EBS volume (SSD).
        required: false
        type: int
  vpc_options:
    description:
      - Options to specify the subnets and security groups for a VPC endpoint.
    type: dict
    suboptions:
      subnets:
        description:
          - Specifies the subnet ids for VPC endpoint.
        required: false
        type: list
        elements: str
      security_groups:
        description:
          - Specifies the security group ids for VPC endpoint.
        required: false
        type: list
        elements: str
  snapshot_options:
    description:
      - Option to set time, in UTC format, of the daily automated snapshot.
    type: dict
    suboptions:
      automated_snapshot_start_hour:
        description:
          - >
            Integer value from 0 to 23 specifying when the service takes a daily automated snapshot
            of the specified Elasticsearch domain.
        required: false
        type: int
  access_policies:
    description:
      - IAM access policy as a JSON-formatted string.
    required: false
    type: dict
  encryption_at_rest_options:
    description:
      - Parameters to enable encryption at rest.
    type: dict
    suboptions:
      enabled:
        description:
          - Should data be encrypted while at rest.
        required: false
        type: bool
      kms_key_id:
        description:
          - If encryption at rest enabled, this identifies the encryption key to use.
          - The value should be a KMS key ARN. It can also be the KMS key id.
        required: false
        type: str
  node_to_node_encryption_options:
    description:
      - Node-to-node encryption options.
    type: dict
    suboptions:
      enabled:
        description:
            - True to enable node-to-node encryption.
        required: false
        type: bool
  cognito_options:
    description:
      - Parameters to configure OpenSearch Service to use Amazon Cognito authentication for OpenSearch Dashboards.
    type: dict
    suboptions:
      enabled:
        description:
          - The option to enable Cognito for OpenSearch Dashboards authentication.
        required: false
        type: bool
      user_pool_id:
        description:
          - The Cognito user pool ID for OpenSearch Dashboards authentication.
        required: false
        type: str
      identity_pool_id:
        description:
          - The Cognito identity pool ID for OpenSearch Dashboards authentication.
        required: false
        type: str
      role_arn:
        description:
          - The role ARN that provides OpenSearch permissions for accessing Cognito resources.
        required: false
        type: str
  domain_endpoint_options:
    description:
      - Options to specify configuration that will be applied to the domain endpoint.
    type: dict
    suboptions:
      enforce_https:
        description:
          - Whether only HTTPS endpoint should be enabled for the domain.
        type: bool
      tls_security_policy:
        description:
          - Specify the TLS security policy to apply to the HTTPS endpoint of the domain.
        type: str
      custom_endpoint_enabled:
        description:
          - Whether to enable a custom endpoint for the domain.
        type: bool
      custom_endpoint:
        description:
          - The fully qualified domain for your custom endpoint.
        type: str
      custom_endpoint_certificate_arn:
        description:
          - The ACM certificate ARN for your custom endpoint.
        type: str
  advanced_security_options:
    description:
      - Specifies advanced security options.
    type: dict
    suboptions:
      enabled:
        description:
          - True if advanced security is enabled.
          - You must enable node-to-node encryption to use advanced security options.
        type: bool
      internal_user_database_enabled:
        description:
          - True if the internal user database is enabled.
        type: bool
      master_user_options:
        description:
          - Credentials for the master user, username and password, ARN, or both.
        type: dict
        suboptions:
          master_user_arn:
            description:
              - ARN for the master user (if IAM is enabled).
            type: str
          master_user_name:
            description:
              - The username of the master user, which is stored in the Amazon OpenSearch Service domain internal database.
            type: str
          master_user_password:
            description:
              - The password of the master user, which is stored in the Amazon OpenSearch Service domain internal database.
            type: str
      saml_options:
        description:
          - The SAML application configuration for the domain.
        type: dict
        suboptions:
          enabled:
            description:
              - True if SAML is enabled.
              - To use SAML authentication, you must enable fine-grained access control.
              - You can only enable SAML authentication for OpenSearch Dashboards on existing domains,
                not during the creation of new ones.
              - Domains only support one Dashboards authentication method at a time.
                If you have Amazon Cognito authentication for OpenSearch Dashboards enabled,
                you must disable it before you can enable SAML.
            type: bool
          idp:
            description:
              - The SAML Identity Provider's information.
            type: dict
            suboptions:
              metadata_content:
                description:
                  - The metadata of the SAML application in XML format.
                type: str
              entity_id:
                description:
                  - The unique entity ID of the application in SAML identity provider.
                type: str
          master_user_name:
            description:
              - The SAML master username, which is stored in the Amazon OpenSearch Service domain internal database.
            type: str
          master_backend_role:
            description:
              - The backend role that the SAML master user is mapped to.
            type: str
          subject_key:
            description:
              - Element of the SAML assertion to use for username. Default is NameID.
            type: str
          roles_key:
            description:
              - Element of the SAML assertion to use for backend roles. Default is roles.
            type: str
          session_timeout_minutes:
            description:
              - The duration, in minutes, after which a user session becomes inactive. Acceptable values are between 1 and 1440, and the default value is 60.
            type: int
  auto_tune_options:
    description:
      - Specifies Auto-Tune options.
    type: dict
    suboptions:
      desired_state:
        description:
          - The Auto-Tune desired state. Valid values are ENABLED and DISABLED.
        type: str
        choices: ['ENABLED', 'DISABLED']
      maintenance_schedules:
        description:
          - A list of maintenance schedules.
        type: list
        elements: dict
        suboptions:
          start_at:
            description:
              - The timestamp at which the Auto-Tune maintenance schedule starts.
            type: str
          duration:
            description:
              - Specifies maintenance schedule duration, duration value and duration unit.
            type: dict
            suboptions:
              value:
                description:
                  - Integer to specify the value of a maintenance schedule duration.
                type: int
              unit:
                description:
                  - The unit of a maintenance schedule duration. Valid value is HOURS.
                choices: ['HOURS']
                type: str
          cron_expression_for_recurrence:
            description:
              - A cron expression for a recurring maintenance schedule.
            type: str
  wait:
    description:
      - Whether or not to wait for completion of OpenSearch creation, modification or deletion.
    type: bool
    default: false
  wait_timeout:
    description:
      - how long before wait gives up, in seconds.
    default: 300
    type: int
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.tags
  - amazon.aws.boto3
z # aL	  

- name: Create OpenSearch domain for dev environment, no zone awareness, no dedicated masters
  community.aws.opensearch:
    domain_name: "dev-cluster"
    engine_version: Elasticsearch_1.1
    cluster_config:
      instance_type: "t2.small.search"
      instance_count: 2
      zone_awareness: false
      dedicated_master: false
    ebs_options:
      ebs_enabled: true
      volume_type: "gp2"
      volume_size: 10
    access_policies: "{{ lookup('file', 'policy.json') | from_json }}"

- name: Create OpenSearch domain with dedicated masters
  community.aws.opensearch:
    domain_name: "my-domain"
    engine_version: OpenSearch_1.1
    cluster_config:
      instance_type: "t2.small.search"
      instance_count: 12
      dedicated_master: true
      zone_awareness: true
      availability_zone_count: 2
      dedicated_master_instance_type: "t2.small.search"
      dedicated_master_instance_count: 3
      warm_enabled: true
      warm_type: "ultrawarm1.medium.search"
      warm_count: 1
      cold_storage_options:
        enabled: false
    ebs_options:
      ebs_enabled: true
      volume_type: "io1"
      volume_size: 10
      iops: 1000
    vpc_options:
      subnets:
        - "subnet-e537d64a"
        - "subnet-e537d64b"
      security_groups:
        - "sg-dd2f13cb"
        - "sg-dd2f13cc"
    snapshot_options:
      automated_snapshot_start_hour: 13
    access_policies: "{{ lookup('file', 'policy.json') | from_json }}"
    encryption_at_rest_options:
      enabled: false
    node_to_node_encryption_options:
      enabled: false
    auto_tune_options:
      enabled: true
      maintenance_schedules:
        - start_at: "2025-01-12"
          duration:
            value: 1
            unit: "HOURS"
          cron_expression_for_recurrence: "cron(0 12 * * ? *)"
        - start_at: "2032-01-12"
          duration:
            value: 2
            unit: "HOURS"
          cron_expression_for_recurrence: "cron(0 12 * * ? *)"
    tags:
      Environment: Development
      Application: Search
    wait: true

- name: Increase size of EBS volumes for existing cluster
  community.aws.opensearch:
    domain_name: "my-domain"
    ebs_options:
      volume_size: 5
    wait: true

- name: Increase instance count for existing cluster
  community.aws.opensearch:
    domain_name: "my-domain"
    cluster_config:
      instance_count: 40
    wait: true
    N)deepcopy)string_types)is_boto3_error_code)compare_policies)AWSRetry)boto3_tag_list_to_ansible_dict)AnsibleCommunityAWSModule)compare_domain_versions)ensure_tags)get_domain_config)get_domain_status)get_target_increment_version)normalize_opensearch)parse_version)wait_for_domain_statusc                    |j                   j                  d      }d}t        | ||      }|j                  r|j	                  dd       	 | j                  |       d}|r|j                   j                  d      st        |      S 	 t        | ||d       t        |      S # t        d      $ r t        d      cY S t        j                  j                  t        j                  j                  f$ r}|j                  |d	
       Y d }~d }~ww xY w# t        d      $ r t        |      cY S t        j                  j                  t        j                  j                  f$ r}|j                  |d       Y d }~y d }~ww xY w)Ndomain_nameFTz.Would have deleted domain if not in check modechangedmsg)
DomainNameResourceNotFoundException)r   ztrying to delete domainr   waitdomain_deletedzawaiting domain deletion)paramsgetr   
check_mode	exit_jsondelete_domainr   dictbotocore
exceptionsClientErrorBotoCoreErrorfail_json_awsr   )clientmoduler   r   domaines         l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/opensearch.pyensure_domain_absentr,     se   --##M2KGvv{;F+[\
?4 **62G$$	<vv{<LMG$$ :; #E""'')) ? 	Q$=>>	? :; %G$$'')) < 	Q :;;	<s<   B# 	D #D?6D5DDF16F'E>>Fc           
         |j                   j                  d      }|}d}|j                  rd}|}||k7  rt        | |||      }||}||k7  r6|j                   j                  d      s|j	                  d| d| d|        |||d	}	|j                  st        | ||d
       	  | j                  di |	 |j                  r|j                  dd| d| d       |}||k7  r|j                   j                  d      rt        | ||d
       y y # t        j                  j                  t        j                  j                  f$ r&}
|j                  |
d| d| d|        Y d }
~
d }
~
ww xY w)Nr   FTallow_intermediate_upgradeszCannot upgrade from z to version z$. The highest compatible version is r   )r   TargetVersionPerformCheckOnlydomain_availablezCouldn't upgrade domain z from  to z Would have upgraded domain from z if not in check moder   r    )r   r   r   r   	fail_jsonr   upgrade_domainr"   r#   r%   r$   r&   r   )r'   r(   source_versiontarget_engine_versionr   next_versionperform_check_onlycurrent_versionv
parametersr*   s              r+   r5   r5   !  s   --##M2K )L !$O
2
2(F[\9 1L00 ==$$%BC  .~.>lK`Ja  bF  GS  FT  U ! 
 &) 2

    #66;@RS	!F!!/J/ 66GtL>Yno   'W 2
2Z }} vv{<NO ! ##1183F3F3R3RS 	   .{m6/ARRVWcVde !  	s   #D 7E+E&&E+c                    d}|d   }| j                   j                  d      }||j                  d      |j                  d      |d<   |j                  d      |j                  d      |d<   |j                  d      |j                  d      |d	<   |d	   r'|j                  d
      d|j                  d
      i|d<   |j                  d      |j                  d      |d<   |d   rJ|j                  d      |j                  d      |d<   |j                  d      |j                  d      |d<   |j                  d      |j                  d      |d<   |d   rJ|j                  d      |j                  d      |d<   |j                  d      |j                  d      |d<   d }||j                  d      }t        |d   d      dk  rS|#|j                  d      r| j                  d       |j	                  d d        |Cd|v r?|d   j	                  d d        n)|'|j                  d      d!|j                  d      i|d <   |$|d   |k7  r|j                  d"|d    d#|        d$}|S )%NFClusterConfigcluster_configinstance_typeInstanceTypeinstance_countInstanceCountzone_awarenessZoneAwarenessEnabledavailability_zone_countAvailabilityZoneCountZoneAwarenessConfigdedicated_masterDedicatedMasterEnableddedicated_master_instance_typeDedicatedMasterTypededicated_master_instance_countDedicatedMasterCountwarm_enabledWarmEnabled	warm_typeWarmType
warm_count	WarmCountcold_storage_optionsEngineVersionzElasticsearch_7.9r   enabledzCold Storage is not supportedr   ColdStorageOptionsEnabledzClusterConfig changed from r2   T)r   r   r
   r4   popappend)r(   current_domain_configdesired_domain_config
change_setr   r?   cluster_optscold_storage_optss           r+   set_cluster_configra   ]  s   G*?;N==$$%56LO,8-9-=-=o-NN>*,-9.:.>.>?O.PN?+,-95A5E5EFV5WN1201 9:F+\-=-=>W-X945 ./;7C7G7GHZ7[N3423 @AM8D8H8HIi8j45 ABN9E9I9IJk9l56N+7,8,<,<^,LN=)-(,8-9-=-=k-Jz*-9.:.>.>|.L{+(,,-CD4_EGZ[^__
 (->-B-B9-M!@A/6 ,DY1Y "/2667KTR (->-B-B9-M-Y,00;4N/0 (-B?-SWe-e78Mo8^7__cdrcstuN    c                    d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   |d   sddi|d<   no|j                  d      |j                  d      |d<   |j                  d      |j                  d      |d	<   |j                  d
      |j                  d
      |d<   |$|d   |k7  r|j                  d|d    d|        d}|S )NF
EBSOptionsebs_optionsebs_enabled
EBSEnabledvolume_type
VolumeTypevolume_size
VolumeSizeiopsIopszEBSOptions changed from r2   Tr   r   r[   )r(   r\   r]   r^   r   
ebs_configebs_optss          r+   set_ebs_optionsrq     s   G&|4J}}  /H||M".#+<<#>
< l#%/
l+ <<&2'/||M'BJ|$<<&2'/||M'BJ|$<<+!)f!5Jv(-B<-PT^-^45J<5X4YY]^h]ijkNrb   c                 J   d}|d   }| j                   j                  d      }|y|j                  d      |j                  d      |d<   |d   sddi|d<   n%|j                  d      |j                  d      |d<   |$|d   |k7  r|j                  d|d    d	|        d
}|S )NFEncryptionAtRestOptionsencryption_at_rest_optionsrW   rY   
kms_key_idKmsKeyIdz%EncryptionAtRestOptions changed from r2   Trn   )r(   r\   r]   r^   r   encryption_at_rest_configencryption_at_rest_optss          r+   set_encryption_at_rest_optionsry     s    G 56O P$mm//0LM&""9-9/F/J/J9/U!),$Y/u<
78 #&&|4@4K4O4OP\4]%j1 	)!";<@YY34IJc4d3e f)*,	
 Nrb   c                     d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   |$|d   |k7  r|j                  d|d    d|        d}|S )	NFNodeToNodeEncryptionOptionsnode_to_node_encryption_optionsrW   rY   z)NodeToNodeEncryptionOptions changed from r2   Trn   )r(   r\   r]   r^   r   node_to_node_encryption_confignode_to_node_encryption_optss          r+   #set_node_to_node_encryption_optionsr     s    G%:;X%Y"#)==#4#45V#W #+#''	2>4P4T4TU^4_&y1 	)!"?@Dbb78MNk8l7m n./1	
 Nrb   c                    d}d }d|v r|d   }| j                   j                  d      }||S |j                  d      }|J|i }||d<   t        |t              r,|j	                  d      D cg c]  }|j                          }}||d<   |j                  d      }	|	J|i }||d<   t        |	t              r,|	j	                  d      D cg c]  }|j                          }	}|	|d<   |d}
d}d|v rd|d   v rt        |d   d         d	kD  rd
}
d|v rd|d   v rt        |d   d         d	kD  rd
}|
|k7  r|j                  d       d
}|S |du r	 |S t        |d   d         t        |d         k7  r"|j                  d|d   d    d|d           d
}t        |d   d         t        |d         k7  r"|j                  d|d   d    d|d           d
}|S c c}w c c}w )NF
VPCOptionsvpc_optionssubnets,	SubnetIdssecurity_groupsSecurityGroupIdsr   Tz+VPCOptions changed between Internet and VPCzSubnetIds changed from r2   zSecurityGroup changed from )	r   r   
isinstancer   splitstriplenr[   set)r(   r\   r]   r^   r   
vpc_configvpc_optsvpc_subnetsxvpc_security_groupscurrent_cluster_is_vpcdesired_cluster_is_vpcs               r+   set_vpc_optionsr     s   GJ,,*<8
}}  /H,,y)KJ2<!,/k<0.9.?.?.DE1779EKE"-
;",,'89&J2<!,/)<86I6O6OPS6T"U1779"U"U)<
%&(!&!&114\BB),7DEI%)"114\BB),7DEI%)"!%;;KLG$ N# $u, N (6{CDJWbLcHdd!!-.CL.QR].^-_ `";/02 (67IJKsS]^pSqOrr!!12G2UVh2i1j k"#5679 Nc F #Vs   ,G	Gc                     d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   ||d   |k7  r|j                  d       d}|S )NFSnapshotOptionssnapshot_optionsautomated_snapshot_start_hourAutomatedSnapshotStartHourzSnapshotOptions changedTrn   )r(   r\   r]   r^   r   snapshot_configsnapshot_optss          r+   set_snapshot_optionsr   *  s    G+,=>OMM%%&89M89E8E8I8IJi8j45(-BCT-UYh-h34Nrb   c                    d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   |d   sddi|d<   no|j                  d      |j                  d      |d<   |j                  d      |j                  d      |d	<   |j                  d
      |j                  d
      |d<   |$|d   |k7  r|j                  d|d    d|        d}|S )NFCognitoOptionscognito_optionsrW   rY   cognito_user_pool_id
UserPoolIdcognito_identity_pool_idIdentityPoolIdcognito_role_arnRoleArnzCognitoOptions changed from r2   Trn   )r(   r\   r]   r^   r   cognito_configcognito_optss          r+   set_cognito_optionsr   8  s4   G*+;<N==$$%67L	".$0$4$4Y$?y!)$u3
./ 23?+7+;+;<R+SN<(67C/;/?/?@Z/[N+,./;(4(8(89K(LN9%(-BCS-TXf-f89NO_9`8aaefteuvwNrb   c                 b   d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   |d   s	ddi|d<   n/|j                  d      |j                  d      |d<   |j                  d      }||j                  d	i        |j                  d
      |j                  d
      |d	   d<   |j                  d      |j                  d      |d	   d<   |j                  d      |j                  d      |d	   d<   |j                  d      }|Y|j                  d      |j                  d      |d   d<   |j                  d      }	|	V|	j                  d      |	j                  d      |d   d   d<   |	j                  d      |	j                  d      |d   d   d<   |j                  d      |j                  d      |d   d<   |j                  d      |j                  d      |d   d<   |j                  d      |j                  d      |d   d<   |j                  d      |j                  d      |d   d<   |j                  d      |j                  d      |d   d<   |$|d   |k7  r|j                  d |d    d!|        d"}|S )#NFAdvancedSecurityOptionsadvanced_security_optionsrW   rY   internal_user_database_enabledInternalUserDatabaseEnabledmaster_user_optionsMasterUserOptionsmaster_user_arnMasterUserARNmaster_user_nameMasterUserNamemaster_user_passwordMasterUserPasswordsaml_optionsSamlOptionsidpmetadata_contentIdpMetadataContent	entity_idEntityIdmaster_backend_roleMasterBackendRolesubject_key
SubjectKey	roles_keyRolesKeysession_timeout_minutesSessionTimeoutMinutesz%AdvancedSecurityOptions changed from r2   T)r   r   
setdefaultr[   )
r(   r\   r]   r^   r   advanced_security_configadvanced_security_optsmaster_user_opts	saml_optsidp_optss
             r+   set_advanced_security_optionsr   R  sG   G45NO#]]../JK%!!),8.D.H.H.S +#I.u<
78 "%%&FGSF\F`F`0G$%BC 2556KL'$//0CRH##$56BQaQeQefwQx()<=oN##$67CRbRfRf&S()<=>NO  ##$:;GVfVjVj*W()<=>RS +..~>	 }}Y'3EN]]S\E](7	B }}U+H#<< 23?X`XdXdewXx,];EBCTU<<,8QYQ]Q]^iQj,];EB:N}}/0<LUMMZlLm(78HI}}23?OX}}]rOs(78KL}}]+7HQVcHd(7E}}[)5FOmmT_F`(7
C}}67CS\S`S`-T(78OP
 	)!";<@XX34IJc4d3e f()+	
 Nrb   c                    d}|d   }| j                   j                  d      }||S |j                  d      |j                  d      |d<   |j                  d      |j                  d      |d<   |j                  d      |j                  d      |d	<   |d	   rJ|j                  d
      |j                  d
      |d<   |j                  d      |j                  d      |d<   |$|d   |k7  r|j                  d|d    d|        d}|S )NFDomainEndpointOptionsdomain_endpoint_optionsenforce_httpsEnforceHTTPStls_security_policyTLSSecurityPolicycustom_endpoint_enabledCustomEndpointEnabledcustom_endpointCustomEndpointcustom_endpoint_certificate_arnCustomEndpointCertificateArnz#DomainEndpointOptions changed from r2   Trn   )r(   r\   r]   r^   r   domain_endpoint_configdomain_endpoint_optss          r+   set_domain_endpoint_optionsr     s`   G23JK!==,,-FG#0<1E1I1I/1Z~. 56B6J6N6NOd6e23 9:F:N:R:RSl:m6756##$56B7K7O7OPa7b"#34##$EFREYE]E]1F"#AB (-BCZ-[_u-u12GH_2`1a b&')	
 Nrb   c                    d}|d   }| j                   j                  d      }||S |j                  d      }|j                  d      |j                  d      |d<   |d   dk7  rddi|d<   n|g |d	<   |D ]  }i }	|j                  d
      }
|
0t        |
t        j                        r|
j	                  d      }
|
|	d<   |j                  d      }|Ui |	d<   |j                  d      |j                  d      |	d   d<   |j                  d      |j                  d      |	d   d<   |j                  d      |j                  d      |	d<   |d	   j                  |	        |`|d   d   |d   k7  r"|j                  d|d   d    d|d           d}|d	   |d   d	   k7  r"|j                  d|d   d	    d|d	           d}|S )NFAutoTuneOptionsauto_tune_optionsmaintenance_schedulesdesired_stateDesiredStateENABLEDDISABLEDMaintenanceSchedulesstart_atz%Y-%m-%dStartAtdurationDurationvalueValueunitUnitcron_expression_for_recurrenceCronExpressionForRecurrencez*AutoTuneOptions.DesiredState changed from r2   Tz2AutoTuneOptions.MaintenanceSchedules changed from )r   r   r   datetimestrftimer[   )r(   r\   r]   r^   r   auto_tune_configauto_tune_opts	schedulessschedule_entryr   duration_opts               r+   set_auto_tune_optionsr     sd   G,->?]]&&':;N""#:;I/*6+9+=+=o+N('94J4
/0 
	35/0 	LANuuZ(H#h(9(9:'00<H,4y)55,L'-/z*##G,8:F:J:J7:SN:.w7##F+79E9I9I&9QN:.v6uu56B@AFf@g<=34;;NK#	L$ ( !23NCGWXfGgg)*;<^LMTRbcqRrQsu G237LM^7_`v7ww)*;<=STU V$%;<=?
 GNrb   c                 v   d }d}| j                   j                  d      }||S 	 t        j                  |      }|Dt        j                  |d         }t        ||      s|j                  d| d|        d}||d<   |S ||d<   |S # t        $ r(}| j                  dt        |              Y d }~yd }~ww xY w)	NFaccess_policiesz.Failed to convert the policy into valid JSON: r   AccessPolicieszAccessPolicy changed from r2   T)
r   r   jsondumps	Exceptionr4   strloadsr   r[   )	r(   r\   r]   r^   access_policy_configr   access_policy_optr*   current_access_policys	            r+   set_access_policyr    s    G))*;< X#zz*;< ( $

+@AQ+R S 57HI :;P:QQUVgUhijG6J!"23 N 3G./N  XMcRSfXVWWXs   B 	B8B33B8c                    |j                   j                  d      }|j                   j                  d      dddddddddiddiddid	d
iddiddiddiddid}t        | ||      \  }}|t        |      }|j                   j                  d      Ut	        |j                   j                  d            }||j                  d       |j                   j                  d      |d<   d}g }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t        ||||      z  }|t!        ||||      z  }|||d   |d   k7  r'd}|j#                  d       t%        | ||d   |d          |r|j&                  r|j)                  dd|        |j+                  dd        	  | j,                  d%i | nj|j                   j                  d      |j                  d       d}|j&                  r|j)                  dd       	  | j8                  d%i |}
|
d   }|d   }	 t;        | j=                  |d      d         }|j                   d    }|j                   d!   }|t?        | ||||      z  }|j                   j                  d"      r|j&                  stA        | ||d#       tC        | ||      }tE        d%d$|itG        | ||      S # t.        j0                  j2                  t.        j0                  j4                  f$ r }	|j7                  |	d|        Y d }	~	d }	~	ww xY w# t.        j0                  j2                  t.        j0                  j4                  f$ r!}	|j7                  |	d|        Y d }	~	Xd }	~	ww xY w# t.        j0                  j4                  t.        j0                  j2                  f$ r }	|j7                  |	d|        Y d }	~	d }	~	ww xY w)&Nr   zOpenSearch_1.1zt2.small.search   F)rA   rC   rE   rJ   rP   rg   rY   r   r   r   r   r   )r   rV   r>   rd   rs   r{   r   r   r   r   r   engine_versionzCInvalid engine_version. Must be Elasticsearch_X.Y or OpenSearch_X.YrV   TzEngineVersion changedz0Would have updated domain if not in check mode: r   zCouldn't update domain r   r   z>state is present but the following is missing: access_policiesz0Would have created a domain if not in check modeDomainStatusARN)r	  	aws_retryTagListzCouldn't get tags for domain tags
purge_tagsr   r1   r   r3   )$r   r   r   r   r   r4   ra   rq   ry   r   r   r   r   r   r   r   r  r[   r5   r   r   rZ   update_domain_configr"   r#   r%   r$   r&   create_domainr   	list_tagsr   r   r   r!   r   )r'   r(   r   r]   r\   
domain_arnr;   r   r^   r*   responser)   existing_tagsdesired_tagsr  s                  r+   ensure_domain_presentr    s   --##M2K
 mm''6)-$)&+ 
 %
 u$
 u(
 )!
 u
 u$
 $U"
 J
G&R +<FFK*X'J( ()> ?}})*6&--++,<=>9bc171B1BCS1To.GJ!&*?AVXbccGv'<>SU_``G-f6KMbdnooG26;PRgisttGv'<>SU_``G#F,ACXZdeeG"6+@BWYcddG,V5JLacmnnG*63HJ_akllG$V-BDY[effG )>@UWabbG( 15J?5[[G56%o6%o6	      J:,W ! 
 "%%ot<U+++D.CD ==./7]^T/ab	Q+v++D.CDHn-FJO6v7G7GJbf7G7ghq7rs ==(L|,J{66:}lT^__G}} ):):vv{<NOvv{;FPP#7#OPPK ##11##// U $$Q.Ek],S$TT	U& --++
 	Q   *A+(O PP		Q ++X-@-@-N-NO OQ"?} MNNOsH   L8 1N O- 87N/N

N7O*	O%%O*-7Q$P??Qc            !      	   t        t        dCi dt        ddgd      dt        d      dt               d	t        d
dd      dt        d
d      dt        dd t        t               t        d
d      t        d
d      t        d
d      t        d
d      t               t        d      t        d
d      t        d
      t        d
d      t        dd t        t        d
d                              dt        dd t        t        d
d                  dt        dd t        t        d
d      t        d
      t        d
d      t        d
d                  dt        dd t        t        ddd
      t        ddd
                  dt        dd t        t        d
d      t        d
      t        d
      t        d
d
       !            d"t        dd t        t        d      t        d
      #            d$t        dd t        t        d                  d%t        dd t        t        d      t               t        d      t               t               &            d't        dd t        t        d      t        d      t        dd t        t               t               t        d(      )            t        dd t        t        d      t        dd t        t               t               *            t               t               t        d
(      t        d
(      t        d      +            ,            d-t        dd t        t        d.d/g0      t        ddd t        t               t        dd t        t        d      t        d1g0      2            t               3      4      5            d6t        dd7g8      d9t        dd:      d;t        dd
:      d<t        dd=:      d>      } 	 | j                  d?t        j                         @      }| j                  d   dk(  rt        |       }nt        |       } | j                  dCi | y # t
        j                  j                  t
        j                  j                  f$ r}| j                  |dAB       Y d }~d }~ww xY w)DNstatepresentabsent)choicesdefaultr   T)requiredr  r.   Fbool)r  typer  r   r!   )r  r  r?   int)r  )rW   )r  r  options)r@   rB   rD   rF   rI   rK   rM   rO   rQ   rS   rU   r   )r   re   )rf   rh   rj   rl   r   listr   )r  elementsr  )r   r   r   )r  no_log)rW   user_pool_ididentity_pool_idrole_arnrt   )rW   ru   r|   r   )r   r   r   r   r   r   )r#  )r   r   r   )r   r   )rW   r   r   r   r   r   r   )rW   r   r   r   r   r   r   )r  HOURS)r   r   )r   r   r   )r  r"  r  r   )r   r   r  resource_tags)r  aliasesr  )r  r  r   wait_timeouti,  )argument_specsupports_check_mode
opensearch)retry_decoratorz+Failed to connect to AWS opensearch servicer   r3   )AnsibleAWSModuler!   r'   r   jittered_backoffr"   r#   r$   r%   r&   r   r,   r  r   )r(   r'   r*   ret_dicts       r+   mainr2    s    [
	84iH[
d+[
  6[
 )-e&RV(W	[

 !%f=[
  "&&#'U#C#'V#D,0%e,L%)5v%F37648e4D!%u6!B"E2#U?)-# $ $$(%f$E!*[
: "26E2R;[
H  $e& A $e 4 $e% @u59		I[
\  fuuM$(fuu$U][
l ! %f=!%u!5%)5%9!5?		m[
@ (, f-#U3(A[
P -1 f--Q[
^ %)"&F"3(,,0f,=$(F48F
%_[
t '+ f-37V3D(,# $ $,0F-1V15T1B!) "&# $ $$(f$5 $%+(,(,59V.2f)"! .2V04(,E(:&*%&848e4D!" $'u[
~ #"&	:/F"G*.#!' $ $%)V%)%+(,(,*.E*:)-wi)@)"& <@6!	+[
n 6O+<=o[
p 6q[
r 651s[
t 5#6u[
x !{^F@S|X=V=V=XY }}W)'7(8F x  ++X-@-@-N-NO SQ$QRRSs   %Q6 67S
-SS
__main__)/DOCUMENTATIONRETURNEXAMPLESr   r   copyr   r"   ImportErroransible.module_utils.sixr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   :ansible_collections.amazon.aws.plugins.module_utils.policyr   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   >ansible_collections.community.aws.plugins.module_utils.modulesr	   r/  Aansible_collections.community.aws.plugins.module_utils.opensearchr
   r   r   r   r   r   r   r   r,   r5   ra   rq   ry   r   r   r   r   r   r   r   r  r  r2  __name__r3   rb   r+   <module>rA     s   BH 
Tl   	 2 \ W P f x e Y _ _ j b [ d <F9Px;|68*@F4>B:/d.CQLk!\ zF I  		s   B) )B10B1