cloud

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: MPL-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkspaceTagsStrategy    workspaceStrategy = "tags"
	WorkspaceNameStrategy    workspaceStrategy = "name"
	WorkspaceNoneStrategy    workspaceStrategy = "none"
	WorkspaceInvalidStrategy workspaceStrategy = "invalid"
)

Variables

This section is empty.

Functions

func GenerateID

func GenerateID(s string) string

func ParseCloudRunVariables

func ParseCloudRunVariables(vv map[string]backend.UnparsedVariableValue, decls map[string]*configs.Variable) (map[string]string, tfdiags.Diagnostics)

ParseCloudRunVariables accepts a mapping of unparsed values and a mapping of variable declarations and returns a name/value variable map appropriate for an API run context, that is, containing variables only sourced from non-file inputs like CLI args and environment variables. However, all variable parsing diagnostics are returned in order to allow callers to short circuit cloud runs that contain variable declaration or parsing errors. The only exception is that missing required values are not considered errors because they may be defined within the cloud workspace.

Types

type Cloud

type Cloud struct {
	// CLI and Colorize control the CLI output. If CLI is nil then no CLI
	// output will be done. If CLIColor is nil then no coloring will be done.
	CLI      cli.Ui
	CLIColor *colorstring.Colorize

	// ContextOpts are the base context options to set when initializing a
	// new Terraform context. Many of these will be overridden or merged by
	// Operation. See Operation for more details.
	ContextOpts *terraform.ContextOpts

	// WorkspaceMapping contains strategies for mapping CLI workspaces in the working directory
	// to remote Terraform Cloud workspaces.
	WorkspaceMapping WorkspaceMapping
	// contains filtered or unexported fields
}

Cloud is an implementation of EnhancedBackend in service of the Terraform Cloud/Enterprise integration for Terraform CLI. This backend is not intended to be surfaced at the user level and is instead an implementation detail of cloud.Cloud.

func New

func New(services *disco.Disco) *Cloud

New creates a new initialized cloud backend.

func (*Cloud) CLIInit

func (b *Cloud) CLIInit(opts *backend.CLIOpts) error

CLIInit implements backend.CLI

func (*Cloud) Colorize

func (b *Cloud) Colorize() Colorer

Colorize returns the Colorize structure that can be used for colorizing output. This is guaranteed to always return a non-nil value and so is useful as a helper to wrap any potentially colored strings.

func (*Cloud) ConfigSchema

func (b *Cloud) ConfigSchema() *configschema.Block

ConfigSchema implements backend.Enhanced.

func (*Cloud) Configure

func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics

Configure implements backend.Enhanced.

func (*Cloud) DeleteWorkspace

func (b *Cloud) DeleteWorkspace(name string) error

DeleteWorkspace implements backend.Enhanced.

func (*Cloud) IgnoreVersionConflict

func (b *Cloud) IgnoreVersionConflict()

IgnoreVersionConflict allows commands to disable the fall-back check that the local Terraform version matches the remote workspace's configured Terraform version. This should be called by commands where this check is unnecessary, such as those performing remote operations, or read-only operations. It will also be called if the user uses a command-line flag to override this check.

func (*Cloud) IsLocalOperations

func (b *Cloud) IsLocalOperations() bool

func (*Cloud) LocalRun

LocalRun implements backend.Local

func (*Cloud) Operation

func (b *Cloud) Operation(ctx context.Context, op *backend.Operation) (*backend.RunningOperation, error)

Operation implements backend.Enhanced.

func (*Cloud) PrepareConfig

func (b *Cloud) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics)

PrepareConfig implements backend.Backend.

func (*Cloud) StateMgr

func (b *Cloud) StateMgr(name string) (statemgr.Full, error)

StateMgr implements backend.Enhanced.

func (*Cloud) VerifyWorkspaceTerraformVersion

func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Diagnostics

VerifyWorkspaceTerraformVersion compares the local Terraform version against the workspace's configured Terraform version. If they are compatible, this means that there are no state compatibility concerns, so it returns no diagnostics.

If the versions aren't compatible, it returns an error (or, if b.ignoreVersionConflict is set, a warning).

func (*Cloud) Workspaces

func (b *Cloud) Workspaces() ([]string, error)

Workspaces implements backend.Enhanced, returning a filtered list of workspace names according to the workspace mapping strategy configured.

type Colorer

type Colorer interface {
	Color(v string) string
}

Colorer is the interface that must be implemented to colorize strings.

type Colorize

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

Colorize is used to print output when the -no-color flag is used. It will strip all ANSI escaped color codes which are set while the operation was executed in Terraform Enterprise.

