tf

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InProgress = "in progress"
	Succeeded  = "succeeded"
	Failed     = "failed"

	TfUpgradeEnabled = "brokerpak.terraform.upgrades.enabled"
)

Variables

This section is empty.

Functions

func CheckTerraformPlanOutput added in v0.10.0

func CheckTerraformPlanOutput(logger lager.Logger, output executor.ExecutionOutput) error

func NewTerraformProvider

func NewTerraformProvider(jobRunner JobRunner, logger lager.Logger, serviceDefinition TfServiceDefinitionV1, store broker.ServiceProviderStorage) broker.ServiceProvider

NewTerraformProvider creates a new ServiceProvider backed by Terraform module definitions for provision and bind.

func UpdateWorkspaceHCL

func UpdateWorkspaceHCL(store broker.ServiceProviderStorage, action TfServiceDefinitionV1Action, operationContext *varcontext.VarContext, tfID string) error

Types

type ImportParameterMapping

type ImportParameterMapping struct {
	TfVariable    string `yaml:"tf_variable"`
	ParameterName string `yaml:"parameter_name"`
}

ImportParameterMapping mapping for tf variable to service parameter

type ImportResource

type ImportResource struct {
	TfResource   string
	IaaSResource string
}

ImportResource represents TF resource to IaaS resource ID mapping for import

type JobRunner

type JobRunner interface {
	StageJob(jobID string, workspace *workspace.TerraformWorkspace) error
	Import(ctx context.Context, id string, importResources []ImportResource) error
	Create(ctx context.Context, id string) error
	Update(ctx context.Context, id string, templateVars map[string]interface{}) error
	Destroy(ctx context.Context, id string, templateVars map[string]interface{}) error
	Status(ctx context.Context, id string) (bool, string, error)
	Outputs(ctx context.Context, id, instanceName string) (map[string]interface{}, error)
	Wait(ctx context.Context, id string) error
	Show(ctx context.Context, id string) (string, error)
}

type TfCatalogDefinitionV1

type TfCatalogDefinitionV1 []*TfServiceDefinitionV1

func (TfCatalogDefinitionV1) Validate

func (tfb TfCatalogDefinitionV1) Validate() (errs *validation.FieldError)

Validate checks the service definitions for semantic errors.

type TfJobRunner

type TfJobRunner struct {
	workspace.WorkspaceBuilder
	invoker.TerraformInvokerBuilder
	// contains filtered or unexported fields
}

TfJobRunner is responsible for executing terraform jobs in the background and providing a way to log and access the state of those background tasks.

Jobs are given an ID and a workspace to operate in, and then the TfJobRunner is told which Terraform commands to execute on the given job. The TfJobRunner executes those commands in the background and keeps track of their state in a database table which gets updated once the task is completed.

The TfJobRunner keeps track of the workspace and the Terraform state file so subsequent commands will operate on the same structure.

func NewTfJobRunner

func NewTfJobRunner(store broker.ServiceProviderStorage,
	tfBinContext executor.TFBinariesContext,
	workspaceFactory workspace.WorkspaceBuilder,
	invokerBuilder invoker.TerraformInvokerBuilder) *TfJobRunner

NewTfJobRunner constructs a new JobRunner for the given project.

func (*TfJobRunner) Create

func (runner *TfJobRunner) Create(ctx context.Context, id string) error

Create runs `terraform apply` on the given workspace in the background. The status of the job can be found by polling the Status function.

func (*TfJobRunner) DefaultInvoker added in v0.10.0

func (runner *TfJobRunner) DefaultInvoker() invoker.TerraformInvoker

func (*TfJobRunner) Destroy

func (runner *TfJobRunner) Destroy(ctx context.Context, id string, templateVars map[string]interface{}) error

Destroy runs `terraform destroy` on the given workspace in the background. The status of the job can be found by polling the Status function.

func (*TfJobRunner) Import

func (runner *TfJobRunner) Import(ctx context.Context, id string, importResources []ImportResource) error

Import runs `terraform import` and `terraform apply` on the given workspace in the background. The status of the job can be found by polling the Status function.

func (*TfJobRunner) Outputs

func (runner *TfJobRunner) Outputs(ctx context.Context, id, instanceName string) (map[string]interface{}, error)

Outputs gets the output variables for the given module instance in the workspace.

func (*TfJobRunner) Show

func (runner *TfJobRunner) Show(ctx context.Context, id string) (string, error)

Show returns the output from terraform show command

func (*TfJobRunner) StageJob

func (runner *TfJobRunner) StageJob(jobID string, workspace *workspace.TerraformWorkspace) error

StageJob stages a job to be executed. Before the workspace is saved to the database, the modules and inputs are validated by Terraform.

func (*TfJobRunner) Status

func (runner *TfJobRunner) Status(ctx context.Context, id string) (bool, string, error)

Status gets the status of the most recent job on the workspace. If isDone is true, then the status of the operation will not change again. if isDone is false, then the operation is ongoing.

func (*TfJobRunner) Update

func (runner *TfJobRunner) Update(ctx context.Context, id string, templateVars map[string]interface{}) error

