def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Autoscaling Launch Configuration"""

    # Check if the "IamInstanceProfile" is passed or not and then update it
    iam_instance_profile = params.get(IAM_INSTANCE_PROFILE)
    if iam_instance_profile:
        if isinstance(iam_instance_profile, basestring):
            iam_instance_profile = iam_instance_profile.strip()
            params[IAM_INSTANCE_PROFILE] = str(iam_instance_profile)
        else:
            raise NonRecoverableError('Invalid {0} data type for {1}'
                                      ''.format(type(iam_instance_profile),
                                                IAM_INSTANCE_PROFILE))

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list)

    image_id = params.get(IMAGEID)

    # Add Instance and Instance Type
    instance_id = params.get(INSTANCEID)
    instance_type = params.get(INSTANCE_TYPE_PROPERTY)
    if not image_id and not instance_id:
        instance_id = utils.find_resource_id_by_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params.update({INSTANCEID: instance_id})
    if instance_id and not instance_type:
        targ = utils.find_rel_by_node_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                INSTANCE_TYPE)
        if targ:
            instance_type = \
                targ.target.instance.runtime_properties.get(
                    'resource_config', {}).get(
                        INSTANCE_TYPE_PROPERTY) or \
                targ.target.node.properties.get(
                    INSTANCE_TYPE_PROPERTY_DEPRECATED)
        params.update({INSTANCE_TYPE_PROPERTY: instance_type})

    utils.update_resource_id(ctx.instance, params.get(RESOURCE_NAME))
    iface.update_resource_id(params.get(RESOURCE_NAME))
    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    resource_arn = iface.properties[LC_ARN]
    utils.update_resource_arn(ctx.instance, resource_arn)
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Group"""
    # Try to populate the Launch Configuration field
    # with a relationship
    lc_name = params.get(LC_NAME)
    instance_id = params.get(INSTANCE_ID)

    if not lc_name and not instance_id:
        lc_name = \
            utils.find_resource_id_by_type(
                ctx.instance,
                LC_TYPE)
        if lc_name:
            params.update({LC_NAME: lc_name})

    # If no LC_NAME, try to populate the
    # InstanceId field with a relationship.
    if not lc_name:
        instance_id = \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params[INSTANCE_ID] = instance_id

    subnet_list_string = params.get(SUBNET_LIST)
    subnet_list = \
        sub("[^\w]", " ", subnet_list_string).split() if \
        subnet_list_string else []

    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnet_list)
    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnet_list)

    if subnet_list:
        # Remove any duplicate items from subnet list
        subnet_list = list(set(subnet_list))
        params[SUBNET_LIST] = ', '.join(subnet_list)

    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    iface.update_resource_id(iface.properties.get(RESOURCE_NAME))
    utils.update_resource_id(
        ctx.instance, iface.properties.get(RESOURCE_NAME))
    utils.update_resource_arn(
        ctx.instance, iface.properties.get(GROUP_ARN))