When Terraform Enterprise supports run specific variables, this code can be removed as we can then pass the CLI flag to the backend and prevent the color codes from being written to the output.

func (*Colorize) Color

func (c *Colorize) Color(v string) string

Color will strip all ANSI escaped color codes and return a uncolored string.

type ConfigChangeMode

type ConfigChangeMode rune

ConfigChangeMode is a rough way to think about different situations that our backend change and state migration codepaths need to distinguish in the context of Cloud integration mode.

const (
	// ConfigMigrationIn represents when the configuration calls for using
	// Cloud mode but the working directory state disagrees.
	ConfigMigrationIn ConfigChangeMode = '↘'

	// ConfigMigrationOut represents when the working directory state calls
	// for using Cloud mode but the working directory state disagrees.
	ConfigMigrationOut ConfigChangeMode = '↖'

	// ConfigChangeInPlace represents when both the working directory state
	// and the config call for using Cloud mode, and so there might be
	// (but won't necessarily be) cloud settings changing, but we don't
	// need to do any actual migration.
	ConfigChangeInPlace ConfigChangeMode = '↻'

	// ConfigChangeIrrelevant represents when the config and working directory
	// state disagree but neither calls for using Cloud mode, and so the
	// Cloud integration is not involved in dealing with this.
	ConfigChangeIrrelevant ConfigChangeMode = '🤷'
)

func DetectConfigChangeType

func DetectConfigChangeType(wdState *legacy.BackendState, config *configs.Backend, haveLocalStates bool) ConfigChangeMode

DetectConfigChangeType encapsulates the fiddly logic for deciding what kind of Cloud configuration change we seem to be making, based on the existing working directory state (if any) and the current configuration.

This is a pretty specialized sort of thing focused on finicky details of the way we currently model working directory settings and config, so its signature probably won't survive any non-trivial refactoring of how the CLI layer thinks about backends/state storage.

func (ConfigChangeMode) InvolvesCloud

func (m ConfigChangeMode) InvolvesCloud() bool

func (ConfigChangeMode) IsCloudMigration

func (m ConfigChangeMode) IsCloudMigration() bool

func (ConfigChangeMode) String

func (i ConfigChangeMode) String() string

type MockApplies

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

func (*MockApplies) Logs

func (m *MockApplies) Logs(ctx context.Context, applyID string) (io.Reader, error)

func (*MockApplies) Read

func (m *MockApplies) Read(ctx context.Context, applyID string) (*tfe.Apply, error)

type MockClient

type MockClient struct {
	Applies               *MockApplies
	ConfigurationVersions *MockConfigurationVersions
	CostEstimates         *MockCostEstimates
	Organizations         *MockOrganizations
	Plans                 *MockPlans
	PolicyChecks          *MockPolicyChecks
	Runs                  *MockRuns
	StateVersions         *MockStateVersions
	Variables             *MockVariables
	Workspaces            *MockWorkspaces
}

func NewMockClient

func NewMockClient() *MockClient

type MockConfigurationVersions

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

func (*MockConfigurationVersions) Create

func (*MockConfigurationVersions) List

func (*MockConfigurationVersions) Read

func (*MockConfigurationVersions) ReadWithOptions

func (*MockConfigurationVersions) Upload

func (m *MockConfigurationVersions) Upload(ctx context.Context, url, path string) error

type MockCostEstimates

type MockCostEstimates struct {
	Estimations map[string]*tfe.CostEstimate
	// contains filtered or unexported fields
}

func (*MockCostEstimates) Logs

func (m *MockCostEstimates) Logs(ctx context.Context, costEstimateID string) (io.Reader, error)

func (*MockCostEstimates) Read

func (m *MockCostEstimates) Read(ctx context.Context, costEstimateID string) (*tfe.CostEstimate, error)

type MockOrganizations

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

func (*MockOrganizations) Capacity

func (m *MockOrganizations) Capacity(ctx context.Context, name string) (*tfe.Capacity, error)

func (*MockOrganizations) Create

func (*MockOrganizations) Delete

func (m *MockOrganizations) Delete(ctx context.Context, name string) error

func (*MockOrganizations) Entitlements

func (m *MockOrganizations) Entitlements(ctx context.Context, name string) (*tfe.Entitlements, error)

func (*MockOrganizations) List

func (*MockOrganizations) Read

func (m *MockOrganizations) Read(ctx context.Context, name string) (*tfe.Organization, error)

func (*MockOrganizations) RunQueue

func (m *MockOrganizations) RunQueue(ctx context.Context, name string, options tfe.RunQueueOptions) (*tfe.RunQueue, error)

func (*MockOrganizations) Update

type MockPlans

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

func (*MockPlans) JSONOutput

