cloud

package
v0.0.0-...-d0ab2d1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MPL-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var ErrStateVersionUnauthorizedUpgradeState = errors.New(strings.TrimSpace(`
You are not authorized to read the full state version containing outputs.
State versions created by durgaform v1.3.0 and newer do not require this level
of authorization and therefore this error can usually be fixed by upgrading the
remote state version.
`))

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 Durgaform context. Many of these will be overridden or merged by
	// Operation. See Operation for more details.
	ContextOpts *durgaform.ContextOpts

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

Cloud is an implementation of EnhancedBackend in service of the Durgaform Cloud/Enterprise integration for Durgaform 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 Durgaform version matches the remote workspace's configured Durgaform 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) VerifyWorkspaceDurgaformVersion

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

VerifyWorkspaceDurgaformVersion compares the local Terraform version against the workspace's configured Durgaform 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 Durgaform Enterprise.

When Durgaform 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 IntegrationContext

type IntegrationContext struct {
	B             *Cloud
	StopContext   context.Context
	CancelContext context.Context
	Op            *backend.Operation
	Run           *tfe.Run
}

IntegrationContext is a set of data that is useful when performing Durgaform Cloud integration operations

func (*IntegrationContext) BeginOutput

func (s *IntegrationContext) BeginOutput(name string) IntegrationOutputWriter

BeginOutput writes a preamble to the CLI and creates a new IntegrationOutputWriter interface to write the remaining CLI output to. Use IntegrationOutputWriter.End() to complete integration output

func (*IntegrationContext) Poll

func (s *IntegrationContext) Poll(every func(i int) (bool, error)) error

type IntegrationOutputWriter

type IntegrationOutputWriter interface {
	End()
	OutputElapsed(message string, maxMessage int)
	Output(str string)
	SubOutput(str string)
}

IntegrationOutputWriter is an interface used to to write output tailored for Durgaform Cloud integrations

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
	StateVersionOutputs   *MockStateVersionOutputs
	Variables             *MockVariables
	Workspaces            *MockWorkspaces
}

func NewMockClient

func NewMockClient() *MockClient

type MockConfigurationVersions

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

func (*MockConfigurationVersions) Archive

func (m *MockConfigurationVersions) Archive(ctx context.Context, cvID string) error

func (*MockConfigurationVersions) Create

func (*MockConfigurationVersions) Download

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

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) Create

func (*MockOrganizations) Delete

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

func (*MockOrganizations) List

func (*MockOrganizations) Read

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

func (*MockOrganizations) ReadCapacity

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

func (*MockOrganizations) ReadEntitlements

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

func (*MockOrganizations) ReadRunQueue

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

func (*MockOrganizations) Update

type MockPlans

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

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)

func (*MockPlans) ReadJSONOutput

func (m *MockPlans) ReadJSONOutput(ctx context.Context, planID string) ([]byte, 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 MockStateVersionOutputs

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

func (*MockStateVersionOutputs) Read

func (*MockStateVersionOutputs) ReadCurrent

func (m *MockStateVersionOutputs) ReadCurrent(ctx context.Context, workspaceID string) (*tfe.StateVersionOutputsList, 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) Download

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

func (*MockStateVersions) List

func (*MockStateVersions) ListOutputs

func (*MockStateVersions) Read

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

func (*MockStateVersions) ReadCurrent

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

func (*MockStateVersions) ReadCurrentWithOptions

func (m *MockStateVersions) ReadCurrentWithOptions(ctx context.Context, workspaceID string, options *tfe.StateVersionCurrentOptions) (*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) ListRemoteStateConsumers

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

func (*MockWorkspaces) ListTags

func (m *MockWorkspaces) ListTags(ctx context.Context, workspaceID string, options *tfe.WorkspaceTagListOptions) (*tfe.TagList, 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) 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) 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 State

type State struct {
	Client *remoteClient
	// contains filtered or unexported fields
}

State is similar to remote State and delegates to it, except in the case of output values, which use a separate methodology that ensures the caller is authorized to read cloud workspace outputs.

func NewState

func NewState(client *remoteClient) *State

func (*State) GetRootOutputValues

func (s *State) GetRootOutputValues() (map[string]*states.OutputValue, error)

GetRootOutputValues fetches output values from Durgaform Cloud

func (*State) Lock

func (s *State) Lock(info *statemgr.LockInfo) (string, error)

Lock delegates calls to lock state to the remote State

func (*State) PersistState

func (s *State) PersistState() error

RefreshState delegates calls to refresh State to the remote State

func (*State) RefreshState

func (s *State) RefreshState() error

RefreshState delegates calls to refresh State to the remote State

func (*State) State

func (s *State) State() *states.State

State delegates calls to read State to the remote State

func (*State) Unlock

func (s *State) Unlock(id string) error

Unlock delegates calls to unlock state to the remote State

func (*State) WriteState

func (s *State) WriteState(state *states.State) error

WriteState delegates calls to write State to the remote State

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