Added ensure_resource function