
    VhF                     @   d Z dZdZddlZddl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  ej.                         d        ZddZd Zd Zd Zd Zd ZddZd Z d Z!ddZ"d Z#e$dk(  r e#        yy# e
$ r Y zw xY w)a  
---
module: cloudformation
version_added: 1.0.0
short_description: Create or delete an AWS CloudFormation stack
description:
  - Launches or updates an AWS CloudFormation stack and waits for it complete.
options:
  stack_name:
    description:
      - Name of the CloudFormation stack.
    required: true
    type: str
  disable_rollback:
    description:
      - If a stacks fails to form, rollback will remove the stack.
    default: false
    type: bool
  on_create_failure:
    description:
      - Action to take upon failure of stack creation. Incompatible with the O(disable_rollback) option.
    choices:
      - DO_NOTHING
      - ROLLBACK
      - DELETE
    type: str
  create_timeout:
    description:
      - The amount of time (in minutes) that can pass before the stack status becomes V(CREATE_FAILED).
    type: int
  template_parameters:
    description:
      - A list of hashes of all the template variables for the stack. The value can be a string or a dict.
      - Dict can be used to set additional template parameter attributes like UsePreviousValue (see example).
    default: {}
    type: dict
  state:
    description:
      - If O(state=present), stack will be created.
      - If O(state=present) and if stack exists and template has changed, it will be updated.
      - If O(state=absent), stack will be removed.
    default: present
    choices: [ present, absent ]
    type: str
  template:
    description:
      - The local path of the CloudFormation template.
      - This must be the full path to the file, relative to the working directory. If using roles this may look
        like V(roles/cloudformation/files/cloudformation-example.json).
      - If O(state=present) and the stack does not exist yet, either O(template), O(template_body) or O(template_url)
        must be specified (but only one of them).
      - If O(state=present), the stack does exist, and neither O(template),
        O(template_body) nor O(template_url) are specified, the previous template will be reused.
      - The O(template) parameter has been deprecated and will be remove in a release after
        2026-05-01. It is recommended to use O(template_body) with the P(ansible.builtin.template#lookup) lookup plugin.
    type: path
  notification_arns:
    description:
      - A comma separated list of Simple Notification Service (SNS) topic ARNs to publish stack related events.
    type: str
  stack_policy:
    description:
      - The path of the file containing the CloudFormation stack policy. A policy cannot be removed once placed, but it can be modified.
        for instance, allow all updates U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html#d0e9051)
    type: str
  stack_policy_body:
    description:
      - The CloudFormation stack policy in JSON. A policy cannot be removed once placed, but it can be modified.
        for instance, allow all updates U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html#d0e9051)
    type: json
    version_added: 1.5.0
  stack_policy_on_update_body:
    description:
      - The body of the cloudformation stack policy only applied during this update.
    type: json
    version_added: 1.5.0
  tags:
    description:
      - Dictionary of tags to associate with stack and its resources during stack creation.
      - Can be updated later, updating tags removes previous entries.
    type: dict
  template_url:
    description:
      - Location of file containing the template body. The URL must point to a template (max size 307,200 bytes) located in an
        S3 bucket in the same region as the stack.
      - If O(state=present) and the stack does not exist yet, either O(template), O(template_body) or O(template_url)
        must be specified (but only one of them).
      - If O(state=present), the stack does exist, and neither O(template), O(template_body) nor O(template_url) are specified,
        the previous template will be reused.
    type: str
  create_changeset:
    description:
      - If stack already exists create a changeset instead of directly applying changes.  See the AWS Change Sets docs
        U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html).
      - B(WARNING:) if the stack does not exist, it will be created without changeset. If O(state=absent), the stack will be
        deleted immediately with no changeset.
    type: bool
    default: false
  changeset_name:
    description:
      - Name given to the changeset when creating a changeset.
      - Only used when O(create_changeset=true).
      - By default a name prefixed with Ansible-STACKNAME is generated based on input parameters.
        See the AWS Change Sets docs for more information
        U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html)
    type: str
  role_arn:
    description:
      - The role that AWS CloudFormation assumes to create the stack. See the AWS CloudFormation Service Role
        docs U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html)
    type: str
  termination_protection:
    description:
      - Enable or disable termination protection on the stack.
    type: bool
  template_body:
    description:
      - Template body. Use this to pass in the actual body of the CloudFormation template.
      - If O(state=present) and the stack does not exist yet, either O(template), O(template_body) or O(template_url)
        must be specified (but only one of them).
      - If O(state=present), the stack does exist, and neither O(template), O(template_body) nor O(template_url)
        are specified, the previous template will be reused.
    type: str
  events_limit:
    description:
      - Maximum number of CloudFormation events to fetch from a stack when creating or updating it.
    default: 200
    type: int
  backoff_delay:
    description:
      - Number of seconds to wait for the next retry.
    default: 3
    type: int
    required: False
  backoff_max_delay:
    description:
      - Maximum amount of time to wait between retries.
    default: 30
    type: int
    required: False
  backoff_retries:
    description:
      - Number of times to retry operation.
      - AWS API throttling mechanism fails CloudFormation module so we have to retry a couple of times.
    default: 10
    type: int
    required: False
  capabilities:
    description:
      - Specify capabilities that stack template contains.
      - Valid values are V(CAPABILITY_IAM), V(CAPABILITY_NAMED_IAM) and V(CAPABILITY_AUTO_EXPAND).
    type: list
    elements: str
    default: [ CAPABILITY_IAM, CAPABILITY_NAMED_IAM ]