Beispiel #3
0
    def test_find_resource_id_by_type(self):

        mock_instance, mock_child = self._prepare_for_find_rel()

        self.assertEqual(
            utils.find_resource_id_by_type(mock_instance.instance,
                                           'cloudify.nodes.Network'), None)

        self.assertEqual(
            utils.find_resource_id_by_type(mock_instance.instance,
                                           'cloudify.nodes.Root'), 'a')
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Group"""
    # Try to populate the Launch Configuration field
    # with a relationship
    lc_name = params.get(LC_NAME)
    instance_id = params.get(INSTANCE_ID)

    if not lc_name and not instance_id:
        lc_name = \
            utils.find_resource_id_by_type(
                ctx.instance,
                LC_TYPE)
        if lc_name:
            params.update({LC_NAME: lc_name})

    # If no LC_NAME, try to populate the
    # InstanceId field with a relationship.
    if not lc_name:
        instance_id = \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params[INSTANCE_ID] = instance_id

    subnet_list_string = params.get(SUBNET_LIST)
    subnet_list = \
        sub("[^\w]", " ", subnet_list_string).split() if \
        subnet_list_string else []

    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE,
            subnet_list)
    subnet_list = \
        utils.add_resources_from_rels(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED,
            subnet_list)

    if subnet_list:
        # Remove any duplicate items from subnet list
        subnet_list = list(set(subnet_list))
        params[SUBNET_LIST] = ', '.join(subnet_list)

    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    iface.update_resource_id(iface.properties.get(RESOURCE_NAME))
    utils.update_resource_id(ctx.instance, iface.properties.get(RESOURCE_NAME))
    utils.update_resource_arn(ctx.instance, iface.properties.get(GROUP_ARN))
    def test_find_resource_id_by_type(self):

        mock_instance, mock_child = self._prepare_for_find_rel()

        self.assertEqual(
            utils.find_resource_id_by_type(
                mock_instance.instance, 'cloudify.nodes.Network'
            ), None
        )

        self.assertEqual(
            utils.find_resource_id_by_type(
                mock_instance.instance, 'cloudify.nodes.Root'
            ), 'a'
        )
def delete(ctx, iface, resource_config, **_):
    '''Deletes an AWS IAM Profile'''
    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()
    instance_profile_name = params.get(RESOURCE_NAME)
    if not instance_profile_name:
        instance_profile_name = iface.resource_id
    params[RESOURCE_NAME] = instance_profile_name

    # Path parameter is not accepted by delete_instance_profile.
    try:
        del params['Path']
    except KeyError:
        pass

    role_name = params.pop('RoleName', None)
    if not role_name:
        role_name = \
            utils.find_resource_id_by_type(ctx.instance,
                                           IAM_ROLE_TYPE)
    if role_name:
        remove_role_params = {
            RESOURCE_NAME: instance_profile_name,
            'RoleName': role_name
        }
        iface.remove_role_from_instance_profile(remove_role_params)

    iface.delete(params)
Beispiel #7
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Autoscaling Lifecycle Hook"""
    params = utils.clean_params(
        dict() if not resource_config else resource_config.copy())
    resource_id = params.get(RESOURCE_NAME)
    if not resource_id:
        resource_id = \
            iface.resource_id or \
            utils.get_resource_id(
                ctx.node,
                ctx.instance,
                use_instance_id=True)
        params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Ensure the $GROUP_NAME parameter is populated.
    autoscaling_group = params.get(GROUP_NAME)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance, GROUP_TYPE)
        params[GROUP_NAME] = autoscaling_group
    ctx.instance.runtime_properties[GROUP_NAME] = \
        autoscaling_group
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Autoscaling Group Notification Configuration"""

    params = \
        dict() if not resource_config else resource_config.copy()

    autoscaling_group = \
        params.get(AUTOSCALING_GROUP_TARGET)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance,
                AUTOSCALING_TYPE)
        params[AUTOSCALING_GROUP_TARGET] = \
            autoscaling_group

    topic_arn = params.get(TOPIC_TARGET)
    if not topic_arn:
        topic_arn = \
            utils.find_resource_arn_by_type(
                ctx.instance,
                TOPIC_TYPE)
        params[TOPIC_TARGET] = \
            topic_arn

    # Actually create the resource
    iface.create(params)
def delete(ctx, iface, resource_config, **_):
    """Deletes an AWS Autoscaling Group Notification Configuration"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    autoscaling_group = \
        params.get(AUTOSCALING_GROUP_TARGET)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance,
                AUTOSCALING_TYPE)
        params[AUTOSCALING_GROUP_TARGET] = \
            autoscaling_group

    topic_arn = params.get(TOPIC_TARGET)
    if not topic_arn:
        topic_arn = \
            utils.find_resource_arn_by_type(
                ctx.instance,
                TOPIC_TYPE)
        params[TOPIC_TARGET] = \
            topic_arn

    iface.delete(params)
