terraform/plugin/discovery/requirements.go

27 lines
810 B
Go

package discovery
// PluginRequirements describes a set of plugins (assumed to be of a consistent
// kind) that are required to exist and have versions within the given
// corresponding sets.
//
// PluginRequirements is a map from plugin name to VersionSet.
type PluginRequirements map[string]VersionSet
// Merge takes the contents of the receiver and the other given requirements
// object and merges them together into a single requirements structure
// that satisfies both sets of requirements.
func (r PluginRequirements) Merge(other PluginRequirements) PluginRequirements {
ret := make(PluginRequirements)
for n, vs := range r {
ret[n] = vs
}
for n, vs := range other {
if existing, exists := ret[n]; exists {
ret[n] = existing.Intersection(vs)
} else {
ret[n] = vs
}
}
return ret
}