cliconfig

package
v0.12.31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2021 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cliconfig has the types representing and the logic to load CLI-level configuration settings.

The CLI config is a small collection of settings that a user can override via some files in their home directory or, in some cases, via environment variables. The CLI config is not the same thing as a Terraform configuration written in the Terraform language; the logic for those lives in the top-level directory "configs".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the configuration directory for Terraform.

func ConfigFile

func ConfigFile() (string, error)

ConfigFile returns the default path to the configuration file.

On Unix-like systems this is the ".terraformrc" file in the home directory. On Windows, this is the "terraform.rc" file in the application data directory.

Types

type Config

type Config struct {
	Providers    map[string]string
	Provisioners map[string]string

	DisableCheckpoint          bool `hcl:"disable_checkpoint"`
	DisableCheckpointSignature bool `hcl:"disable_checkpoint_signature"`

	// If set, enables local caching of plugins in this directory to
	// avoid repeatedly re-downloading over the Internet.
	PluginCacheDir string `hcl:"plugin_cache_dir"`

	Hosts map[string]*ConfigHost `hcl:"host"`

	Credentials        map[string]map[string]interface{}   `hcl:"credentials"`
	CredentialsHelpers map[string]*ConfigCredentialsHelper `hcl:"credentials_helper"`
}

Config is the structure of the configuration for the Terraform CLI.

This is not the configuration for Terraform itself. That is in the "config" package.

var BuiltinConfig Config

BuiltinConfig is the built-in defaults for the configuration. These can be overridden by user configurations.

func EnvConfig

func EnvConfig() *Config

EnvConfig returns a Config populated from environment variables.

Any values specified in this config should override those set in the configuration file.

func LoadConfig

func LoadConfig() (*Config, tfdiags.Diagnostics)

LoadConfig reads the CLI configuration from the various filesystem locations and from the environment, returning a merged configuration along with any diagnostics (errors and warnings) encountered along the way.

func (*Config) CredentialsSource added in v0.12.8

func (c *Config) CredentialsSource(helperPlugins pluginDiscovery.PluginMetaSet) (*CredentialsSource, error)

CredentialsSource creates and returns a service credentials source whose behavior depends on which "credentials" and "credentials_helper" blocks, if any, are present in the receiving config.

func (*Config) Merge

func (c1 *Config) Merge(c2 *Config) *Config

Merge merges two configurations and returns a third entirely new configuration with the two merged.

func (*Config) Validate

func (c *Config) Validate() tfdiags.Diagnostics

Validate checks for errors in the configuration that cannot be detected just by HCL decoding, returning any problems as diagnostics.

On success, the returned diagnostics will return false from the HasErrors method. A non-nil diagnostics is not necessarily an error, since it may contain just warnings.

type ConfigCredentialsHelper

type ConfigCredentialsHelper struct {
	Args []string `hcl:"args"`
}

ConfigCredentialsHelper is the structure of the "credentials_helper" nested block within the CLI configuration.

type ConfigHost

type ConfigHost struct {
	Services map[string]interface{} `hcl:"services"`
}

ConfigHost is the structure of the "host" nested block within the CLI configuration, which can be used to override the default service host discovery behavior for a particular hostname.

type CredentialsLocation added in v0.12.8

type CredentialsLocation rune

CredentialsLocation describes a type of storage used for the credentials for a particular hostname.

const (
	// CredentialsNotAvailable means that we know that there are no credential
	// available for the host.
	//
	// Note that CredentialsViaHelper might also lead to no credentials being
	// available, depending on how the helper answers when we request credentials
	// from it.
	CredentialsNotAvailable CredentialsLocation = 0

	// CredentialsInPrimaryFile means that there is already a credentials object
	// for the host in the credentials.tfrc.json file.
	CredentialsInPrimaryFile CredentialsLocation = 'P'

	// CredentialsInOtherFile means that there is already a credentials object
	// for the host in a CLI config file other than credentials.tfrc.json.
	CredentialsInOtherFile CredentialsLocation = 'O'

	// CredentialsViaHelper indicates that no statically-configured credentials
	// are available for the host but a helper program is available that may
	// or may not have credentials for the host.
	CredentialsViaHelper CredentialsLocation = 'H'
)

type CredentialsSource added in v0.12.8

type CredentialsSource struct {
	// contains filtered or unexported fields
}

CredentialsSource is an implementation of svcauth.CredentialsSource that can read and write the CLI configuration, and possibly also delegate to a credentials helper when configured.

func EmptyCredentialsSourceForTests added in v0.12.8

func EmptyCredentialsSourceForTests(credentialsFilePath string) *CredentialsSource

EmptyCredentialsSourceForTests constructs a CredentialsSource with no credentials pre-loaded and which writes new credentials to a file at the given path.

As the name suggests, this function is here only for testing and should not be used in normal application code.

func (*CredentialsSource) CredentialsFilePath added in v0.12.8

func (s *CredentialsSource) CredentialsFilePath() (string, error)

CredentialsFilePath returns the full path to the local credentials configuration file, so that a caller can mention this path in order to be transparent about where credentials will be stored.

This file will be used for writes only if HostCredentialsLocation for the relevant host returns CredentialsInPrimaryFile or CredentialsNotAvailable.

The credentials file path is found relative to the current user's home directory, so this function will return an error in the unlikely event that we cannot determine a suitable home directory to resolve relative to.

func (*CredentialsSource) CredentialsHelperType added in v0.12.8

func (s *CredentialsSource) CredentialsHelperType() string

CredentialsHelperType returns the name of the configured credentials helper type, or an empty string if no credentials helper is configured.

func (*CredentialsSource) ForHost added in v0.12.8

func (s *CredentialsSource) ForHost(host svchost.Hostname) (svcauth.HostCredentials, error)

func (*CredentialsSource) ForgetForHost added in v0.12.8

func (s *CredentialsSource) ForgetForHost(host svchost.Hostname) error

func (*CredentialsSource) HostCredentialsLocation added in v0.12.8

func (s *CredentialsSource) HostCredentialsLocation(host svchost.Hostname) CredentialsLocation

HostCredentialsLocation returns a value indicating what type of storage is currently used for the credentials for the given hostname.

The current location of credentials determines whether updates are possible at all and, if they are, where any updates will be written.

func (*CredentialsSource) StoreForHost added in v0.12.8

func (s *CredentialsSource) StoreForHost(host svchost.Hostname, credentials svcauth.HostCredentialsWritable) error

type ErrUnwritableHostCredentials added in v0.12.8

type ErrUnwritableHostCredentials svchost.Hostname

ErrUnwritableHostCredentials is an error type that is returned when a caller tries to write credentials for a host that has existing credentials configured in a file that we cannot automatically update.

func (ErrUnwritableHostCredentials) Error added in v0.12.8

func (ErrUnwritableHostCredentials) Hostname added in v0.12.8

func (err ErrUnwritableHostCredentials) Hostname() svchost.Hostname

Hostname returns the host that could not be written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL