driver

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RunOptionNow runs the task immediate (now) once the task has been updated
	RunOptionNow = "now"
	// RunOptionInspect does a dry-run task update and returns dry-run info
	RunOptionInspect = "inspect"
)

Variables

View Source
var TerraformVersion *goVersion.Version

TerraformVersion is the version of Terraform CLI for the Terraform driver.

Functions

func InstallTerraform

func InstallTerraform(ctx context.Context, conf *config.TerraformConfig) error

InstallTerraform installs the Terraform binary to the configured path. If an existing Terraform exists in the path, it is checked for compatibility.

Types

type BufferPeriod

type BufferPeriod struct {
	Min time.Duration
	Max time.Duration
}

BufferPeriod contains the task's buffer period configuration information if enabled

type Driver

type Driver interface {
	// InitTask initializes the task that the driver executes
	InitTask(ctx context.Context) error

	// SetBufferPeriod sets the task's buffer period on the watcher
	SetBufferPeriod()

	// TemplateIDs returns the list of template IDs for the driver
	TemplateIDs() []string

	// RenderTemplate renders a template. Returns if template rendering
	// completed or not
	RenderTemplate(ctx context.Context) (bool, error)

	// InspectTask inspects for any differences pertaining to the task between
	// the state of Consul and network infrastructure
	InspectTask(ctx context.Context) (InspectPlan, error)

	// ApplyTask applies change for the task managed by the driver
	ApplyTask(ctx context.Context) error

	// UpdateTask supports updating certain fields of a task
	UpdateTask(ctx context.Context, task PatchTask) (InspectPlan, error)

	// DestroyTask destroys task dependencies so that it can be safely deleted
	DestroyTask(ctx context.Context)

	// Task returns the task information of the driver
	Task() *Task

	// Version returns the version of the driver.
	Version() string
}

Driver describes the interface for using an CTS driver to carry out changes downstream to update network infrastructure.

type Drivers

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

Drivers wraps the map of task-name to associated driver so that the map can be accessed concurrently

func NewDrivers

func NewDrivers() *Drivers

NewDrivers returns a new drivers object

func (*Drivers) Add

func (d *Drivers) Add(taskName string, driver Driver) error

Add adds a new driver

func (*Drivers) Delete added in v0.5.0

func (d *Drivers) Delete(taskName string) error

Delete removes the driver for the given task name from the map of drivers.

func (*Drivers) Get

func (d *Drivers) Get(taskName string) (Driver, bool)

Get retrieves the driver for a task by task name

func (*Drivers) GetTaskByTemplate added in v0.5.0

func (d *Drivers) GetTaskByTemplate(tmplID string) (Driver, bool)

GetTaskByTemplate retrieves the driver for a task by template ID

func (*Drivers) IsActive added in v0.1.3

func (d *Drivers) IsActive(name string) bool

func (*Drivers) IsMarkedForDeletion added in v0.5.0

func (d *Drivers) IsMarkedForDeletion(name string) bool

func (*Drivers) Len added in v0.4.0

func (d *Drivers) Len() int

func (*Drivers) Map

func (d *Drivers) Map() map[string]Driver

Map returns a copy of the map containing the drivers

func (*Drivers) MarkForDeletion added in v0.5.0

func (d *Drivers) MarkForDeletion(name string)

func (*Drivers) Reset added in v0.1.3

func (d *Drivers) Reset(ctx context.Context)

func (*Drivers) SetActive added in v0.1.3

func (d *Drivers) SetActive(name string) bool

func (*Drivers) SetBufferPeriod added in v0.1.3

func (d *Drivers) SetBufferPeriod()

func (*Drivers) SetInactive added in v0.1.3

func (d *Drivers) SetInactive(name string) bool

type InspectPlan

type InspectPlan struct {
	ChangesPresent bool   `json:"changes_present"`
	Plan           string `json:"plan"`
	URL            string `json:"url,omitempty"`
}

InspectPlan stores return the information about what

type PatchTask

type PatchTask struct {
	// RunOption is a set of options on how to handle the patch update
	// current options are "now" and "inspect". See constants for more details
	RunOption string

	Enabled bool
}

PatchTask holds the information to patch update a task. It will only include fields that we support updating at this time

type Service

