Ensure Cognito Identity Pool exists.

    name
        The name of the state definition

    IdentityPoolName
        Name of the Cognito Identity Pool

    AuthenticatedRole
        An IAM role name or ARN that will be associated with temporary AWS
        credentials for an authenticated cognito identity.

    AllowUnauthenticatedIdentities
        Whether to allow anonymous user identities

    UnauthenticatedRole
        An IAM role name or ARN that will be associated with anonymous
        user identities

    SupportedLoginProviders
        A dictionary or pillar that contains key:value pairs mapping provider
        names to provider app IDs.

    DeveloperProviderName
        A string which is the domain by which Cognito will refer to your users.
        This name acts as a placeholder that allows your backend and the Cognito
        service to communicate about the developer provider.  Once you have set a
        developer provider name, you cannot change it.  Please take care in setting
        this parameter.

    OpenIdConnectProviderARNs
        A list or pillar name that contains a list of OpenID Connect provider ARNs.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.

def pool_present(name,
                 IdentityPoolName,
                 AuthenticatedRole,
                 AllowUnauthenticatedIdentities=False,
                 UnauthenticatedRole=None,
                 SupportedLoginProviders=None,
                 DeveloperProviderName=None,
                 OpenIdConnectProviderARNs=None,
                 region=None, key=None, keyid=None, profile=None):
    '''
    Ensure Cognito Identity Pool exists.

    name
        The name of the state definition

    IdentityPoolName
        Name of the Cognito Identity Pool

    AuthenticatedRole
        An IAM role name or ARN that will be associated with temporary AWS
        credentials for an authenticated cognito identity.

    AllowUnauthenticatedIdentities
        Whether to allow anonymous user identities

    UnauthenticatedRole
        An IAM role name or ARN that will be associated with anonymous
        user identities

    SupportedLoginProviders
        A dictionary or pillar that contains key:value pairs mapping provider
        names to provider app IDs.

    DeveloperProviderName
        A string which is the domain by which Cognito will refer to your users.
        This name acts as a placeholder that allows your backend and the Cognito
        service to communicate about the developer provider.  Once you have set a
        developer provider name, you cannot change it.  Please take care in setting
        this parameter.

    OpenIdConnectProviderARNs
        A list or pillar name that contains a list of OpenID Connect provider ARNs.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    '''
    ret = {'name': IdentityPoolName,
           'result': True,
           'comment': '',
           'changes': {}}

    conn_params = dict(region=region, key=key, keyid=keyid, profile=profile)

    r = __salt__['boto_cognitoidentity.describe_identity_pools'](IdentityPoolName=IdentityPoolName,
                                                                 **conn_params)

    if r.get('error'):
        ret['result'] = False
        ret['comment'] = 'Failed to describe identity pools {0}'.format(r['error']['message'])
        return ret

    identity_pools = r.get('identity_pools')
    if identity_pools and len(identity_pools) > 1:
        ret['result'] = False
        ret['comment'] = ('More than one identity pool for the given name matched '
                          'Cannot execute pool_present function.\n'
                          'Matched Identity Pools:\n{0}'.format(identity_pools))
        return ret
    existing_identity_pool = None if identity_pools is None else identity_pools[0]
    IdentityPoolId = None if existing_identity_pool is None else existing_identity_pool.get('IdentityPoolId')

    if __opts__['test']:
        if identity_pools is None:
            ret['comment'] = ('A new identity pool named {0} will be '
                              'created.'.format(IdentityPoolName))
        else:
            ret['comment'] = ('An existing identity pool named {0} with id '
                              '{1}will be updated.'.format(IdentityPoolName,
                                                           IdentityPoolId))
        ret['result'] = None
        return ret

    SupportedLoginProviders = _get_object(SupportedLoginProviders, dict)
    OpenIdConnectProviderARNs = _get_object(OpenIdConnectProviderARNs, list)

    request_params = dict(IdentityPoolName=IdentityPoolName,
                          AllowUnauthenticatedIdentities=AllowUnauthenticatedIdentities,
                          SupportedLoginProviders=SupportedLoginProviders,
                          DeveloperProviderName=DeveloperProviderName,
                          OpenIdConnectProviderARNs=OpenIdConnectProviderARNs)
    request_params.update(conn_params)

    updated_identity_pool = None
    if IdentityPoolId is None:
        r = __salt__['boto_cognitoidentity.create_identity_pool'](**request_params)

        if r.get('created'):
            updated_identity_pool = r.get('identity_pool')
            IdentityPoolId = updated_identity_pool.get('IdentityPoolId')
            ret['comment'] = ('A new identity pool with name {0}, id {1} '
                              'is created.'.format(IdentityPoolName, IdentityPoolId))
        else:
            ret['result'] = False
            ret['comment'] = ('Failed to add a new identity pool: '
                              '{0}'.format(r['error'].get('message', r['error'])))
            return ret
    else:    # Update an existing pool
        request_params['IdentityPoolId'] = IdentityPoolId
        # we will never change the IdentityPoolName from the state module
        request_params.pop('IdentityPoolName', None)
        r = __salt__['boto_cognitoidentity.update_identity_pool'](**request_params)

        if r.get('updated'):
            updated_identity_pool = r.get('identity_pool')
            ret['comment'] = ('Existing identity pool with name {0}, id {1} '
                              'is updated.'.format(IdentityPoolName, IdentityPoolId))
        else:
            ret['result'] = False
            ret['comment'] = ('Failed to update an existing identity pool {0} {1}: '
                              '{2}'.format(IdentityPoolName, IdentityPoolId,
                                           r['error'].get('message', r['error'])))
            return ret

    if existing_identity_pool != updated_identity_pool:
        ret['changes']['old'] = dict()
        ret['changes']['new'] = dict()
        change_key = 'Identity Pool Name {0}'.format(IdentityPoolName)
        ret['changes']['old'][change_key] = existing_identity_pool
        ret['changes']['new'][change_key] = updated_identity_pool
    else:
        ret['comment'] = 'Identity Pool state is current, no changes.'

    # Now update the Auth/Unauth Roles
    _role_present(ret, IdentityPoolId, AuthenticatedRole, UnauthenticatedRole, conn_params)

    return ret