func (m *MockPlans) JSONOutput(ctx context.Context, planID string) ([]byte, error)

func (*MockPlans) Logs

func (m *MockPlans) Logs(ctx context.Context, planID string) (io.Reader, error)

func (*MockPlans) Read

func (m *MockPlans) Read(ctx context.Context, planID string) (*tfe.Plan, error)

type MockPolicyChecks

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

func (*MockPolicyChecks) List

func (*MockPolicyChecks) Logs

func (m *MockPolicyChecks) Logs(ctx context.Context, policyCheckID string) (io.Reader, error)

func (*MockPolicyChecks) Override

func (m *MockPolicyChecks) Override(ctx context.Context, policyCheckID string) (*tfe.PolicyCheck, error)

func (*MockPolicyChecks) Read

func (m *MockPolicyChecks) Read(ctx context.Context, policyCheckID string) (*tfe.PolicyCheck, error)

type MockRuns

type MockRuns struct {
	sync.Mutex

	Runs map[string]*tfe.Run

	// If ModifyNewRun is non-nil, the create method will call it just before
	// saving a new run in the runs map, so that a calling test can mimic
	// side-effects that a real server might apply in certain situations.
	ModifyNewRun func(client *MockClient, options tfe.RunCreateOptions, run *tfe.Run)
	// contains filtered or unexported fields
}

func (*MockRuns) Apply

func (m *MockRuns) Apply(ctx context.Context, runID string, options tfe.RunApplyOptions) error

func (*MockRuns) Cancel

func (m *MockRuns) Cancel(ctx context.Context, runID string, options tfe.RunCancelOptions) error

func (*MockRuns) Create

func (m *MockRuns) Create(ctx context.Context, options tfe.RunCreateOptions) (*tfe.Run, error)

func (*MockRuns) Discard

func (m *MockRuns) Discard(ctx context.Context, runID string, options tfe.RunDiscardOptions) error

func (*MockRuns) ForceCancel

func (m *MockRuns) ForceCancel(ctx context.Context, runID string, options tfe.RunForceCancelOptions) error

func (*MockRuns) List

func (m *MockRuns) List(ctx context.Context, workspaceID string, options tfe.RunListOptions) (*tfe.RunList, error)

func (*MockRuns) Read

func (m *MockRuns) Read(ctx context.Context, runID string) (*tfe.Run, error)

func (*MockRuns) ReadWithOptions

func (m *MockRuns) ReadWithOptions(ctx context.Context, runID string, _ *tfe.RunReadOptions) (*tfe.Run, error)

type MockStateVersions

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

func (*MockStateVersions) Create

func (m *MockStateVersions) Create(ctx context.Context, workspaceID string, options tfe.StateVersionCreateOptions) (*tfe.StateVersion, error)

func (*MockStateVersions) Current

func (m *MockStateVersions) Current(ctx context.Context, workspaceID string) (*tfe.StateVersion, error)

func (*MockStateVersions) CurrentWithOptions

func (m *MockStateVersions) CurrentWithOptions(ctx context.Context, workspaceID string, options *tfe.StateVersionCurrentOptions) (*tfe.StateVersion, error)

func (*MockStateVersions) Download

func (m *MockStateVersions) Download(ctx context.Context, url string) ([]byte, error)

func (*MockStateVersions) List

func (*MockStateVersions) Outputs

func (*MockStateVersions) Read

func (m *MockStateVersions) Read(ctx context.Context, svID string) (*tfe.StateVersion, error)

func (*MockStateVersions) ReadWithOptions

func (m *MockStateVersions) ReadWithOptions(ctx context.Context, svID string, options *tfe.StateVersionReadOptions) (*tfe.StateVersion, error)

type MockVariables

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

func (*MockVariables) Create

func (m *MockVariables) Create(ctx context.Context, workspaceID string, options tfe.VariableCreateOptions) (*tfe.Variable, error)

func (*MockVariables) Delete

func (m *MockVariables) Delete(ctx context.Context, workspaceID string, variableID string) error

func (*MockVariables) List

func (m *MockVariables) List(ctx context.Context, workspaceID string, options tfe.VariableListOptions) (*tfe.VariableList, error)

func (*MockVariables) Read

func (m *MockVariables) Read(ctx context.Context, workspaceID string, variableID string) (*tfe.Variable, error)

func (*MockVariables) Update

func (m *MockVariables) Update(ctx context.Context, workspaceID string, variableID string, options tfe.VariableUpdateOptions) (*tfe.Variable, error)

type MockWorkspaces

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

func (*MockWorkspaces) AddRemoteStateConsumers

func (m *MockWorkspaces) AddRemoteStateConsumers(ctx context.Context, workspaceID string, options tfe.WorkspaceAddRemoteStateConsumersOptions) error

func (*MockWorkspaces) AddTags

func (m *MockWorkspaces) AddTags(ctx context.Context, workspaceID string, options tfe.WorkspaceAddTagsOptions) error

func (*MockWorkspaces) AssignSSHKey

func (m *MockWorkspaces) AssignSSHKey(ctx context.Context, workspaceID string, options tfe.WorkspaceAssignSSHKeyOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) Create

func (m *MockWorkspaces) Create(ctx context.Context, organization string, options tfe.WorkspaceCreateOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) Delete

func (m *MockWorkspaces) Delete(ctx context.Context, organization, workspace string) error

func (*MockWorkspaces) DeleteByID

func (m *MockWorkspaces) DeleteByID(ctx context.Context, workspaceID string) error

func (*MockWorkspaces) ForceUnlock

func (m *MockWorkspaces) ForceUnlock(ctx context.Context, workspaceID string) (*tfe.Workspace, error)

func (*MockWorkspaces) List

func (m *MockWorkspaces) List(ctx context.Context, organization string, options tfe.WorkspaceListOptions) (*tfe.WorkspaceList, error)

func (*MockWorkspaces) Lock

func (m *MockWorkspaces) Lock(ctx context.Context, workspaceID string, options tfe.WorkspaceLockOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) Read

func (m *MockWorkspaces) Read(ctx context.Context, organization, workspace string) (*tfe.Workspace, error)

func (*MockWorkspaces) ReadByID

func (m *MockWorkspaces) ReadByID(ctx context.Context, workspaceID string) (*tfe.Workspace, error)

func (*MockWorkspaces) ReadByIDWithOptions

func (m *MockWorkspaces) ReadByIDWithOptions(ctx context.Context, workspaceID string, options *tfe.WorkspaceReadOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) ReadWithOptions

func (m *MockWorkspaces) ReadWithOptions(ctx context.Context, organization string, workspace string, options *tfe.WorkspaceReadOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) Readme

func (m *MockWorkspaces) Readme(ctx context.Context, workspaceID string) (io.Reader, error)

func (*MockWorkspaces) RemoteStateConsumers

func (m *MockWorkspaces) RemoteStateConsumers(ctx context.Context, workspaceID string, options *tfe.RemoteStateConsumersListOptions) (*tfe.WorkspaceList, error)

func (*MockWorkspaces) RemoveRemoteStateConsumers

func (m *MockWorkspaces) RemoveRemoteStateConsumers(ctx context.Context, workspaceID string, options tfe.WorkspaceRemoveRemoteStateConsumersOptions) error

func (*MockWorkspaces) RemoveTags

func (m *MockWorkspaces) RemoveTags(ctx context.Context, workspaceID string, options tfe.WorkspaceRemoveTagsOptions) error

func (*MockWorkspaces) RemoveVCSConnection

func (m *MockWorkspaces) RemoveVCSConnection(ctx context.Context, organization, workspace string) (*tfe.Workspace, error)

func (*MockWorkspaces) RemoveVCSConnectionByID

func (m *MockWorkspaces) RemoveVCSConnectionByID(ctx context.Context, workspaceID string) (*tfe.Workspace, error)

func (*MockWorkspaces) Tags

func (m *MockWorkspaces) Tags(ctx context.Context, workspaceID string, options tfe.WorkspaceTagListOptions) (*tfe.TagList, error)

func (*MockWorkspaces) UnassignSSHKey

func (m *MockWorkspaces) UnassignSSHKey(ctx context.Context, workspaceID string) (*tfe.Workspace, error)

func (*MockWorkspaces) Unlock

func (m *MockWorkspaces) Unlock(ctx context.Context, workspaceID string) (*tfe.Workspace, error)

func (*MockWorkspaces) Update

func (m *MockWorkspaces) Update(ctx context.Context, organization, workspace string, options tfe.WorkspaceUpdateOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) UpdateByID

func (m *MockWorkspaces) UpdateByID(ctx context.Context, workspaceID string, options tfe.WorkspaceUpdateOptions) (*tfe.Workspace, error)

func (*MockWorkspaces) UpdateRemoteStateConsumers

func (m *MockWorkspaces) UpdateRemoteStateConsumers(ctx context.Context, workspaceID string, options tfe.WorkspaceUpdateRemoteStateConsumersOptions) error

type WorkspaceMapping

type WorkspaceMapping struct {
	Name string
	Tags []string
}

func (WorkspaceMapping) Strategy

func (wm WorkspaceMapping) Strategy() workspaceStrategy

Jump to

Keyboard shortcuts

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