type Service struct {
	Datacenter      string
	Description     string
	Name            string
	Namespace       string
	Filter          string
	UserDefinedMeta map[string]string
}

Service contains service configuration information

type Task

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

Task contains task configuration information

func NewTask added in v0.2.0

func NewTask(conf TaskConfig) (*Task, error)

func (*Task) BufferPeriod

func (t *Task) BufferPeriod() (BufferPeriod, bool)

BufferPeriod returns a copy of the buffer period. If the buffer period is not configured, the second parameter returns false.

func (*Task) Condition added in v0.2.0

func (t *Task) Condition() config.ConditionConfig

Condition returns the type of condition for the task to run

func (*Task) DeprecatedTFVersion added in v0.6.0

func (t *Task) DeprecatedTFVersion() string

DeprecatedTFVersion returns the Terraform version to use when using the Terraform Cloud driver. Enterprise. Deprecated, use the Terraform Version from TFCWorkspace() instead.

func (*Task) Description

func (t *Task) Description() string

Description returns the task description

func (*Task) Disable added in v0.2.0

func (t *Task) Disable()

Disable sets the task as disabled

func (*Task) Enable added in v0.2.0

func (t *Task) Enable()

Enable sets the task as enabled

func (*Task) Env

func (t *Task) Env() map[string]string

Env returns a copy of task environment variables

func (*Task) IsEnabled added in v0.2.0

func (t *Task) IsEnabled() bool

IsEnabled returns whether the task is enabled or disabled

func (*Task) IsScheduled added in v0.4.0

func (t *Task) IsScheduled() bool

IsScheduled returns if the task is a scheduled task or not (a dynamic task)

func (*Task) Module added in v0.5.0

func (t *Task) Module() string

Module returns the task's module

func (*Task) ModuleInputs added in v0.5.0

func (t *Task) ModuleInputs() config.ModuleInputConfigs

ModuleInputs returns the type of module input for the task to run

func (*Task) Name

func (t *Task) Name() string

Name returns the task name

func (*Task) ProviderIDs added in v0.6.0

func (t *Task) ProviderIDs() []string

ProviderIDs returns the list of providers that the task has configured. The provider id is formatted the same as how providers are configured in a task: If alias provided: <provider-name>.<provider-alias> If alias not provided: <provider-name>

func (*Task) Providers

func (t *Task) Providers() TerraformProviderBlocks

ProviderNames returns the list of providers that the task has configured

func (*Task) ServiceNames

func (t *Task) ServiceNames() []string

ServiceNames returns the list of services that the task has configured

func (*Task) Services

func (t *Task) Services() []Service

Services returns a copy of the list of services that the task has configured

func (*Task) TFCWorkspace added in v0.6.0

func (t *Task) TFCWorkspace() config.TerraformCloudWorkspaceConfig

TFCWorkspace returns the Terraform Cloud Workspace configuration to use for the task when using the Terraform Cloud driver. Enterprise only.

func (*Task) Variables added in v0.2.0

func (t *Task) Variables() hcltmpl.Variables

Variables returns a copy of the loaded input variables for a module from configured variable files.

func (*Task) Version

func (t *Task) Version() string

Version returns the configured version for the module of the task

func (*Task) WorkingDir added in v0.3.0

func (t *Task) WorkingDir() string

WorkingDir returns the working directory to manage generated artifacts for the task.

type TaskConfig added in v0.2.0

type TaskConfig struct {
	Description  string
	Name         string
	Enabled      bool
	Env          map[string]string
	Providers    TerraformProviderBlocks
	ProviderInfo map[string]interface{}
	Services     []Service
	Module       string
	Variables    map[string]string
	Version      string
	BufferPeriod *BufferPeriod
	Condition    config.ConditionConfig
	ModuleInputs config.ModuleInputConfigs
	WorkingDir   string

	// Enterprise
	DeprecatedTFVersion string
	TFCWorkspace        config.TerraformCloudWorkspaceConfig
}

type Terraform

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

Terraform is a CTS driver that uses the Terraform CLI to interface with low-level network infrastructure.

func NewTerraform

func NewTerraform(config *TerraformConfig) (*Terraform, error)

NewTerraform configures and initializes a new Terraform driver for a task. The underlying Terraform CLI client and out-of-band handlers are prepared.

func (*Terraform) ApplyTask

func (tf *Terraform) ApplyTask(ctx context.Context) error