author:
  - "James S. Martin (@jsmartin)"
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
a  
- name: create a cloudformation stack
  amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation"
    state: "present"
    region: "us-east-1"
    disable_rollback: true
    # The template parameter has been deprecated, use template_body with lookup instead.
    # template: "files/cloudformation-example.json"
    template_body: "{{ lookup('file', 'cloudformation-example.json') }}"
    template_parameters:
      KeyName: "jmartin"
      DiskType: "ephemeral"
      InstanceType: "m1.small"
      ClusterSize: 3
    tags:
      Stack: "ansible-cloudformation"

# Basic role example
- name: create a stack, specify role that cloudformation assumes
  amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation"
    state: "present"
    region: "us-east-1"
    disable_rollback: true
    # The template parameter has been deprecated, use template_body with lookup instead.
    # template: "roles/cloudformation/files/cloudformation-example.json"
    template_body: "{{ lookup('file', 'cloudformation-example.json') }}"
    role_arn: 'arn:aws:iam::123456789012:role/cloudformation-iam-role'

- name: delete a stack
  amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation-old"
    state: "absent"

# Create a stack, pass in template from a URL, disable rollback if stack creation fails,
# pass in some parameters to the template, provide tags for resources created
- name: create a stack, pass in the template via an URL
  amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation"
    state: present
    region: us-east-1
    disable_rollback: true
    template_url: https://s3.amazonaws.com/my-bucket/cloudformation.template
    template_parameters:
      KeyName: jmartin
      DiskType: ephemeral
      InstanceType: m1.small
      ClusterSize: 3
    tags:
      Stack: ansible-cloudformation

# Create a stack, passing in template body using lookup of Jinja2 template, disable rollback if stack creation fails,
# pass in some parameters to the template, provide tags for resources created
- name: create a stack, pass in the template body via lookup template
  amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation"
    state: present
    region: us-east-1
    disable_rollback: true
    template_body: "{{ lookup('template', 'cloudformation.j2') }}"
    template_parameters:
      KeyName: jmartin
      DiskType: ephemeral
      InstanceType: m1.small
      ClusterSize: 3
    tags:
      Stack: ansible-cloudformation

# Pass a template parameter which uses CloudFormation's UsePreviousValue attribute
# When use_previous_value is set to True, the given value will be ignored and
# CloudFormation will use the value from a previously submitted template.
# If use_previous_value is set to False (default) the given value is used.
- amazon.aws.cloudformation:
    stack_name: "ansible-cloudformation"
    state: "present"
    region: "us-east-1"
    template: "files/cloudformation-example.json"
    template_parameters:
      DBSnapshotIdentifier:
        use_previous_value: true
        value: arn:aws:rds:es-east-1:123456789012:snapshot:rds:my-db-snapshot
      DBName:
        use_previous_value: true
    tags:
      Stack: "ansible-cloudformation"

# Enable termination protection on a stack.
# If the stack already exists, this will update its termination protection
- name: enable termination protection during stack creation
  amazon.aws.cloudformation:
    stack_name: my_stack
    state: present
    template_url: https://s3.amazonaws.com/my-bucket/cloudformation.template
    termination_protection: true

