opentofu/providers/addressed_types.go
Kristin Laemmert 47a16b0937
addrs: embed Provider in AbsProviderConfig instead of Type
a large refactor to addrs.AbsProviderConfig, embedding the addrs.Provider instead of a Type string. I've added and updated tests, added some Legacy functions to support older state formats and shims, and added a normalization step when reading v4 (current) state files (not the added tests under states/statefile/roundtrip which work with both current and legacy-style AbsProviderConfig strings).

The remaining 'fixme' and 'todo' comments are mostly going to be addressed in a subsequent PR and involve looking up a given local provider config's FQN. This is fine for now as we are only working with default assumption.
2020-02-13 15:32:58 -05:00

34 lines
740 B
Go

package providers
import (
"sort"
"github.com/hashicorp/terraform/addrs"
)
// AddressedTypesAbs is a helper that extracts all of the distinct provider
// types from the given list of absolute provider configuration addresses.
func AddressedTypesAbs(providerAddrs []addrs.AbsProviderConfig) []addrs.Provider {
if len(providerAddrs) == 0 {
return nil
}
m := map[string]addrs.Provider{}
for _, addr := range providerAddrs {
m[addr.Provider.String()] = addr.Provider
}
names := make([]string, 0, len(m))
for typeName := range m {
names = append(names, typeName)
}
sort.Strings(names) // Stable result for tests
ret := make([]addrs.Provider, len(names))
for i, name := range names {
ret[i] = m[name]
}
return ret
}