mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
internal/depsfile: Introduce the concept of "non-lockable" providers
It doesn't make sense for a built-in provider to appear in a lock file because built-in providers have no version independent of the version of Terraform they are compiled into. We also exclude legacy providers here, because they were supported only as a transitional aid to enable the Terraform 0.13 upgrade process and are not intended for explicit selection. The provider installer will, once it's updated to understand dependency locking, use this concept to decide which subset of its selections to record in the dependency lock file for reference for future installation requests.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package depsfile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
@@ -52,7 +53,16 @@ func (l *Locks) Provider(addr addrs.Provider) *ProviderLock {
|
||||
// SetProvider returns the newly-created provider lock object, which
|
||||
// invalidates any ProviderLock object previously returned from Provider or
|
||||
// SetProvider for the given provider address.
|
||||
//
|
||||
// Only lockable providers can be passed to this method. If you pass a
|
||||
// non-lockable provider address then this function will panic. Use
|
||||
// function ProviderIsLockable to determine whether a particular provider
|
||||
// should participate in the version locking mechanism.
|
||||
func (l *Locks) SetProvider(addr addrs.Provider, version getproviders.Version, constraints getproviders.VersionConstraints, hashes map[getproviders.Platform][]string) *ProviderLock {
|
||||
if !ProviderIsLockable(addr) {
|
||||
panic(fmt.Sprintf("Locks.SetProvider with non-lockable provider %s", addr))
|
||||
}
|
||||
|
||||
// Normalize the hash lists into a consistent order.
|
||||
for _, slice := range hashes {
|
||||
sort.Strings(slice)
|
||||
@@ -68,6 +78,15 @@ func (l *Locks) SetProvider(addr addrs.Provider, version getproviders.Version, c
|
||||
return new
|
||||
}
|
||||
|
||||
// ProviderIsLockable returns true if the given provider is eligible for
|
||||
// version locking.
|
||||
//
|
||||
// Currently, all providers except builtin and legacy providers are eligible
|
||||
// for locking.
|
||||
func ProviderIsLockable(addr addrs.Provider) bool {
|
||||
return !(addr.IsBuiltIn() || addr.IsLegacy())
|
||||
}
|
||||
|
||||
// Sources returns the source code of the file the receiver was generated from,
|
||||
// or an empty map if the receiver wasn't generated from a file.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user