github.com/opentofu/opentofu@v1.7.1/internal/providers/addressed_types.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package providers 7 8 import ( 9 "sort" 10 11 "github.com/opentofu/opentofu/internal/addrs" 12 ) 13 14 // AddressedTypesAbs is a helper that extracts all of the distinct provider 15 // types from the given list of absolute provider configuration addresses. 16 func AddressedTypesAbs(providerAddrs []addrs.AbsProviderConfig) []addrs.Provider { 17 if len(providerAddrs) == 0 { 18 return nil 19 } 20 m := map[string]addrs.Provider{} 21 for _, addr := range providerAddrs { 22 m[addr.Provider.String()] = addr.Provider 23 } 24 25 names := make([]string, 0, len(m)) 26 for typeName := range m { 27 names = append(names, typeName) 28 } 29 30 sort.Strings(names) // Stable result for tests 31 32 ret := make([]addrs.Provider, len(names)) 33 for i, name := range names { 34 ret[i] = m[name] 35 } 36 37 return ret 38 }