commons

package
v3.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSSHPrivateKeyFilePath is the default SSH private Key file path
	// used to connect to provisioned resources
	DefaultSSHPrivateKeyFilePath = "~/.ssh/yorc.pem"
	// NullPluginVersionConstraint is the Terraform null plugin version constraint
	NullPluginVersionConstraint = "~> 1.0"
	// DefaultConsulProviderAddress is Default Address to use  for Terraform Consul Provider
	DefaultConsulProviderAddress = "127.0.0.1:8500"
)
View Source
const FileOutputPrefix = "file:"

FileOutputPrefix is the prefix to identify file output

Variables

This section is empty.

Functions

func AddConnectionCheckResource

func AddConnectionCheckResource(infrastructure *Infrastructure, user string, privateKey *sshutil.PrivateKey, accessIP, resourceName string, env *[]string) error

AddConnectionCheckResource builds a null specific resource to check SSH connection with SSH key passed via env variable

func AddOutput

func AddOutput(infrastructure *Infrastructure, outputName string, output *Output)

AddOutput allows to add an Output to a defined Infrastructure

func AddResource

func AddResource(infrastructure *Infrastructure, resourceType, resourceName string, resource interface{})

AddResource allows to add a Resource to a defined Infrastructure

func GetBackendConfiguration

func GetBackendConfiguration(path string, cfg config.Configuration) map[string]interface{}

GetBackendConfiguration returns the Terraform Backend configuration to store the state in the Consul KV store at a given path

func GetConnInfoFromEndpointCredentials

func GetConnInfoFromEndpointCredentials(ctx context.Context, kv *api.KV, deploymentID, nodeName string) (string, *sshutil.PrivateKey, error)

GetConnInfoFromEndpointCredentials allow to retrieve user and private key path for connection needs from endpoint credentials

func GetConsulProviderfiguration

func GetConsulProviderfiguration(cfg config.Configuration) map[string]interface{}

GetConsulProviderfiguration returns the Terraform Consul Provider configuration

func PreDestroyStorageInfraCallback

func PreDestroyStorageInfraCallback(ctx context.Context, kv *api.KV, cfg config.Configuration, deploymentID, nodeName, infrastructurePath string) (bool, error)

PreDestroyStorageInfraCallback is a callback of type PreDestroyInfraCallback checking if a block storage node is deletable on undeployment.

func SSHAgentFromContext added in v3.2.4

func SSHAgentFromContext(ctx context.Context) (*sshutil.SSHAgent, bool)

SSHAgentFromContext retrieves an sshutil.SSHAgent from the given Context

func StoreSSHAgentInContext added in v3.2.4

func StoreSSHAgentInContext(ctx context.Context, agent *sshutil.SSHAgent) context.Context

StoreSSHAgentInContext allows to store an sshutil.SSHAgent into the given Context

Types

type Connection

type Connection struct {
	ConnType   string `json:"type,omitempty"`
	User       string `json:"user,omitempty"`
	Password   string `json:"password,omitempty"`
	Host       string `json:"host,omitempty"`
	Port       string `json:"port,omitempty"`
	Timeout    string `json:"timeout,omitempty"` // defaults to "5m"
	PrivateKey string `json:"private_key,omitempty"`
}

A Connection allows to overwrite the way Terraform connects to a resource

type ConsulKey

type ConsulKey struct {
	Path string `json:"path"`

	// Should only be use in datasource (read) mode, this is the name to use to access this key within the terraform interpolation syntax
	Name string `json:"name,omitempty"`

	Default string `json:"default,omitempty"`

	Value string `json:"value,omitempty"`

	// Should only be use in resource (write) mode, deletes the key
	Delete bool `json:"delete,omitempty"`
}

A ConsulKey can be used in a ConsulKeys 'resource' to writes or a ConsulKeys 'data' to read an individual Key/Value pair into Consul

type ConsulKeys

type ConsulKeys struct {
	Resource
	Datacenter string      `json:"datacenter,omitempty"`
	Token      string      `json:"token,omitempty"`
	Keys       []ConsulKey `json:"key"`
}

The ConsulKeys can be used as 'resource' to writes or 'data' to read sets of individual values into Consul.

type Generator

type Generator interface {
	// GenerateTerraformInfraForNode generates the Terraform infrastructure file for the given node.
	// It returns 'true' if a file was generated and 'false' otherwise (in case of a infrastructure component
	// already exists for this node and should just be reused).
	// GenerateTerraformInfraForNode can also return a map of outputs names indexed by consul keys into which the outputs results should be stored.
	// And a list of environment variables in form "key=value" to be added to the current process environment when running terraform commands.
	// This is particularly useful for adding secrets that should not be in tf files.
	// It returns too a callback function allowing execution some cleanup stuff once the infrastructure has been applied
	GenerateTerraformInfraForNode(ctx context.Context, cfg config.Configuration, deploymentID, nodeName, infrastructurePath string) (bool, map[string]string, []string, PostApplyCallback, error)
}

A Generator is used to generate the Terraform infrastructure for a given TOSCA node

type Infrastructure

type Infrastructure struct {
	Terraform map[string]interface{} `json:"terraform,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
	Variable  map[string]interface{} `json:"variable,omitempty"`
	Provider  map[string]interface{} `json:"provider,omitempty"`
	Resource  map[string]interface{} `json:"resource,omitempty"`
	Output    map[string]*Output     `json:"output,omitempty"`
}

An Infrastructure is the top-level element of a Terraform infrastructure definition

type LocalExec

type LocalExec struct {
	Command     string                 `json:"command"`
	WorkingDir  string                 `json:"working_dir,omitempty"`
	Interpreter string                 `json:"interpreter,omitempty"`
	Environment map[string]interface{} `json:"environment,omitempty"`
}

LocalExec allows to invoke a local executable after a resource is created. This invokes a process on the machine running Terraform, not on the resource

type Output

type Output struct {
	// Value is the value of the output. This can be a string, list, or map.
	// This usually includes an interpolation since outputs that are static aren't usually useful.
	Value     interface{} `json:"value"`
	Sensitive bool        `json:"sensitive,omitempty"`
}

An Output allows to define a terraform output value

type PostApplyCallback

type PostApplyCallback func()

PostApplyCallback is a callback function called after Terraform apply execution

type PreDestroyInfraCallback

type PreDestroyInfraCallback func(ctx context.Context, kv *api.KV, cfg config.Configuration, deploymentID, nodeName, infrastructurePath string) (bool, error)

PreDestroyInfraCallback is a function that is call before destroying an infrastructure. If it returns false the node will not be destroyed.

type RemoteExec

type RemoteExec struct {
	Connection *Connection `json:"connection,omitempty"`
	Inline     []string    `json:"inline,omitempty"`
	Script     string      `json:"script,omitempty"`
	Scripts    []string    `json:"scripts,omitempty"`
}

The RemoteExec provisioner invokes a script on a remote resource after it is created.

The remote-exec provisioner supports both ssh and winrm type connections.

type Resource

type Resource struct {
	Count        int                      `json:"count,omitempty"`
	DependsOn    []string                 `json:"depends_on,omitempty"`
	Connection   *Connection              `json:"connection,omitempty"`
	Provisioners []map[string]interface{} `json:"provisioner,omitempty"`
}

A Resource is the base type for terraform resources

Jump to

Keyboard shortcuts

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