# Configure TimeoutInMinutes before the stack status becomes CREATE_FAILED
# In this case, if disable_rollback is not set or is set to false, the stack will be rolled back.
- name: enable termination protection during stack creation
  amazon.aws.cloudformation:
    stack_name: my_stack
    state: present
    template_url: https://s3.amazonaws.com/my-bucket/cloudformation.template
    create_timeout: 5

# Configure rollback behaviour on the unsuccessful creation of a stack allowing
# CloudFormation to clean up, or do nothing in the event of an unsuccessful
# deployment
# In this case, if on_create_failure is set to "DELETE", it will clean up the stack if
# it fails to create
- name: create stack which will delete on creation failure
  amazon.aws.cloudformation:
    stack_name: my_stack
    state: present
    template_url: https://s3.amazonaws.com/my-bucket/cloudformation.template
    on_create_failure: DELETE
aC  
events:
  description: Most recent events in CloudFormation's event log. This may be from a previous run in some cases.
  returned: always
  type: list
  sample: [
        "StackEvent AWS::CloudFormation::Stack stackname UPDATE_COMPLETE",
        "StackEvent AWS::CloudFormation::Stack stackname UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"
    ]
log:
  description: Debugging logs. Useful when modifying or finding an error.
  returned: always
  type: list
  elements: str
  sample: ["updating stack"]
change_set_id:
  description: The ID of the stack change set when created.
  returned:  when O(state=present) and O(create_changeset=true).
  type: str
  sample: "arn:aws:cloudformation:us-east-1:123456789012:changeSet/Ansible-StackName-f4496805bd1b2be824d1e315c6884247ede41eb0"
stack_resources:
  description: AWS stack resources and their status. List of dictionaries, one dict per resource.
  returned: when O(state=present)
  type: list
  elements: dict
  sample: [
          {
              "last_updated_time": "2016-10-11T19:40:14.979000+00:00",
              "logical_resource_id": "CFTestSg",
              "physical_resource_id": "cloudformation2-CFTestSg-16UQ4CYQ57O9F",
              "resource_type": "AWS::EC2::SecurityGroup",
              "status": "UPDATE_COMPLETE",
              "status_reason": null
          }
      ]
stack_outputs:
  description: A key:value dictionary of all the stack outputs currently defined. If there are no stack outputs, it is an empty dictionary.
  returned: When O(state=present)
  type: dict
  sample: {"MySg": "AnsibleModuleTestYAML-CFTestSg-C8UVS567B6NS"}
    N)sha1)to_bytes)	to_native)boto_exception)is_boto3_error_message)AnsibleAWSModule)AWSRetry)ansible_dict_to_boto3_tag_listc                     | j                  d      j                  |d|i      }|t        |j                  d            S t        |j                  d| d            S )Ndescribe_stack_eventsMaxItems)	StackNamePaginationConfigzStackEvents[*]z$StackEvents[?ClientRequestToken == 'z'])get_paginatorpaginatelistsearch)cfn
stack_nameevents_limittoken_filterpgs        m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/amazon/aws/plugins/modules/cloudformation.py_search_eventsr   _  si    			2	3	<	<$l3 
= 
B BII./00		@bQRSS    c           	      <   g g d}	 t        | |||      }|D ]l  }d|d    d	|d
    d	|d    }	|d   j                  |	       |d   j                  d      s@|d    d	|d
    d	|d    d|d    }
|d   j                  |
       n |S # t        d      $ r |d   j                  d       |cY S t        j                  j
                  t        j                  j                  f$ r7}t        |      }|d   j                  dt        |      z          |cY d}~S d}~ww xY w)z_This event data was never correct, it worked as a side effect. So the v2.3 format is different.)eventslogdoes not existr   zStack does not exist.zUnknown error: NzStackEvent ResourceType LogicalResourceIdResourceStatusr   FAILEDz: ResourceStatusReason)