Beispiel #10
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Cloudwatch Target"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    rule = params.get(RULE)
    if not rule:
        rule = utils.find_resource_id_by_type(ctx.instance, RULE_TYPE)
        params[RULE] = rule

    targets = params.get(TARGETS, [])
    for target in targets:
        target_arn = target.get(ARN, '')
        if not utils.validate_arn(target_arn):
            targs = \
                utils.find_rels_by_node_name(
                    ctx.instance,
                    target_arn)
            if targs:
                target_arn = \
                    targs[0].target.instance.runtime_properties.get(
                        EXTERNAL_RESOURCE_ARN, target_arn)
        targets.remove(target)
        target[ARN] = target_arn
        targets.append(target)

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Profile'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        ) or iface.resource_id
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    role_name = params.pop('RoleName', None)

    create_response = iface.create(params)
    resource_id = create_response['InstanceProfile'][RESOURCE_NAME]
    iface.update_resource_id(resource_id)
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(
        ctx.instance, create_response['InstanceProfile']['Arn'])

    role_name = role_name or \
        utils.find_resource_id_by_type(ctx.instance,
                                       IAM_ROLE_TYPE)
    if role_name:
        add_role_params = {
            RESOURCE_NAME: iface.resource_id,
            'RoleName': role_name
        }
        iface.add_role_to_instance_profile(add_role_params)
        ctx.instance.runtime_properties['RoleName'] = role_name
def delete(ctx, iface, resource_config, **_):
    """Deletes an AWS Autoscaling Group Notification Configuration"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    autoscaling_group = \
        params.get(AUTOSCALING_GROUP_TARGET)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance,
                AUTOSCALING_TYPE)
        params[AUTOSCALING_GROUP_TARGET] = \
            autoscaling_group

    topic_arn = params.get(TOPIC_TARGET)
    if not topic_arn:
        topic_arn = \
            utils.find_resource_arn_by_type(
                ctx.instance,
                TOPIC_TYPE)
        params[TOPIC_TARGET] = \
            topic_arn

    iface.delete(params)
Beispiel #13
0
def delete(ctx, iface, resource_config, **_):
    '''Deletes an AWS IAM Profile'''
    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()
    instance_profile_name = params.get(RESOURCE_NAME)
    if not instance_profile_name:
        instance_profile_name = iface.resource_id
    params[RESOURCE_NAME] = instance_profile_name

    # Path parameter is not accepted by delete_instance_profile.
    try:
        del params['Path']
    except KeyError:
        pass

    role_name = params.pop('RoleName', None)
    if not role_name:
        role_name = \
            utils.find_resource_id_by_type(ctx.instance,
                                           IAM_ROLE_TYPE)
    if role_name:
        remove_role_params = {
            RESOURCE_NAME: instance_profile_name,
            'RoleName': role_name
        }
        iface.remove_role_from_instance_profile(remove_role_params)

    iface.delete(params)
Beispiel #14
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Profile'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        ) or iface.resource_id
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    role_name = params.pop('RoleName', None)

    create_response = iface.create(params)
    resource_id = create_response['InstanceProfile'][RESOURCE_NAME]
    iface.update_resource_id(resource_id)
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(ctx.instance,
                              create_response['InstanceProfile']['Arn'])

    role_name = role_name or \
        utils.find_resource_id_by_type(ctx.instance,
                                       IAM_ROLE_TYPE)
    if role_name:
        add_role_params = {
            RESOURCE_NAME: iface.resource_id,
            'RoleName': role_name
        }
        iface.add_role_to_instance_profile(add_role_params)
        ctx.instance.runtime_properties['RoleName'] = role_name
Beispiel #15
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Role Policy'''
    # Build API params
    params = utils.clean_params(
        dict() if not resource_config else resource_config.copy())
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        ) or iface.resource_id
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Add RoleName
    role_name = params.get(ROLE_NAME, '')
    if not role_name:
        params[ROLE_NAME] = \
            utils.find_resource_id_by_type(
                ctx.instance,
                ROLE_TYPE)
    if 'PolicyDocument' in params and \
            isinstance(params['PolicyDocument'], dict):
        params['PolicyDocument'] = json_dumps(params['PolicyDocument'])

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Autoscaling Group Notification Configuration"""

    params = \
        dict() if not resource_config else resource_config.copy()

    autoscaling_group = \
        params.get(AUTOSCALING_GROUP_TARGET)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance,
                AUTOSCALING_TYPE)
        params[AUTOSCALING_GROUP_TARGET] = \
            autoscaling_group

    topic_arn = params.get(TOPIC_TARGET)
    if not topic_arn:
        topic_arn = \
            utils.find_resource_arn_by_type(
                ctx.instance,
                TOPIC_TYPE)
        params[TOPIC_TARGET] = \
            topic_arn

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS EC2 NAT Gateway"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    subnet_id = params.get(SUBNET_ID)
    if not subnet_id:
        subnet_id = \
            utils.find_resource_id_by_type(
                ctx.instance, SUBNET_TYPE) or \
            utils.find_resource_id_by_type(
                ctx.instance, SUBNET_TYPE_DEPRECATED)
        params.update({SUBNET_ID: subnet_id})

    allocation_id = params.get(ALLOCATION_ID)
    if not allocation_id:
        targ = \
            utils.find_rel_by_node_type(
                ctx.instance,
                ELASTICIP_TYPE) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                ELASTICIP_TYPE_DEPRECATED)
        if targ:
            allocation_id = \
                targ.target.instance.runtime_properties.get(
                    ALLOCATION_ID_DEPRECATED)
    params[ALLOCATION_ID] = allocation_id
    ctx.instance.runtime_properties['allocation_id'] = \
        allocation_id

    # Actually create the resource
    create_response = iface.create(params)['NatGateway']
    ctx.instance.runtime_properties['create_response'] = \
        utils.JsonCleanuper(create_response).to_dict()
    utils.update_resource_id(
        ctx.instance, create_response.get(NATGATEWAY_ID))