ApplyTask applies the task changes.

func (*Terraform) DestroyTask added in v0.5.0

func (tf *Terraform) DestroyTask(_ context.Context)

DestroyTask destroys task dependencies so that it is safe for deletion

func (*Terraform) InitTask

func (tf *Terraform) InitTask(ctx context.Context) error

InitTask initializes the task by creating the Terraform root module and related files to execute on.

func (*Terraform) InspectTask

func (tf *Terraform) InspectTask(ctx context.Context) (InspectPlan, error)

InspectTask inspects for any differences pertaining to the task between the state of Consul and network infrastructure using the Terraform plan command

func (*Terraform) OnceDone added in v0.7.0

func (tf *Terraform) OnceDone() bool

func (*Terraform) RenderTemplate

func (tf *Terraform) RenderTemplate(_ context.Context) (bool, error)

RenderTemplate fetches data for the template. If the data is complete fetched, renders the template. Rendering a template for the first time may take several cycles to load all the dependencies asynchronously. Returns a boolean whether the template was rendered

func (*Terraform) SetBufferPeriod

func (tf *Terraform) SetBufferPeriod()

SetBufferPeriod sets the buffer period for the task. Do not set this when task needs to immediately render a template and run.

func (*Terraform) Task

func (tf *Terraform) Task() *Task

Task returns the task config info

func (*Terraform) TemplateIDs added in v0.5.0

func (tf *Terraform) TemplateIDs() []string

func (*Terraform) UpdateTask

func (tf *Terraform) UpdateTask(ctx context.Context, patch PatchTask) (InspectPlan, error)

UpdateTask updates the task on the driver. Makes any calls to re-init depending on the fields updated. If update task is requested with the inspect run option, then dry run the updates by returning the inspected plan for the expected updates but do not update the task

func (*Terraform) Version

func (tf *Terraform) Version() string

Version returns the Terraform CLI version for the Terraform driver.

type TerraformConfig

type TerraformConfig struct {
	Task              *Task
	Log               bool
	PersistLog        bool
	Path              string
	Backend           map[string]interface{}
	RequiredProviders map[string]interface{}
	Watcher           templates.Watcher
	// empty/unknown string will default to TerraformCLI client
	ClientType string
}

TerraformConfig configures the Terraform driver

type TerraformProviderBlock

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

TerraformProviderBlock contains provider arguments and environment variables for the Terraform provider.

func NewTerraformProviderBlock

func NewTerraformProviderBlock(b hcltmpl.NamedBlock) TerraformProviderBlock

NewTerraformProviderBlock creates a provider block with the environment variables separated from provider arguments from the base hcl block.

func (TerraformProviderBlock) Copy added in v0.2.0

func (TerraformProviderBlock) Env

func (p TerraformProviderBlock) Env() map[string]string

Env returns the configured environment variables for the Terraform provider. These values are set for the task workspace and are not written to any generated Terraform configuration file.

func (TerraformProviderBlock) ID added in v0.6.0

ID returns the unique id of the provider. This is the same as nae if no alias is provided. If alias provided, then the id is <provider-name>.<provider-alias>

func (TerraformProviderBlock) Name

func (p TerraformProviderBlock) Name() string

Name returns the name of the provider. This is the label of the HCL named block.

func (TerraformProviderBlock) ProviderBlock

func (p TerraformProviderBlock) ProviderBlock() hcltmpl.NamedBlock

ProviderBlock returns the arguments for the Terraform provider block.

type TerraformProviderBlocks

type TerraformProviderBlocks []TerraformProviderBlock

TerraformProviderBlocks are a list of providers and their arguments and env

func NewTerraformProviderBlocks

func NewTerraformProviderBlocks(blocks []hcltmpl.NamedBlock) TerraformProviderBlocks

NewTerraformProviderBlocks creates a new list of provider blocks with the environment variables separated from provider arguments from the base hcl block.

func (TerraformProviderBlocks) Copy added in v0.2.0

func (TerraformProviderBlocks) Env

Env returns a merged map of environment variables across all providers.

func (TerraformProviderBlocks) ProviderBlocks

func (p TerraformProviderBlocks) ProviderBlocks() []hcltmpl.NamedBlock

ProviderBlocks returns a list of the provider blocks.

Jump to

Keyboard shortcuts

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