mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-19 13:12:58 -06:00
e3416124cc
* huge change to weave new addrs.Provider into addrs.ProviderConfig * terraform: do not include an empty string in the returned Providers / Provisioners - Fixed a minor bug where results included an extra empty string
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package providers
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
// AddressedTypes is a helper that extracts all of the distinct provider
|
|
// types from the given list of relative provider configuration addresses.
|
|
func AddressedTypes(providerAddrs []addrs.ProviderConfig) []string {
|
|
if len(providerAddrs) == 0 {
|
|
return nil
|
|
}
|
|
m := map[string]struct{}{}
|
|
for _, addr := range providerAddrs {
|
|
m[addr.Type.LegacyString()] = struct{}{}
|
|
}
|
|
|
|
names := make([]string, 0, len(m))
|
|
for typeName := range m {
|
|
names = append(names, typeName)
|
|
}
|
|
|
|
sort.Strings(names) // Stable result for tests
|
|
return names
|
|
}
|
|
|
|
// 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) []string {
|
|
if len(providerAddrs) == 0 {
|
|
return nil
|
|
}
|
|
m := map[string]struct{}{}
|
|
for _, addr := range providerAddrs {
|
|
m[addr.ProviderConfig.Type.LegacyString()] = struct{}{}
|
|
}
|
|
|
|
names := make([]string, 0, len(m))
|
|
for typeName := range m {
|
|
names = append(names, typeName)
|
|
}
|
|
|
|
sort.Strings(names) // Stable result for tests
|
|
return names
|
|
}
|