r   r   appendbotocore
exceptionsValidationErrorClientErrorr   strendswith)r   r   r   r   retr   err	error_msge	eventlinefailures              r   get_stack_eventsr3   k  s[   
#CZ|L  '!!N"3!4Aa8K6L5MQqQaObNcd	HY'''1>*+1Q/B-C,DAaHXFYEZZ\]^_u]v\wxGJg&' J' ""23 E
12
++''  #3'	E
+c)n<=
s#   B $D.6D$,DDDc                    d|vrd|vr| j                  d       | j                  j                  d      | j                  d   |d<   n| j                  d   |d<   | j                  j                  d	      | j                  d	   |d
<   | j                  j                  d      't        | j                  j                  d            |d<   	  |j                  dddi|}t        | ||d   d||j                  dd             }s| j                  d       |S # t        j                  j                  t        j                  j                  f$ r/}| j                  |d|j                  d              Y d }~wd }~ww xY w)NTemplateBodyTemplateURLz_Either 'template', 'template_body' or 'template_url' is required when the stack does not exist.msgon_create_failure	OnFailuredisable_rollbackDisableRollbackcreate_timeoutTimeoutInMinutestermination_protectionEnableTerminationProtection	aws_retryTStackIdCREATEClientRequestTokenzFailed to create stack r   empty result )	fail_jsonparamsgetboolcreate_stackstack_operationr'   r(   BotoCoreErrorr*   fail_json_aws)modulestack_paramsr   r   responseresultr.   s          r   rK   rK     s   \)m<.Oq 	 	
 }},-9$*MM2E$F[!*0--8J*K&'}})*6+1==9I+J'(}}12>6:6==;L;LMe;f6g23a#3##CdClC C),hlFVFVWkmqFr

 ^,M	 --x/B/B/N/NO aS(?@P@PQ\@]?^&_``as   7D 7E>%E99E>c                 ^    | j                  d|      }|d   D cg c]  }|d   	 c}S c c}w )NTrA   r   	SummariesChangeSetName)list_change_sets)r   r   rescss       r   list_changesetsrZ     s5    




DC*-k*:;BB;;;s   *c                    d|vrd|vr| j                  d       | j                  d   | j                  d   |d<   |j                  dd        	 t        |      }||d<   t	        ||d         }||v r$d	t        |       d
}t        dd| d|g      }n |j                  d)ddi|}t        j                         dz   }	t        j                         |	k  r	 |j                  d|d         }

d   dk(  s|
d   dk(  rt        j                  d       n<|
d   dk(  r3d|
d   v sd|
d   v r%|j                  d|d          t        dd      }|S n-t        j                  d       t        j                         |	k  rt!        | ||d   d|      }|d   |d<   d | d!|d    d"|d    d#g|d$<   s| j                  d(       |S # t        j                  j                  $ r}| j                  |       Y d }~
d }~ww xY w# t#        d%      $ r t        dd&      }Y ot        j                  j                  t        j                  j$                  f$ r}| j                  |d'       Y d }~d }~ww xY w)*Nr5   r6   z0Either 'template' or 'template_url' is required.r7   changeset_namerV   rD   r   z	WARNING: z. pending changeset(s) exist(s) for this stack!Fz
ChangeSet z already exists.)changedoutputwarningsrA   TiX  IdrA   rV   StatusCREATE_PENDINGCREATE_IN_PROGRESS   r$   z0The submitted information didn't contain changesStatusReasonNo updates are to be performedzQThe created Change Set did not contain any changes to this stack and was deleted.r]   r^   CREATE_CHANGESETchange_set_idzCreated changeset named z for stack zRYou can execute it using: aws cloudformation execute-change-set --change-set-name zGNOTE that dependencies on this stack might fail due to pending changes!r_   No updates are to be performed.Stack is already up-to-date.zFailed to create change setrE   rF   )rG   rH   popbuild_changeset_namerZ   lendictcreate_change_settimedescribe_change_setr'   r(   rM   rN   sleepdelete_change_setrL   r   r*   )rO   rP   r   r   r\   pending_changesetswarningrR   rY   time_endnewcsr.   s               r   create_changesetrz     s   \)m<.OOP}}%&2(.6F(G_% )40.E-l;(6_% -S,{2KL//!#&8"9!::hiG%*^<LL\0]iphqrF&&&FFFByy{S(H))+(.33dRTUYRZ3[E ?&66%/Ma:aJJqM8_0F%P^J__75;PP))D4)Q! %rF "M

1- ))+(. %VS,{2KM_amnF&(hF?#*>*:+lS^F_E`adeghlemdnoY"F: ^,ME  **88 .((--.6 ""CD Le,JK--x/B/B/N/NO ES&CDDEsV   B	H G /A H -H >1H G>"G93H 9G>>H I16I1I,,I1c                 (   d|vr	d|vrd|d<   | j                   d   | j                   d   |d<   | j                   d   |d<   	  |j                  dd	di| t        | ||d
   d||j                  dd             }s| j                  d       |S # t	        d      $ r t        dd      }Y 3t        j                  j                  t        j                  j                  f$ r/}| j                  |d|j                  d
              Y d }~d }~ww xY w)Nr5   r6   TUsePreviousTemplatestack_policy_on_update_bodyStackPolicyDuringUpdateBodyr;   r<   rA   r   UPDATErD   rk   Frl   rh   zFailed to update stack r7   rE   rF   )rH   update_stackrL   rI   r   rp   r'   r(   rM   r*   rN   rG   )rO   rP   r   r   rR   r.   s         r   r   r     s2   \)m<.O.2*+}}23?6<mmDa6b23&,mm4F&GL"#
