
    Vhu                         d Z dZdZ	 ddlZddlmZ ddlmZ	 d Z
d Zd	 Zd
 Zd Zedk(  r e        yy# e$ r Y 0w xY w)a^  
---
module: elasticbeanstalk_app
version_added: 1.0.0

short_description: Create, update, and delete an Elastic Beanstalk application

description:
  - Creates, updates, deletes Elastic Beanstalk applications if I(app_name) is provided.
  - Prior to release 5.0.0 this module was called C(community.aws.aws_elasticbeanstalk_app).
    The usage did not change.

options:
  app_name:
    description:
      - Name of the Beanstalk application you wish to manage.
    aliases: [ 'name' ]
    type: str
  description:
    description:
      - The description of the application.
    type: str
  state:
    description:
      - Whether to ensure the application is present or absent.
    default: present
    choices: ['absent','present']
    type: str
  terminate_by_force:
    description:
      - When I(terminate_by_force=true), running environments will be terminated before deleting the application.
    default: false
    type: bool
author:
  - Harpreet Singh (@hsingh)
  - Stephen Granger (@viper233)
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
z
# Create or update an application
- community.aws.elasticbeanstalk_app:
    app_name: Sample_App
    description: "Hello World App"
    state: present

# Delete application
- community.aws.elasticbeanstalk_app:
    app_name: Sample_App
    state: absent
a$  
app:
    description: Beanstalk application.
    returned: always
    type: dict
    sample: {
        "ApplicationName": "app-name",
        "ConfigurationTemplates": [],
        "DateCreated": "2016-12-28T14:50:03.185000+00:00",
        "DateUpdated": "2016-12-28T14:50:03.185000+00:00",
        "Description": "description",
        "Versions": [
            "1.0.0",
            "1.0.1"
        ]
    }
output:
    description: Message indicating what change will occur.
    returned: in check mode
    type: str
    sample: App is up-to-date
    N)is_boto3_error_message)AnsibleCommunityAWSModulec                 F    t        | ||      }t        |      dk7  rd S |d   S )N   r   )	list_appslen)ebsapp_namemoduleappss       v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/elasticbeanstalk_app.pydescribe_appr   _   s)    S(F+Dt9>4.tAw.    c                 "   	 || j                  |g      }n| j                         }j                  dg       S # t        j                  j                  t        j                  j                  f$ r}|j                  |d       Y d }~ad }~ww xY w)N)ApplicationNameszCould not describe applicationmsgApplications)describe_applicationsbotocore
exceptionsClientErrorBotoCoreErrorfail_json_awsget)r	   r
   r   r   es        r   r   r   e   s    F,,xj,ID,,.D 88NB'' ++X-@-@-N-NO FQ$DEEFs   &: 7B1B		Bc                    |j                   d   }|j                   d   }|j                   d   }i }|dk(  r|t        dd      }n|dk(  r$|j                  dd       |k7  rt        dd	|
      }nn|dk(  r$|j                  dd       |k(  rt        dd|
      }nE|dk(  r|t        ddi 
      }n/|dk(  r|t        dd|
      }n|dk(  r||du rt        dd|
      } |j                  di | y )Ndescriptionstateterminate_by_forcepresentTzApp would be created)changedoutputDescriptionzApp would be updatedr"   r#   appFzApp is up-to-dateabsentzApp does not existzApp will be deletedz>Running environments terminated before the App will be deleted )paramsdictr   	exit_json)r	   r&   r   r   r   r    results          r   	check_appr-   q   s   --.KMM'"E';<F	ckd+AB	)	t < Kd+AsK	)	t < Ke,?SI	(	s{e,@bI	(	sd+@cJ	(	s3E3Md+kqtuFvr   c                  J    i }| j                         D ]  \  }}|s	|||<    |S )N)items)kwargsretvalkvs       r   filter_emptyr4      s3    F 1F1I Mr   c            
         t        t        dgdd      t               t        ddgd      t        ddd	      
      } t        | d      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }||j                  d       i }|j	                  d      }t        |||      }|j                  rt        |||       |j                  d       |dk(  r|9	  |j                  d i t        ||       t        |||      }t        d|      }n|j                  dd       |k7  rD	 |s|j!                  |       n|j!                  ||       t        |||      }t        d|      }nWt        d|      }nI|t        ddi       }n8	 |r|j#                  ||       n|j#                  |       d}
t        
|      } |j&                  d i | y # t        j                  j                  t        j                  j                  f$ r}	|j                  |	d       Y d }	~	.d }	~	ww xY w# t        j                  j                  t        j                  j                  f$ r}	|j                  |	d       Y d }	~	-d }	~	ww xY w# t%        d      $ r d}
Y t        j                  j                  t        j                  j                  f$ r}	|j                  |	d       Y d }	~	1d }	~	ww xY w)!NnamestrF)aliasestyperequiredr!   r'   )choicesdefaultbool)r9   r<   r:   )r
   r   r   r    T)argument_specsupports_check_moder
   r   r   r    z'Module parameter "app_name" is requiredr   elasticbeanstalkz9ASSERTION FAILURE: check_app() should not return control.)ApplicationNamer$   zCould not create application)r"   r&   r$   )rA   zCould not update applicationzApplication not foundr%   )rA   TerminateEnvByForcez It is currently pending deletionzCannot terminate appr(   )r*   AnsibleAWSModuler)   	fail_jsonclientr   
check_moder-   create_applicationr4   r   r   r   r   r   r   update_applicationdelete_applicationr   r+   )r>   r   r
   r   r   r    r,   r	   r&   r   r"   s              r   mainrJ      s   vhUUCFIx0)DVUUK	M MtTF}}Z(H--.KMM'"E';<FGF
--*
+C
sHf
-C#sF#XY	;L&&&ih\g)hi sHf5C$C0Fww}d+{:P&..x.H..xU`.a #3&9d4e5 ;%0GRPFD%**8Yk*l**8*D 's3FFvW ''33X5H5H5V5VW L$$Q,J$KKL !++779L9L9Z9Z[ P((0N(OOP( **LM  ##//##11 D $$Q,B$CC	DsN   .G) <(I *J )7H> H99H>7J8JJK?+6K?!K::K?__main__)DOCUMENTATIONEXAMPLESRETURNr   ImportError<ansible_collections.amazon.aws.plugins.module_utils.botocorer   >ansible_collections.community.aws.plugins.module_utils.modulesr   rC   r   r   r-   r4   rJ   __name__r(   r   r   <module>rS      sp   (T
.	 ` x/	(.K\ zF O  		s   5 ==