private boolean matches(Set<InstanceName> elementInstances,
                            Set<Environment> elementEnvironments,
                            Set<RegionName> elementRegions,
                            Set<CloudName> elementClouds,
                            Tags elementTags) {
        if ( ! elementInstances.isEmpty()) { // match instance
            if ( ! elementInstances.contains(instance)) return false;
        }

        if ( ! elementEnvironments.isEmpty()) { // match environment
            if ( ! elementEnvironments.contains(environment)) return false;
        }

        if ( ! elementRegions.isEmpty()) { // match region
            if ( ! elementRegions.contains(region)) return false;
        }

        if ( ! elementClouds.isEmpty()) { // match cloud
            if ( ! elementClouds.contains(cloud)) return false;
        }

        if ( ! elementTags.isEmpty()) { // match tags
            if ( ! elementTags.intersects(tags)) return false;
            // Tags are set on instances. Having a tag match for a deployment to a non-prod environment
            // disables the usual downscaling of the cluster, which is surprising. We therefore either
            // require the tags match to either also match an environment directive, or the implicit prod.
            if (elementEnvironments.isEmpty() && environment != Environment.prod) return false;
        }

        return true;
    }
Prune elements that are not matching our environment and region.
config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java