a848<8 Ck2HlLL\L\]qswLx
 ^,M ""CD Le,JK--x/B/B/N/NO aS(?@P@PQ\@]?^&_``as   7B D,6D"%DDc                     d}t        | ||      }|r |d   |ur	 |j                  d||       d}|S |S # t        j                  j                  $ r}| j                  |       Y d}~|S d}~ww xY w)z)updates termination protection of a stackFr@   T)rA   r@   r   N)get_stack_factsupdate_termination_protectionr'   r(   r*   rN   )rO   r   r   $desired_termination_protection_stater]   stackr0   s          r   r   r     s    GFC4E./7[[(11"0T( 2 
  N7N &&22 ($$Q''N(s   4 A-A((A-c                    g }	 	 t        | ||d      }|j                  d       t        ||||      }|sDd|v s|dk(  r$t        ||||      }|j                  ddd       |S |j                  d	dd
d       |S |d   j                  d      r |dk7  r|j                  ddd| dd       |S |d   dk(  r|dk(  r|j                  dddd       |S |d   j                  d      r|j                  dd| dd       |S |d   j                  d      r|j                  ddd| dd       |S |d   j                  d      r|j                  ddd| dd       |S t        j                  d       p# t        j                  j                  t        j                  j
                  f$ rK d|v s|dk(  r&t        ||||      }|j                  ddd       |cY S dddt        j                         dcY S w xY w)z>gets the status of a stack while it is created/updated/deletedT)raise_errorsyesDELETEzStack Deletedrh   zStack Not Found)r]   failedr^   	exceptionFStack not found.)r]   r   r^   StackStatusROLLBACK_COMPLETEri   zProblem with z. Rollback completeDELETE_COMPLETErC   z%Stack create failed. Delete complete.	_COMPLETEzStack z	 complete_ROLLBACK_FAILEDz rollback failed_FAILEDz failed   )r   r&   r'   r(   rM   r*   r3   update	traceback
format_excr,   rr   rt   )	rO   r   r   	operationr   op_tokenexistedr   r-   s	            r   rL   rL     s4   G
	#FC$OENN5! sJhG9#8&sJhO

tGH


uHZ[\
 =!**+>?IQcDcJJ44]S\R]]pCqrsJ=!%669;PJJ44CjklJ=!**;7JJ4VI;i3PQRJ=!**+=>JJ44VI;VfCghiJ=!**95JJ44VI;V]C^_`J JJqMa  ##1183F3F3R3RS 	 9#8&sJhO

tGH
  $"/!*!5!5!7	 	s    E4 4A$G6G65G6c                     d| v r| d   S t        j                  | d      }t        t        |d            j	                         }d| d    d| S )	NrV   T)	sort_keyssurrogate_or_strict)errorszAnsible-r   -)jsondumpsr   r   	hexdigest)rP   json_paramschangeset_shas      r   rn   rn   L  sY    ,&O,,**\T:K+6KLMWWYMl;/0-AAr   c                 Z   t        |      |d<   |j                  dd       	  |j                  dddi|}t        d      D ]6  }|j	                  d|d         }|d	   d
v r n/t        j                  d       8 | j                  d|d           |j                  d|d          j                  d      }|d	   dk(  rd|v sd|v rd||dS d||d   dS # t        j                  j                  t        j                  j                  f$ r}| j                  |       Y d}~yd}~ww xY w)zSCreate a change set, describe it and delete it before returning check mode outputs.rV   rD   NrA   T<   r`   ra   rb   )CREATE_COMPLETEr$   r   zFailed to create change set r7   rf   r$   zdidn't contain changesrg   Fr]   r8   metaChangesrF   )rn   rm   rq   rangers   rr   rt   rG   ru   rI   r'   r(   r)   r*   rN   )rO   rP   r   
change_set_idescriptionreasonr.   s           r   check_mode_changesetr   V  sP   $8$FL!)40"*S**JTJ\J
) 	aB11DPZ[_P`1aK8$(EEJJqM		a #?_@]?^!_`Jt<LM0x H,$.2RV\2\$VVDDI8NOO//1D1D1P1PQ "S!!"s   B,C C 7D*D%%D*c                 d   	 |j                  d|      }|d   d   }r'|j                  dd       r|d   }t        |      r|d   }S # t        d      $ r Y y t        j                  j                  t        j                  j
                  f$ r!}|r|| j                  |d       Y d }~d }~ww xY w)NTrT   Stacksr   r   zFailed to describe stackr7   )	describe_stacksr   r'   r(   r)   r*   rN   rI   ro   )rO   r   r   r   stack_response
