The variety and complexity of habitats, niches, and ecological processes within a particular ecosystem.