def add_resource(stack_definition, resource_definition):
    """Insert the given resource definition into the stack definition.

    Add the resource to the template and store any temporary data.
    """
    resource_name = resource_definition.name
    stack_definition._resources.pop(resource_name, None)
    stack_definition._resource_data.pop(resource_name, None)
    stack_definition.t.add_resource(resource_definition)
    if stack_definition._resource_defns is not None:
        stack_definition._resource_defns[resource_name] = resource_definition