stack_infor.   stackss           r   r   r   u  s    B,,tz,R#H-a0
 .,,Xt<)v;J ""23 ++'' B IS&@AABs   A B/6B/B**B/c                     t        dii dt        d      dt        ddi       dt        d	d	d
g      dt        d dddd      dt        d d      dt        d d      dt        d dd      dt        d dd      dt        dd      dt        d dg d      dt        d d      d t        d d      d!t        d d      d"t        dd      d#t        d d      d$t        d d      d%t        d d      d&t        d d      d't        d(d      d)t        dd*d+      d,t        dd-d+      d.t        dd/d+      d0t        d1d2d3d4g5      } t        | g d6ddggd7      }g }|j                  j                  d0      }|D ]  }|d8vs|j	                  |        |r|j                  d9|d:;       |t        t        j                               d<}|j                  d   }|j                  d   |d=<   |j                  d   6t        |j                  d   d>      5 }|j                         |d?<   d d d        nC|j                  d!   |j                  d!   |d?<   n!|j                  d    |j                  d    |d@<   |j                  j                  d      r"|j                  d   j                  dA      |dB<   ng |dB<   |j                  d   .|j                  s"|j                  d"   s|j                  d   |dC<   n_|j                  d   P|j                  sD|j                  d"   s5t        |j                  d   d>      5 }|j                         |dC<   d d d        |j                  d   }	g |dD<   |	j                         D ]  \  }
}t        |t               r_t        |
E      }dF|v rt        |dF         |dG<   dH|v r%t!        |dH         rd|dI<   |j#                  dGd        |dD   j	                  |       u|dD   j	                  |
t        |      dJ        t        |j                  j                  d%      t               rt%        |j                  d%         |dK<   |j                  j                  d$      r|j                  d$   |dL<   i }t'        j(                  |j                  j                  d)      |j                  j                  d,      |j                  j                  d.      M      }|j+                  dN|O      }t-        |||d=         }|j                  rq|d
k(  r|r|j/                  ddPg Q       nU|d
k(  r|s|j/                  ddRg Q       n9|d	k(  r|s|j/                  ddSg Q       n |j.                  dii t1        |||       |d	k(  r|s(t3        ||||j                  j                  d'            }nd}|j                  j                  d"      r)t5        ||||j                  j                  d'            }d}|j                  j                  d&      6t7        |||d=   t!        |j                  j                  d&                  |dT<   |s't9        ||||j                  j                  d'            }t-        |||d=         }|O|j                  dU      i |dU<   |j                  dVg       D ]  }|dW   |dU   |dX   <    g }|j;                  d|d=   Y      }|j                  dZg       D ]E  }|j	                  |d[   |j                  d\d]      |d^   |d_   |d`   |j                  da      db       G ||dc<   n|d
k(  r	 t-        |||d=         }|sdddde}n~|j                  dL      |j=                  d|d=   Y       n|j=                  d|d=   |dL   f       t?        |||d=   dg|j                  j                  d'      |j                  dhd             } |j.                  dii | y # 1 sw Y   ~xY w# 1 sw Y   xY w# t@        jB                  jD                  t@        jB                  jF                  f$ r}|jI                  |       Y d }~zd }~ww xY w)jNr   T)requiredtemplate_parametersFrp   )r   typedefaultstatepresentabsent)r   choicestemplatepathz
2026-05-01z
amazon.aws)r   r   r   removed_at_dateremoved_from_collectionnotification_arns)r   r   stack_policystack_policy_bodyr   )r   r   r   r}   r;   rJ   )r   r   r9   )
DO_NOTHINGROLLBACKr   )r   r   r   r=   inttemplate_urltemplate_bodyrz   r\   role_arntagsr?   r      backoff_retries
   )r   r   r   backoff_delay   backoff_max_delay   capabilitiesr   r+   CAPABILITY_IAMCAPABILITY_NAMED_IAM)r   elementsr   )r   r   r   )argument_specmutually_exclusivesupports_check_mode)r   r   CAPABILITY_AUTO_EXPANDz%Specified capabilities are invalid : z3, please check documentation for valid capabilitiesr7   )CapabilitiesrD   r   rr5   r6   ,NotificationARNsStackPolicyBody
Parameters)ParameterKeyvalueParameterValueuse_previous_valueUsePreviousValue)r   r   TagsRoleARN)retriesdelay	max_delaycloudformation)retry_decoratorzStack would be deletedr   zStack doesn't existzNew stack would be createdr]   stack_outputsOutputsOutputValue	OutputKeyrT   StackResourceSummariesr"   PhysicalResourceId r    LastUpdatedTimestampr#   r%   )logical_resource_idphysical_resource_idresource_typelast_updated_timestatusstatus_reasonstack_resourcesr   rh   )rA   r   r   r   rD   rF   )%rp   r   rH   rI   r&   rG   r   uuiduuid4openreadsplit
check_modeitems
isinstancer+   rJ   rm   r
   r	   jittered_backoffclientr   	exit_jsonr   rK   rz   r   r   list_stack_resourcesdelete_stackrL   r'   r(   rM   r*   rN   )r   rO   invalid_capabilitiesuser_capabilitiesuser_caprP   r   template_fhstack_policy_fhr   kvparamrR   r   r   r   changeset_updatedr   r^   r   reslistrX   r.   s                           r   mainr    s	    & %fbI 9y(.CD ($0
	 te< $7 te&I %)F$S e&9  teEij!" Du5#$ $7%& 4%8'( e&9)* D59+, dU3-. $V,/0  $Dv>12 #E234 %eD56 q5A78 E2F9: v@PRh?ij;M@ #IL^`sKtu F )).9% 2__ ''12 78L7O  PC  D 	 	
 *'

