Documentation
¶
Index ¶
- func HasOpenTofuExtension(name string) bool
- func HasTerraformExtension(name string) bool
- func IsGitSSHSource(u *url.URL) bool
- func IsLocalModule(source string) bool
- func NormalizeGitURLToHTTPS(u *url.URL) (*url.URL, error)
- func RecursivelyAddDirsToSparseCheckout(repoRoot string, sourceURL string, packageFetcher *PackageFetcher, ...) error
- func ResetGlobalModuleCache()
- func ResolveSymLinkedDirs(repoRoot, dir string) ([]string, error)
- type BaseCredentialSet
- type Cache
- type ConditionalTransport
- type CredentialsSource
- type CustomGitGetter
- type Disco
- type FetchTokenFunc
- type HostCredentials
- type HttpPublicModuleChecker
- type Manifest
- type ManifestModule
- type ModuleLoader
- type ModuleLoaderOptions
- type PackageFetcher
- type PackageFetcherOpts
- type PublicModuleChecker
- type RegistryLoader
- type RegistryLookupResult
- type RegistryURL
- type RemoteCache
- type S3Cache
- type SharedHCLParser
- type SourceMapResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasOpenTofuExtension ¶
func HasTerraformExtension ¶
func IsGitSSHSource ¶
IsGitSSHSource returns if the url u is a valid git ssh source. Param u is expected to be an url that has been transformed by a modsource Detect pass, removing shorthand and aliased for various sources.
func IsLocalModule ¶
IsLocalModule checks if the module is a local module by checking if the module source starts with any known local prefixes
func NormalizeGitURLToHTTPS ¶
NormalizeGitURLToHTTPS normalizes a Git source url to an HTTPS equivalent. It supports SSH URLs, as well as HTTPS URLS with usernames. This allows us to convert Terraform module source urls to HTTPS URLs, so we can attempt to download over HTTPS first using the existing credentials we have. It can also be used for generating links to resources within the module. There is a special case for Azure DevOps SSH URLs to handle converting them to the equivalent HTTPS URL.
func RecursivelyAddDirsToSparseCheckout ¶
func RecursivelyAddDirsToSparseCheckout(repoRoot string, sourceURL string, packageFetcher *PackageFetcher, existingDirs []string, dirs []string, mu *sync.Mutex, logger zerolog.Logger, depth int) error
RecursivelyAddDirsToSparseCheckout adds the given directories to the sparse-checkout file list. It then checks any symlinks within the directories and adds them to the sparse-checkout file list as well.
func ResetGlobalModuleCache ¶
func ResetGlobalModuleCache()
func ResolveSymLinkedDirs ¶
ResolveSymLinkedDirs traverses the directory to find symlinks and resolve their destinations
Types ¶
type BaseCredentialSet ¶
BaseCredentialSet are the underlying credentials that CredentialsSource will use if no other credentials can be found for a given host.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a cache of modules that can be used to lookup modules to check if they've already been loaded.
This only works with modules that have the same identifier. It doesn't cache modules that are used multiple times with different identifiers. That is done separately by the PackageFetcher and only caches per-run of C3X, so if you add the same module to your Terraform code it will redownload that module. We could optimize it by moving the package fetching cache logic into here, but it would be inconsistent with how terraform init works.
type ConditionalTransport ¶
type ConditionalTransport struct {
ProxyHosts []string
ProxyURL string
Inner http.RoundTripper
}
type CredentialsSource ¶
type CredentialsSource struct {
BaseCredentialSet BaseCredentialSet
FetchToken FetchTokenFunc
}
CredentialsSource is an object that may be able to provide credentials for a given module source.
func NewTerraformCredentialsSource ¶
func NewTerraformCredentialsSource(creds BaseCredentialSet) (*CredentialsSource, error)
NewTerraformCredentialsSource returns a CredentialsSource attempting to set the BaseCredentialSet as the base. If creds doesn't contain static details, NewTerraformCredentialsSource will attempt to fill the credential set from the environment, returning an error if it cannot.
func (*CredentialsSource) ForHost ¶
func (s *CredentialsSource) ForHost(host svchost.Hostname) (auth.HostCredentials, error)
ForHost returns a non-nil HostCredentials if the source has credentials available for the host, and a nil HostCredentials if it does not.
func (*CredentialsSource) ForgetForHost ¶
func (s *CredentialsSource) ForgetForHost(host svchost.Hostname) error
ForgetForHost is unimplemented but is required for the auth.CredentialsSource interface.
func (*CredentialsSource) StoreForHost ¶
func (s *CredentialsSource) StoreForHost(host svchost.Hostname, credentials auth.HostCredentialsWritable) error
StoreForHost is unimplemented but is required for the auth.CredentialsSource interface.
type CustomGitGetter ¶
CustomGitGetter extends the standard GitGetter and normalizes SSH and HTTPS URLs so it can attempt to use the Git credentials on the host machine to resolve the Get before falling back to the original method. SSH URLs are transformed to their HTTPS equivalent before attempting a Get. HTTPS URLS are stripped of any credentials.
type Disco ¶
type Disco struct {
// contains filtered or unexported fields
}
Disco allows discovery on given hostnames. It tries to resolve a module source based on a set of discovery rules. It caches the results by hostname to avoid repeated requests for the same information. Therefore, it is advisable to use Disco per project and pass it to all required clients.
func NewDisco ¶
func NewDisco(credentialsSource auth.CredentialsSource, logger zerolog.Logger) *Disco
NewDisco returns a Disco with the provided credentialsSource initialising the underlying Terraform Disco. If Credentials are nil then all registry requests will be unauthed.
func (*Disco) DownloadLocation ¶
func (d *Disco) DownloadLocation(moduleURL RegistryURL, version string) (string, error)
func (*Disco) ModuleLocation ¶
func (d *Disco) ModuleLocation(source string) (RegistryURL, bool, error)
ModuleLocation performs a discovery lookup for the given source and returns a RegistryURL with the real url of the module source and any required Credential information. It returns false if the module location is not recognised as a registry module.
type FetchTokenFunc ¶
FetchTokenFunc defines a function that returns a token for a given key. This can be an environment key, a header key, whatever the CredentialsSource requires.
type HostCredentials ¶
type HostCredentials struct {
// contains filtered or unexported fields
}
func (HostCredentials) PrepareRequest ¶
func (c HostCredentials) PrepareRequest(req *http.Request)
func (HostCredentials) Token ¶
func (c HostCredentials) Token() string
type HttpPublicModuleChecker ¶
type HttpPublicModuleChecker struct {
// contains filtered or unexported fields
}
func NewHttpPublicModuleChecker ¶
func NewHttpPublicModuleChecker() *HttpPublicModuleChecker
func (*HttpPublicModuleChecker) IsPublicModule ¶
func (h *HttpPublicModuleChecker) IsPublicModule(moduleAddr string) (bool, error)
IsPublic checks if a module is public by making a HEAD request to the module address and checking if the response status code is 200.
type Manifest ¶
type Manifest struct {
Path string `json:"Path"`
Version string `json:"Version"`
Modules []*ManifestModule `json:"Modules"`
// contains filtered or unexported fields
}
Manifest is a struct that represents the JSON found in the manifest.json file in the .c3x dir It is used for caching the modules that have already been downloaded. It uses the same format as the .terraform/modules/modules.json file
func (Manifest) Get ¶
func (m Manifest) Get(key string) ManifestModule
type ManifestModule ¶
type ManifestModule struct {
Key string `json:"Key"`
Source string `json:"Source"`
Version string `json:"Version,omitempty"`
Dir string `json:"Dir"`
DownloadURL string
IsSourceMapped bool `json:"-"`
}
ManifestModule represents a single module in the manifest.json file
func (ManifestModule) URL ¶
func (m ManifestModule) URL() string
type ModuleLoader ¶
type ModuleLoader struct {
// contains filtered or unexported fields
}
ModuleLoader handles the loading of Terraform modules. It supports local, registry and other remote modules.
The path should be the root directory of the Terraform project. We use a distinct module loader per Terraform project, because at the moment the cache is per project. The cache reads the manifest.json file from the path's .c3x/terraform_modules directory. We could implement a global cache in the future, but for now have decided to go with the same approach as Terraform.
func NewModuleLoader ¶
func NewModuleLoader(opts ModuleLoaderOptions) *ModuleLoader
NewModuleLoader constructs a new module loader
func (*ModuleLoader) Load ¶
func (m *ModuleLoader) Load(path string) (man *Manifest, err error)
Load loads the modules from the given path. For each module it checks if the module has already been downloaded, by checking if iut exists in the manifest If not then it downloads the module from the registry or from a remote source and updates the module manifest with the latest metadata.
func (*ModuleLoader) MapSourceWithRegex ¶
func (m *ModuleLoader) MapSourceWithRegex(source string) (SourceMapResult, error)
MapSourceWithRegex maps the module source using regex patterns if available. Falls back to the standard MapSource function if regex mapping is not configured or if no regex patterns match.
type ModuleLoaderOptions ¶
type ModuleLoaderOptions struct {
CachePath string
HCLParser *SharedHCLParser
CredentialsSource *CredentialsSource
SourceMap settings.TerraformSourceMap
SourceMapRegex settings.TerraformSourceMapRegex
Logger zerolog.Logger
ModuleSync *intSync.KeyMutex
RemoteCache RemoteCache
PublicModuleChecker PublicModuleChecker
}
type PackageFetcher ¶
type PackageFetcher struct {
// contains filtered or unexported fields
}
PackageFetcher downloads modules from a remote source to the given destination This supports all the non-local and non-Terraform registry sources listed here: https://www.terraform.io/language/modules/sources
func NewPackageFetcher ¶
func NewPackageFetcher(remoteCache RemoteCache, logger zerolog.Logger, opts ...PackageFetcherOpts) *PackageFetcher
NewPackageFetcher constructs a new package fetcher
func (*PackageFetcher) Fetch ¶
func (p *PackageFetcher) Fetch(moduleAddr string, dest string) error
fetch downloads the remote module using the modsource library See: https://github.com/hashicorp/modsource
type PackageFetcherOpts ¶
type PackageFetcherOpts func(*PackageFetcher)
func WithGetters ¶
func WithGetters(getters map[string]getter.Getter) PackageFetcherOpts
func WithPublicModuleChecker ¶
func WithPublicModuleChecker(publicModuleChecker PublicModuleChecker) PackageFetcherOpts
Option to provide a checker to determine if a module is public
type PublicModuleChecker ¶
PublicModuleChecker is an interface that defines the method for checking if a module is public.
type RegistryLoader ¶
type RegistryLoader struct {
// contains filtered or unexported fields
}
RegistryLoader is a loader that can lookup modules from a Terraform Registry and download them to the given destination
func NewRegistryLoader ¶
func NewRegistryLoader(packageFetcher *PackageFetcher, disco *Disco, logger zerolog.Logger) *RegistryLoader
NewRegistryLoader constructs a registry loader
func (*RegistryLoader) DownloadLocation ¶
func (r *RegistryLoader) DownloadLocation(moduleURL RegistryURL, version string) (string, error)
type RegistryLookupResult ¶
type RegistryLookupResult struct {
OK bool
ModuleURL RegistryURL
Version string
}
RegistryLookupResult is returned when looking up the module to check if it exists in the registry and has a matching version
type RegistryURL ¶
type RegistryURL struct {
RawSource string
Host string
Location string
Credentials auth.HostCredentials
}
RegistryURL contains given URL information for a module source. This can be used to build http requests to download the module or check versions of the module.
type RemoteCache ¶
type RemoteCache interface {
Exists(key string, public bool) (bool, error)
Get(key string, dest string, public bool) error
Put(key string, src string, ttl time.Duration, public bool) error
}
RemoteCache is an interface that defines the methods for a remote cache, i.e. an S3 bucket.
type S3Cache ¶
type S3Cache struct {
// contains filtered or unexported fields
}
func NewS3Cache ¶
NewS3Cache creates a new S3Cache instance
type SharedHCLParser ¶
type SharedHCLParser struct {
// contains filtered or unexported fields
}
func NewSharedHCLParser ¶
func NewSharedHCLParser() *SharedHCLParser
func (*SharedHCLParser) ParseHCLFile ¶
func (p *SharedHCLParser) ParseHCLFile(filename string) (*hcl.File, hcl.Diagnostics)
func (*SharedHCLParser) ParseJSONFile ¶
func (p *SharedHCLParser) ParseJSONFile(filename string) (*hcl.File, hcl.Diagnostics)
type SourceMapResult ¶
func MapSource ¶
func MapSource(sourceMap settings.TerraformSourceMap, source string) (SourceMapResult, error)
MapSource maps the module source to a new source if it is in the source map otherwise it returns the original source. It works similarly to the TERRAGRUNT_SOURCE_MAP environment variable except it matches by prefixes and supports query params. It works by matching the longest prefix first, so the most specific prefix is matched first.
It does not support mapping registry versions to git tags since we can't guarantee that the tag is correct - depending on the git repo the version might be prefixed with a 'v' or not.