"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.imagebuilder.create_infrastructure_configuration
hub.exec.boto3.client.imagebuilder.delete_infrastructure_configuration
hub.exec.boto3.client.imagebuilder.get_infrastructure_configuration
hub.exec.boto3.client.imagebuilder.list_infrastructure_configurations
hub.exec.boto3.client.imagebuilder.update_infrastructure_configuration
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_profile_name: Text, client_token: Text, description: Text = None, instance_types: List = None, security_group_ids: List = None, subnet_id: Text = None, logging: Dict = None, key_pair: Text = None, terminate_instance_on_failure: bool = None, sns_topic_arn: Text = None, resource_tags: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new infrastructure configuration. An infrastructure configuration defines the environment in which
    your image will be built and tested.

    Args:
        name(Text): The name of the infrastructure configuration.
        description(Text, optional): The description of the infrastructure configuration. Defaults to None.
        instance_types(List, optional): The instance types of the infrastructure configuration. You can specify one or more instance
            types to use for this build. The service will pick one of these instance types based on
            availability. Defaults to None.
        instance_profile_name(Text): The instance profile to associate with the instance used to customize your Amazon EC2 AMI.
        security_group_ids(List, optional): The security group IDs to associate with the instance used to customize your Amazon EC2 AMI. Defaults to None.
        subnet_id(Text, optional): The subnet ID in which to place the instance used to customize your Amazon EC2 AMI. Defaults to None.
        logging(Dict, optional): The logging configuration of the infrastructure configuration. Defaults to None.
        key_pair(Text, optional): The key pair of the infrastructure configuration. This can be used to log on to and debug the
            instance used to create your image. Defaults to None.
        terminate_instance_on_failure(bool, optional): The terminate instance on failure setting of the infrastructure configuration. Set to false if
            you want Image Builder to retain the instance used to configure your AMI if the build or test
            phase of your workflow fails. Defaults to None.
        sns_topic_arn(Text, optional): The SNS topic on which to send image build events. Defaults to None.
        resource_tags(Dict, optional): The tags attached to the resource created by Image Builder. Defaults to None.
        tags(Dict, optional): The tags of the infrastructure configuration. Defaults to None.
        client_token(Text): The idempotency token used to make this request idempotent.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.imagebuilder.infrastructure_configuration.present:
                - name: value
                - instance_profile_name: value
                - client_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.imagebuilder.infrastructure_configuration.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.imagebuilder.get_infrastructure_configuration(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.imagebuilder.create_infrastructure_configuration(
                ctx,
                
                
                **{"Name": name, "description": description, "instanceTypes": instance_types, "instanceProfileName": instance_profile_name, "securityGroupIds": security_group_ids, "subnetId": subnet_id, "logging": logging, "keyPair": key_pair, "terminateInstanceOnFailure": terminate_instance_on_failure, "snsTopicArn": sns_topic_arn, "resourceTags": resource_tags, "tags": tags, "clientToken": client_token}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.imagebuilder.get_infrastructure_configuration(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, infrastructure_configuration_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes an infrastructure configuration.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        infrastructure_configuration_arn(Text): The Amazon Resource Name (ARN) of the infrastructure configuration to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.imagebuilder.infrastructure_configuration.absent:
                - name: value
                - infrastructure_configuration_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.imagebuilder.infrastructure_configuration.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.imagebuilder.get_infrastructure_configuration(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.imagebuilder.delete_infrastructure_configuration(
                ctx,
                
                
                **{"infrastructureConfigurationArn": infrastructure_configuration_arn}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.imagebuilder.get_infrastructure_configuration(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