5L MM'"E &l ;L}}Z ,&--
+S1 	>[+6+;+;+=L(	> 	>		'	3'-}}_'E^$	~	&	2&,mmN&C]#}},-+1==9L+M+S+STW+X'(+-'( 	)*6!!01*0--8K*L&'	~	&	26;L;LU[UbUbcuUv&--/5 	E.=.B.B.DL*+	E !--(=>!#L#))+ ]1aa(E!|*-aj/&'#q(T!4H2I-J,0()		*D1&--e4 &--qTWXYTZ.[\]" &--##F+T2=fmmF>STV}}$"(--
";YF //!!"34mm0--##$78O
 --(/-
JC l;.GHJHT/GbQhzU0EBOi
T/KRTUFO3FL#NO	!&,V]]=N=N~=^_F %}}  !34)&,V]]EVEVWeEfg$(!}}  !9:F$ACk!:DARARSkAl<m%y! %%flCARARSaAbc  \+-FGzz/*2*,'))Ir2 U?Em?T'{(;<U O..VaIb.cG{{#;R@ 
&&/23F/G038Lb0Q),^)<-01G-H"%&6"7),1G)H	
 )8F$%	(	
	&#FCk1JKE%*6HI##I.6$$t|K?X$Y$$"&,{2KUabkUl %  ) -MM%%n5 $$%94@ FvU	> 	>(	E 	Ef ##1183F3F3R3RS 	&  %%	&s1   +_?`B` ?`	`7a+a&&a+__main__)N)F)%DOCUMENTATIONEXAMPLESRETURNr   rr   r   r   hashlibr   r'   ImportErroransible.module_utils._textr   r   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   r   ;ansible_collections.amazon.aws.plugins.module_utils.modulesr   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr	   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr
   r  r   r3   rK   rZ   rz   r   r   rL   rn   r   r   r  __name__rF   r   r   <module>r!     s   aFtl(
T     	 0 0 W _ X P f T T8><
;|4$4EnB">,EP zF C  		s   B BB