tf

package
v4.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func NewTerraformProvider

func NewTerraformProvider(jobRunner *TfJobRunner, logger lager.Logger, serviceDefinition TfServiceDefinitionV1) broker.ServiceProvider

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

Types

type TfJobRunner

type TfJobRunner struct {
	ProjectId      string
	ServiceAccount string

	// Executor holds a custom executor that will be called when commands are run.
	Executor wrapper.TerraformExecutor
}

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 NewTfJobRunerFromEnv

func NewTfJobRunerFromEnv() (*TfJobRunner, error)

NewTfJobRunerFromEnv creates a new TfJobRunner with default configuration values.

func NewTfJobRunnerForProject

func NewTfJobRunnerForProject(projectId string) *TfJobRunner

Construct 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) Destroy

func (runner *TfJobRunner) Destroy(ctx context.Context, id string) 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) 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) StageJob

func (runner *TfJobRunner) StageJob(ctx context.Context, jobId string, workspace *wrapper.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) (isDone bool, err 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) 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" validate:"required,eq=1"`
	Name              string                      `yaml:"name" validate:"required"`
	Id                string                      `yaml:"id" validate:"required,uuid"`
	Description       string                      `yaml:"description" validate:"required"`
	DisplayName       string                      `yaml:"display_name" validate:"required"`
	ImageUrl          string                      `yaml:"image_url" validate:"url"`
	DocumentationUrl  string                      `yaml:"documentation_url" validate:"url"`
	SupportUrl        string                      `yaml:"support_url" validate:"url"`
	Tags              []string                    `yaml:"tags,flow"`
	Plans             []TfServiceDefinitionV1Plan `yaml:"plans" validate:"required,dive"`
	ProvisionSettings TfServiceDefinitionV1Action `yaml:"provision" validate:"required,dive"`
	BindSettings      TfServiceDefinitionV1Action `yaml:"bind" validate:"required,dive"`
	Examples          []broker.ServiceExample     `yaml:"examples" validate:"required,dive"`

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

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() error

Validate checks the service definition for semantic errors.

type TfServiceDefinitionV1Action

type TfServiceDefinitionV1Action struct {
	PlanInputs []broker.BrokerVariable      `yaml:"plan_inputs" validate:"dive"`
	UserInputs []broker.BrokerVariable      `yaml:"user_inputs" validate:"dive"`
	Computed   []varcontext.DefaultVariable `yaml:"computed_inputs" validate:"dive"`
	Template   string                       `yaml:"template" validate:"hcl"`
	Outputs    []broker.BrokerVariable      `yaml:"outputs" validate:"dive"`
}

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

func (*TfServiceDefinitionV1Action) ValidateTemplateIO

func (action *TfServiceDefinitionV1Action) ValidateTemplateIO() error

ValidateTemplateIO makes sure that the inputs supplied by the user are a superset of the inputs needed by the Terraform template, and the template outputs match the outputs.

type TfServiceDefinitionV1Plan

type TfServiceDefinitionV1Plan struct {
	Name        string            `yaml:"name" validate:"required"`
	Id          string            `yaml:"id" validate:"required,uuid"`
	Description string            `yaml:"description" validate:"required"`
	DisplayName string            `yaml:"display_name" validate:"required"`
	Bullets     []string          `yaml:"bullets,omitempty"`
	Free        bool              `yaml:"free,omitempty"`
	Properties  map[string]string `yaml:"properties" validate:"required"`
}

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

func (*TfServiceDefinitionV1Plan) ToPlan

Converts this plan definition to a broker.ServicePlan.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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