Beispiel #18
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS EC2 NAT Gateway"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    subnet_id = params.get(SUBNET_ID)
    if not subnet_id:
        subnet_id = \
            utils.find_resource_id_by_type(
                ctx.instance, SUBNET_TYPE) or \
            utils.find_resource_id_by_type(
                ctx.instance, SUBNET_TYPE_DEPRECATED)
        params.update({SUBNET_ID: subnet_id})

    allocation_id = params.get(ALLOCATION_ID)
    if not allocation_id:
        targ = \
            utils.find_rel_by_node_type(
                ctx.instance,
                ELASTICIP_TYPE) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                ELASTICIP_TYPE_DEPRECATED)
        if targ:
            allocation_id = \
                targ.target.instance.runtime_properties.get(
                    ALLOCATION_ID_DEPRECATED)
    params[ALLOCATION_ID] = allocation_id
    ctx.instance.runtime_properties['allocation_id'] = \
        allocation_id

    # Actually create the resource
    create_response = iface.create(params)['NatGateway']
    ctx.instance.runtime_properties['create_response'] = \
        utils.JsonCleanuper(create_response).to_dict()
    utils.update_resource_id(ctx.instance, create_response.get(NATGATEWAY_ID))
Beispiel #19
0
def delete(ctx, iface, resource_config, **_):
    """Deletes an AWS Cloudwatch Target"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    rule = params.get(RULE)
    if not rule:
        rule = utils.find_resource_id_by_type(ctx.instance, RULE_TYPE)
        params[RULE] = rule

    params[IDS] = \
        [target.get(ID) for target in params.pop(TARGETS)]

    iface.delete(params)
Beispiel #20
0
def create(ctx, iface, resource_config, params, **_):
    '''Creates an AWS IAM Role Policy'''

    # Add RoleName
    role_name = params.get(ROLE_NAME, '')
    if not role_name:
        params[ROLE_NAME] = \
            utils.find_resource_id_by_type(
                ctx.instance,
                ROLE_TYPE)
    if 'PolicyDocument' in params and \
            isinstance(params['PolicyDocument'], dict):
        params['PolicyDocument'] = json_dumps(params['PolicyDocument'])

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, params, **_):
    '''Creates an AWS IAM Role Policy'''

    # Add RoleName
    role_name = params.get(ROLE_NAME, '')
    if not role_name:
        params[ROLE_NAME] = \
            utils.find_resource_id_by_type(
                ctx.instance,
                ROLE_TYPE)
    if 'PolicyDocument' in params and \
            isinstance(params['PolicyDocument'], dict):
        params['PolicyDocument'] = json_dumps(params['PolicyDocument'])

    # Actually create the resource
    iface.create(params)
Beispiel #22
0
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Lifecycle Hook"""

    # Ensure the $GROUP_NAME parameter is populated.
    autoscaling_group = params.get(GROUP_NAME)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance, GROUP_TYPE)
        params[GROUP_NAME] = autoscaling_group
    ctx.instance.runtime_properties[GROUP_NAME] = \
        autoscaling_group
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))

    # Actually create the resource
    iface.create(params)
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Lifecycle Hook"""

    # Ensure the $GROUP_NAME parameter is populated.
    autoscaling_group = params.get(GROUP_NAME)
    if not autoscaling_group:
        autoscaling_group = \
            utils.find_resource_id_by_type(
                ctx.instance, GROUP_TYPE)
        params[GROUP_NAME] = autoscaling_group
    ctx.instance.runtime_properties[GROUP_NAME] = \
        autoscaling_group
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))

    # Actually create the resource
    iface.create(params)
def delete(ctx, iface, resource_config, **_):
    '''Deletes an AWS IAM Role Policy'''
    params = \
        dict() if not resource_config else resource_config.copy()

    # Add RoleName
    role_name = params.get(ROLE_NAME, '')
    if not role_name:
        params[ROLE_NAME] = \
            utils.find_resource_id_by_type(
                ctx.instance,
                ROLE_TYPE)
    # Add Policy Name
    policy_name = params.get(RESOURCE_NAME, '')
    if not policy_name:
        params[RESOURCE_NAME] = \
            ctx.node.properties.get('resource_id') or \
            ctx.instance.runtime_properties[CTS.EXTERNAL_RESOURCE_ID] or \
            ctx.instance.id

    iface.delete(params)
Beispiel #25
0
def delete(ctx, iface, resource_config, **_):
    '''Deletes an AWS IAM Role Policy'''
    params = \
        dict() if not resource_config else resource_config.copy()

    # Add RoleName
    role_name = params.get(ROLE_NAME, '')
    if not role_name:
        params[ROLE_NAME] = \
            utils.find_resource_id_by_type(
                ctx.instance,
                ROLE_TYPE)
    # Add Policy Name
    policy_name = params.get(RESOURCE_NAME, '')
    if not policy_name:
        params[RESOURCE_NAME] = \
            ctx.node.properties.get('resource_id') or \
            ctx.instance.runtime_properties[CTS.EXTERNAL_RESOURCE_ID] or \
            ctx.instance.id

    iface.delete(params)
def create(ctx, iface, resource_config, params, **_):
    """Creates an AWS Autoscaling Autoscaling Launch Configuration"""

    # Check if the "IamInstanceProfile" is passed or not and then update it
    iam_instance_profile = params.get(IAM_INSTANCE_PROFILE)
    if iam_instance_profile:
        if isinstance(iam_instance_profile, basestring):
            iam_instance_profile = iam_instance_profile.strip()
            params[IAM_INSTANCE_PROFILE] = str(iam_instance_profile)
        else:
            raise NonRecoverableError(
                'Invalid {0} data type for {1}'
                ''.format(type(iam_instance_profile), IAM_INSTANCE_PROFILE))

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list)

    image_id = params.get(IMAGEID)

    # Add Instance and Instance Type
    instance_id = params.get(INSTANCEID)
    instance_type = params.get(INSTANCE_TYPE_PROPERTY)
    if not image_id and not instance_id:
        instance_id = utils.find_resource_id_by_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_resource_id_by_type(
                ctx.instance,
                INSTANCE_TYPE)
        params.update({INSTANCEID: instance_id})
    if instance_id and not instance_type:
        targ = utils.find_rel_by_node_type(
            ctx.instance,
            INSTANCE_TYPE_NEW) or \
            utils.find_rel_by_node_type(
                ctx.instance,
                INSTANCE_TYPE)
        if targ:
            instance_type = \
                targ.target.instance.runtime_properties.get(
                    'resource_config', {}).get(
                        INSTANCE_TYPE_PROPERTY) or \
                targ.target.node.properties.get(
                    INSTANCE_TYPE_PROPERTY_DEPRECATED)
        params.update({INSTANCE_TYPE_PROPERTY: instance_type})

    utils.update_resource_id(
        ctx.instance, params.get(RESOURCE_NAME))
    iface.update_resource_id(params.get(RESOURCE_NAME))
    # Actually create the resource
    if not iface.resource_id:
        setattr(iface, 'resource_id', params.get(RESOURCE_NAME))
    iface.create(params)
    resource_arn = iface.properties[LC_ARN]
    utils.update_resource_arn(
        ctx.instance, resource_arn)