func (*TfJobRunner) VersionedInvoker added in v0.10.0

func (runner *TfJobRunner) VersionedInvoker(version *version.Version) invoker.TerraformInvoker

func (*TfJobRunner) Wait

func (runner *TfJobRunner) Wait(ctx context.Context, id string) error

Wait waits for an operation to complete, polling its status once per second.

type TfServiceDefinitionV1

type TfServiceDefinitionV1 struct {
	Version           int                         `yaml:"version"`
	Name              string                      `yaml:"name"`
	ID                string                      `yaml:"id"`
	Description       string                      `yaml:"description"`
	DisplayName       string                      `yaml:"display_name"`
	ImageURL          string                      `yaml:"image_url"`
	DocumentationURL  string                      `yaml:"documentation_url"`
	SupportURL        string                      `yaml:"support_url"`
	Tags              []string                    `yaml:"tags,flow"`
	Plans             []TfServiceDefinitionV1Plan `yaml:"plans"`
	ProvisionSettings TfServiceDefinitionV1Action `yaml:"provision"`
	BindSettings      TfServiceDefinitionV1Action `yaml:"bind"`
	Examples          []broker.ServiceExample     `yaml:"examples"`
	PlanUpdateable    bool                        `yaml:"plan_updateable"`

	// Internal SHOULD be set to true for Google maintained services.
	Internal        bool `yaml:"-"`
	RequiredEnvVars []string
}

TfServiceDefinitionV1 is the first version of user defined services.

func NewExampleTfServiceDefinition

func NewExampleTfServiceDefinition() TfServiceDefinitionV1

NewExampleTfServiceDefinition creates a new service defintition with sample values for the service broker suitable to give a user a template to manually edit.

func (*TfServiceDefinitionV1) ToService

ToService converts the flat TfServiceDefinitionV1 into a broker.ServiceDefinition that the registry can use.

func (*TfServiceDefinitionV1) Validate

func (tfb *TfServiceDefinitionV1) Validate() (errs *validation.FieldError)

Validate checks the service definition for semantic errors.

type TfServiceDefinitionV1Action

type TfServiceDefinitionV1Action struct {
	PlanInputs               []broker.BrokerVariable      `yaml:"plan_inputs"`
	UserInputs               []broker.BrokerVariable      `yaml:"user_inputs"`
	Computed                 []varcontext.DefaultVariable `yaml:"computed_inputs"`
	Template                 string                       `yaml:"template"`
	TemplateRef              string                       `yaml:"template_ref"`
	Outputs                  []broker.BrokerVariable      `yaml:"outputs"`
	Templates                map[string]string            `yaml:"templates"`
	TemplateRefs             map[string]string            `yaml:"template_refs"`
	ImportVariables          []broker.ImportVariable      `yaml:"import_inputs"`
	ImportParameterMappings  []ImportParameterMapping     `yaml:"import_parameter_mappings"`
	ImportParametersToDelete []string                     `yaml:"import_parameters_to_delete"`
	ImportParametersToAdd    []ImportParameterMapping     `yaml:"import_parameters_to_add"`
}

TfServiceDefinitionV1Action holds information needed to process user inputs for a single provision or bind call.

func (*TfServiceDefinitionV1Action) IsTfImport

func (action *TfServiceDefinitionV1Action) IsTfImport(provisionContext *varcontext.VarContext) bool

func (*TfServiceDefinitionV1Action) LoadTemplate

func (action *TfServiceDefinitionV1Action) LoadTemplate(srcDir string) error

LoadTemplate loads template ref into template if provided

func (*TfServiceDefinitionV1Action) Validate

func (action *TfServiceDefinitionV1Action) Validate() (errs *validation.FieldError)

Validate implements validation.Validatable.

func (*TfServiceDefinitionV1Action) ValidateTemplateIO

func (action *TfServiceDefinitionV1Action) ValidateTemplateIO() (errs *validation.FieldError)

type TfServiceDefinitionV1Plan

type TfServiceDefinitionV1Plan struct {
	Name               string                 `yaml:"name"`
	ID                 string                 `yaml:"id"`
	Description        string                 `yaml:"description"`
	DisplayName        string                 `yaml:"display_name"`
	Bullets            []string               `yaml:"bullets,omitempty"`
	Free               bool                   `yaml:"free,omitempty"`
	Properties         map[string]interface{} `yaml:"properties"`
	ProvisionOverrides map[string]interface{} `yaml:"provision_overrides,omitempty"`
	BindOverrides      map[string]interface{} `yaml:"bind_overrides,omitempty"`
}

TfServiceDefinitionV1Plan represents a service plan in a human-friendly format that can be converted into an OSB compatible plan.

func (*TfServiceDefinitionV1Plan) ToPlan

ToPlan converts this plan definition to a broker.ServicePlan.

func (*TfServiceDefinitionV1Plan) Validate

func (plan *TfServiceDefinitionV1Plan) Validate() (errs *validation.FieldError)

Validate implements validation.Validatable.

Directories

Path Synopsis
executorfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
invokerfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
Code generated by counterfeiter.
workspacefakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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