Raise InvalidTemplateReference for missing resources

Previously this code raised InvalidTemplateAttribute when a resource
doesn't exist. But our existing code (in the dependency check, which
executes first) raises InvalidTemplateReference in this case and reserves
InvalidTemplateAttribute for when the resource exists but the attribute is
invalid. This patch makes the functions consistent with that behaviour.

It also raises InvalidTemplateReference, instead of KeyError, in the same
case in get_resource. I assumed that this could never fail, but that is
only true for Ref, not get_resource.

Change-Id: Ib7dcd3333bc2fc7778d3a013abae10c5795086dd
Merge "Raise InvalidTemplateReference for missing resources"