
    Vh&                         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
 Zd Zd ZddZd Zedk(  r e        yy# e$ r Y Cw xY w)aH  
---
module: eks_cluster
version_added: 1.0.0
short_description: Manage Elastic Kubernetes Service (EKS) Clusters
description:
  - Manage Elastic Kubernetes Service (EKS) Clusters.
  - Prior to release 5.0.0 this module was called C(community.aws.aws_eks_cluster).
    The usage did not change.
author:
  - Will Thames (@willthames)
options:
  name:
    description: Name of the EKS cluster.
    required: True
    type: str
  version:
    description:
      - Kubernetes version.
      - Defaults to C(latest).
    type: str
  role_arn:
    description: ARN of IAM role used by the EKS cluster.
    type: str
  subnets:
    description: List of subnet IDs for the Kubernetes cluster.
    type: list
    elements: str
  security_groups:
    description: List of security group names or IDs.
    type: list
    elements: str
  state:
    description: Desired state of the EKS cluster.
    choices:
      - absent
      - present
    default: present
    type: str
  tags:
    description:
      - A dictionary of tags to add the EKS cluster.
    type: dict
    version_added: 5.3.0
  wait:
    description: >-
      Specifies whether the module waits until the cluster is active or deleted
      before moving on. It takes "usually less than 10 minutes" per AWS documentation.
    type: bool
    default: false
  wait_timeout:
    description: >-
      The duration in seconds to wait for the cluster to become active. Defaults
      to 1200 seconds (20 minutes).
    default: 1200
    type: int
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
a  
# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: Create an EKS cluster
  community.aws.eks_cluster:
    name: my_cluster
    version: 1.14
    role_arn: my_eks_role
    subnets:
      - subnet-aaaa1111
    security_groups:
      - my_eks_sg
      - sg-abcd1234
  register: caller_facts

- name: Remove an EKS cluster
  community.aws.eks_cluster:
    name: my_cluster
    wait: true
    state: absent
a  
arn:
  description: ARN of the EKS cluster
  returned: when state is present
  type: str
  sample: arn:aws:eks:us-west-2:123456789012:cluster/my-eks-cluster
certificate_authority:
  description: Dictionary containing Certificate Authority Data for cluster
  returned: after creation
  type: complex
  contains:
    data:
      description: Base-64 encoded Certificate Authority Data for cluster
      returned: when the cluster has been created and is active
      type: str
endpoint:
  description: Kubernetes API server endpoint
  returned: when the cluster has been created and is active
  type: str
  sample: https://API_SERVER_ENDPOINT.yl4.us-west-2.eks.amazonaws.com
created_at:
  description: Cluster creation date and time
  returned: when state is present
  type: str
  sample: '2018-06-06T11:56:56.242000+00:00'
name:
  description: EKS cluster name
  returned: when state is present
  type: str
  sample: my-eks-cluster
resources_vpc_config:
  description: VPC configuration of the cluster
  returned: when state is present
  type: complex
  contains:
    security_group_ids:
      description: List of security group IDs
      returned: always
      type: list
      sample:
      - sg-abcd1234
      - sg-aaaa1111
    subnet_ids:
      description: List of subnet IDs
      returned: always
      type: list
      sample:
      - subnet-abcdef12
      - subnet-345678ab
      - subnet-cdef1234
    vpc_id:
      description: VPC id
      returned: always
      type: str
      sample: vpc-a1b2c3d4
role_arn:
  description: ARN of the IAM role used by the cluster
  returned: when state is present
  type: str
  sample: arn:aws:iam::123456789012:role/eks_cluster_role
status:
  description: status of the EKS cluster
  returned: when state is present
  type: str
  sample:
  - CREATING
  - ACTIVE
version:
  description: Kubernetes version of the cluster
  returned: when state is present
  type: str
  sample: '1.10'
    N)camel_dict_to_snake_dict)is_boto3_error_code)%get_ec2_security_group_ids_from_names)
get_waiter)AnsibleCommunityAWSModulec                    |j                   j                  d      }|j                   d   }|j                   d   }|j                   j                  d      }t        | |      }	 |j                  d      }|j	                  |d   g      d   d   d	   }t        |||      }|rt        |d   d         t        |      k7  r|j                  d       t        |d   d         t        |      k7  r|j                  d       |j                   j                  d      r3|j                   j                  d      |d   k7  r|j                  d       |rt        | |d       t        | |      } |j                  d ddit        |       |j                   r|j                  d       	 t#        ||j                   d   t#        ||            }
|j                   d   r|j                   d   |
d<   |j                   d   r|j                   d   |
d<    | j$                  d i |
d   }|rt        | |d       t        | |      } |j                  d ddit        |       y # t        j                  j                  t        j                  j                  f$ r}	|j                  |	d
       Y d }	~	d }	~	ww xY w# t        j                  j&                  $ r- |j                  d| j(                  j*                   d       Y t        j                  j                  t        j                  j                  f$ r!}	|j                  |	d|        Y d }	~	,d }	~	ww xY w)!Nnamesubnetssecurity_groupswaitec2r   )	SubnetIdsSubnetsVpcIdzCouldn't lookup security groupsmsgresourcesVpcConfig	subnetIdsz)Cannot modify subnets of existing clustersecurityGroupIdsz1Cannot modify security groups of existing clusterversionz)Cannot modify version of existing clustercluster_activechangedFTr   role_arn)r   r   )r	   roleArnr   tagsclusterRegion  is not supported by EKSzCouldn't create cluster  )paramsgetget_clusterclientdescribe_subnetsr   botocore
exceptionsBotoCoreErrorClientErrorfail_json_awsset	fail_json
wait_until	exit_jsonr   
check_modedictcreate_clusterEndpointConnectionErrormetaregion_name)r$   moduler	   r
   groupsr   r   r   vpc_ider!   s              m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/eks_cluster.pyensure_presentr:      s(   ==V$DmmI&G]],-F==V$D&&)GGmmE"%%%=iHKGT6vsFK w+,[9:c'lJ!LMw+,-?@AS[P!TU==Y'FMM,=,=i,HGT]L^,^!LMvv'78 "&&1GLL*B7*KL&GMM*-#gO

 ==# &i 8F9== #]]62F6N'&''1&1)< 66#34 ff-FGTG%=g%FGW --x/B/B/N/NO GQ$EFFG@ 66 Zwv{{'>'>&??WXY--x/B/B/N/NO GQ&>tf$EFFGs8   "=I $A=J2 7J/J**J/2AM;6M1MMc                    |j                   j                  d      }t        | |      }|j                   j                  d      }|s|j                  d       |j                  s 	 | j                  |j                   d          |rt        | |d
       |j                  d       y # t        j                  j                  $ r- |j                  d| j                  j                   d       Y kt        j                  j                  t        j                  j                  f$ r }|j                  |d	|        Y d }~d }~ww xY w)Nr	   r   Fr   r	   r   r   r   zCouldn't delete cluster cluster_deletedT)r!   r"   r#   r.   r/   delete_clusterr&   r'   r2   r,   r3   r4   r(   r)   r*   r-   )r$   r5   r	   existingr   r8   s         r9   ensure_absentr@      s    ==V$D66*H==V$D'	K!!v}}V'<!= 66#45
T" "":: 	^76;;+B+B*CC[!\]##1183F3F3R3RS 	K  *B4&(I JJ	Ks   $B% %AE.6E$D??Ec                    |j                   j                  d      }	 | j                  |      d   S # t        d      $ r Y y t        j
                  j                  $ r- |j                  d| j                  j                   d       Y y t        j
                  j                  t        j
                  j                  f$ r }|j                  |d|        Y d }~y d }~ww xY w)	Nr	   r<   r   ResourceNotFoundExceptionr   r   r   zCouldn't get cluster )r!   r"   describe_clusterr   r&   r'   r2   r,   r3   r4   r(   r)   r*   )r$   r5   r	   r8   s       r9   r#   r#      s    ==V$D
D&&D&1)<<:; 66 Zwv{{'>'>&??WXY))'' D 	Q&;D6$BCC	Ds"   2 C AC 
6C  CC c                     |j                   j                  d      }|j                   j                  d      }t        | |      }dt        ||j                  j
                  z        z   }|j                  |d|i       y )Nr	   wait_timeout   MaxAttempts)r	   WaiterConfig)r!   r"   r   intconfigdelayr   )r$   r5   waiter_namer	   rE   waiterattemptss          r9   r-   r-     si    ==V$D==$$^4L,F3|fmm&9&99::H
KKT(AKB    c                     t        t        d      t               t               t        dd      t        dd      t        ddgd      t        d	d
      t        d
d      t        dd      	      } t        | ddg dggd      }|j                  d      }|j                  j	                  d      dk(  rt        ||       y t        ||       y )NT)requiredliststr)typeelementsabsentpresent)choicesdefaultr0   F)rT   rQ   bool)rY   rT   i  rI   )	r	   r   r   r
   r   stater   r   rE   r[   )r   r
   r   )argument_specrequired_ifsupports_check_modeeks)r0   AnsibleAWSModuler$   r!   r"   r:   r@   )r\   r5   r$   s      r9   mainra     s    4 &51&59Hi0)Dv.%f-$U3
M #y*TUV F ]]5!F}}!Y.vv&ff%rO   __main__)r   )DOCUMENTATIONEXAMPLESRETURNr&   ImportError0ansible.module_utils.common.dict_transformationsr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   7ansible_collections.amazon.aws.plugins.module_utils.ec2r   ;ansible_collections.amazon.aws.plugins.module_utils.waitersr   >ansible_collections.community.aws.plugins.module_utils.modulesr   r`   r:   r@   r#   r-   ra   __name__r    rO   r9   <module>rm      s}   <|,H
T	 V \ i R x5Hp#(DC&6 zF W  		s   A AA