terraform

package
v2.8.0-pre Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package terraform handles creation/destruction of a Constellation cluster using Terraform.

Since Terraform does not provide a stable Go API, we use the `terraform-exec` package to interact with Terraform.

The Terraform templates are located in the "terraform" subdirectory. The templates are embedded into the CLI binary using `go:embed`. On use the relevant template is extracted to the working directory and the user customized variables are written to a `terraform.tfvars` file.

Index

Constants

This section is empty.

Variables

View Source
var ErrTerraformWorkspaceDifferentFiles = errors.New("creating cluster: trying to overwrite an existing Terraform file with a different version")

ErrTerraformWorkspaceDifferentFiles is returned when a re-used existing Terraform workspace has different files than the ones to be extracted (e.g. due to a version mix-up or incomplete writes).

View Source
var ErrTerraformWorkspaceExistsWithDifferentVariables = errors.New("creating cluster: a Terraform workspace already exists with different variables")

ErrTerraformWorkspaceExistsWithDifferentVariables is returned when existing Terraform files differ from the version the CLI wants to extract.

Functions

func GetExecutable

func GetExecutable(ctx context.Context, workingDir string) (terraform *tfexec.Terraform, remove func(), err error)

GetExecutable returns a Terraform executable either from the local filesystem, or downloads the latest version fulfilling the version constraint.

Types

type AWSClusterVariables added in v2.3.0

type AWSClusterVariables struct {
	// CommonVariables contains common variables.
	CommonVariables
	// Region is the AWS region to use.
	Region string
	// Zone is the AWS zone to use in the given region.
	Zone string
	// AMIImageID is the ID of the AMI image to use.
	AMIImageID string
	// InstanceType is the type of the EC2 instance to use.
	InstanceType string
	// StateDiskType is the EBS disk type to use for the state disk.
	StateDiskType string
	// IAMGroupControlPlane is the IAM group to use for the control-plane nodes.
	IAMProfileControlPlane string
	// IAMGroupWorkerNodes is the IAM group to use for the worker nodes.
	IAMProfileWorkerNodes string
	// Debug is true if debug mode is enabled.
	Debug bool
}

AWSClusterVariables is user configuration for creating a cluster with Terraform on GCP.

func (*AWSClusterVariables) String added in v2.3.0

func (v *AWSClusterVariables) String() string

type AWSIAMOutput added in v2.3.0

type AWSIAMOutput struct {
	ControlPlaneInstanceProfile string
	WorkerNodeInstanceProfile   string
}

AWSIAMOutput contains the output information of the Terraform IAM operation on GCP.

type AWSIAMVariables added in v2.3.0

type AWSIAMVariables struct {
	// Region is the AWS location to use. (e.g. us-east-2)
	Region string
	// Prefix is the name prefix of the resources to use.
	Prefix string
}

AWSIAMVariables is user configuration for creating the IAM configuration with Terraform on Microsoft Azure.

func (*AWSIAMVariables) String added in v2.3.0

func (v *AWSIAMVariables) String() string

String returns a string representation of the IAM-specific variables, formatted as Terraform variables.

type AzureClusterVariables added in v2.3.0

type AzureClusterVariables struct {
	// CommonVariables contains common variables.
	CommonVariables

	// ResourceGroup is the name of the Azure resource group to use.
	ResourceGroup string
	// Location is the Azure location to use.
	Location string
	// UserAssignedIdentity is the name of the Azure user-assigned identity to use.
	UserAssignedIdentity string
	// InstanceType is the Azure instance type to use.
	InstanceType string
	// StateDiskType is the Azure disk type to use for the state disk.
	StateDiskType string
	// ImageID is the ID of the Azure image to use.
	ImageID string
	// ConfidentialVM sets the VM to be confidential.
	ConfidentialVM bool
	// SecureBoot sets the VM to use secure boot.
	SecureBoot bool
	// CreateMAA sets whether a Microsoft Azure attestation provider should be created.
	CreateMAA bool
	// Debug is true if debug mode is enabled.
	Debug bool
}

AzureClusterVariables is user configuration for creating a cluster with Terraform on Azure.

func (*AzureClusterVariables) String added in v2.3.0

func (v *AzureClusterVariables) String() string

String returns a string representation of the variables, formatted as Terraform variables.

type AzureIAMOutput added in v2.3.0

type AzureIAMOutput struct {
	SubscriptionID               string
	TenantID                     string
	ApplicationID                string
	UAMIID                       string
	ApplicationClientSecretValue string
}

AzureIAMOutput contains the output information of the Terraform IAM operation on Microsoft Azure.

type AzureIAMVariables added in v2.3.0

type AzureIAMVariables struct {
	// Region is the Azure region to use. (e.g. westus)
	Region string
	// ServicePrincipal is the name of the service principal to use.
	ServicePrincipal string
	// ResourceGroup is the name of the resource group to use.
	ResourceGroup string
}

AzureIAMVariables is user configuration for creating the IAM configuration with Terraform on Microsoft Azure.

func (*AzureIAMVariables) String added in v2.3.0

func (v *AzureIAMVariables) String() string

String returns a string representation of the IAM-specific variables, formatted as Terraform variables.

type Client

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

Client manages interaction with Terraform.

func New

func New(ctx context.Context, workingDir string) (*Client, error)

New sets up a new Client for Terraform.

func (*Client) CleanUpWorkspace

func (c *Client) CleanUpWorkspace() error

CleanUpWorkspace removes terraform files from the current directory.

func (*Client) CreateCluster

func (c *Client) CreateCluster(ctx context.Context) (CreateOutput, error)

CreateCluster creates a Constellation cluster using Terraform.

func (*Client) CreateIAMConfig added in v2.3.0

func (c *Client) CreateIAMConfig(ctx context.Context, provider cloudprovider.Provider) (IAMOutput, error)

CreateIAMConfig creates an IAM configuration using Terraform.

func (*Client) Destroy added in v2.5.3

func (c *Client) Destroy(ctx context.Context) error

Destroy destroys Terraform-created cloud resources.

func (*Client) PrepareWorkspace added in v2.3.0

func (c *Client) PrepareWorkspace(path string, vars Variables) error

PrepareWorkspace prepares a Terraform workspace for a Constellation cluster.

func (*Client) RemoveInstaller

func (c *Client) RemoveInstaller()

RemoveInstaller removes the Terraform installer, if it was downloaded for this command.

func (*Client) Show added in v2.6.0

func (c *Client) Show(ctx context.Context) (*tfjson.State, error)

Show reads the default state path and outputs the state.

type CommonVariables

type CommonVariables struct {
	// Name of the cluster.
	Name string
	// CountControlPlanes is the number of control-plane nodes to create.
	CountControlPlanes int
	// CountWorkers is the number of worker nodes to create.
	CountWorkers int
	// StateDiskSizeGB is the size of the state disk to allocate to each node, in GB.
	StateDiskSizeGB int
}

CommonVariables is user configuration for creating a cluster with Terraform.

func (*CommonVariables) String

func (v *CommonVariables) String() string

String returns a string representation of the variables, formatted as Terraform variables.

type CreateOutput added in v2.5.0

type CreateOutput struct {
	IP     string
	Secret string
	UID    string
	// AttestationURL is the URL of the attestation provider.
	// It is only set if the cluster is created on Azure.
	AttestationURL string
}

CreateOutput contains the Terraform output values of a cluster creation.

type GCPClusterVariables added in v2.3.0

type GCPClusterVariables struct {
	// CommonVariables contains common variables.
	CommonVariables

	// Project is the ID of the GCP project to use.
	Project string
	// Region is the GCP region to use.
	Region string
	// Zone is the GCP zone to use.
	Zone string
	// CredentialsFile is the path to the GCP credentials file.
	CredentialsFile string
	// InstanceType is the GCP instance type to use.
	InstanceType string
	// StateDiskType is the GCP disk type to use for the state disk.
	StateDiskType string
	// ImageID is the ID of the GCP image to use.
	ImageID string
	// Debug is true if debug mode is enabled.
	Debug bool
}

GCPClusterVariables is user configuration for creating resources with Terraform on GCP.

func (*GCPClusterVariables) String added in v2.3.0

func (v *GCPClusterVariables) String() string

String returns a string representation of the variables, formatted as Terraform variables.

type GCPIAMOutput added in v2.3.0

type GCPIAMOutput struct {
	SaKey string
}

GCPIAMOutput contains the output information of the Terraform IAM operation on GCP.

type GCPIAMVariables added in v2.3.0

type GCPIAMVariables struct {
	// Project is the ID of the GCP project to use.
	Project string
	// Region is the GCP region to use.
	Region string
	// Zone is the GCP zone to use.
	Zone string
	// ServiceAccountID is the ID of the service account to use.
	ServiceAccountID string
}

GCPIAMVariables is user configuration for creating the IAM confioguration with Terraform on GCP.

func (*GCPIAMVariables) String added in v2.3.0

func (v *GCPIAMVariables) String() string

String returns a string representation of the IAM-specific variables, formatted as Terraform variables.

type IAMOutput added in v2.3.0

type IAMOutput struct {
	GCP   GCPIAMOutput
	Azure AzureIAMOutput
	AWS   AWSIAMOutput
}

IAMOutput contains the output information of the Terraform IAM operations.

type OpenStackClusterVariables added in v2.6.0

type OpenStackClusterVariables struct {
	// CommonVariables contains common variables.
	CommonVariables

	// Cloud is the (optional) name of the OpenStack cloud to use when reading the "clouds.yaml" configuration file. If empty, environment variables are used.
	Cloud string
	// AvailabilityZone is the OpenStack availability zone to use.
	AvailabilityZone string
	// Flavor is the ID of the OpenStack flavor (machine type) to use.
	FlavorID string
	// FloatingIPPoolID is the ID of the OpenStack floating IP pool to use for public IPs.
	FloatingIPPoolID string
	// ImageURL is the URL of the OpenStack image to use.
	ImageURL string
	// DirectDownload decides whether to download the image directly from the URL to OpenStack or to upload it from the local machine.
	DirectDownload bool
	// OpenstackUserDomainName is the OpenStack user domain name to use.
	OpenstackUserDomainName string
	// OpenstackUsername is the OpenStack user name to use.
	OpenstackUsername string
	// OpenstackPassword is the OpenStack password to use.
	OpenstackPassword string
	// Debug is true if debug mode is enabled.
	Debug bool
}

OpenStackClusterVariables is user configuration for creating a cluster with Terraform on OpenStack.

func (*OpenStackClusterVariables) String added in v2.6.0

func (v *OpenStackClusterVariables) String() string

String returns a string representation of the variables, formatted as Terraform variables.

type QEMUVariables

type QEMUVariables struct {
	// CommonVariables contains common variables.
	CommonVariables

	// LibvirtURI is the libvirt connection URI.
	LibvirtURI string
	// LibvirtSocketPath is the path to the libvirt socket in case of unix socket.
	LibvirtSocketPath string
	// CPUCount is the number of CPUs to allocate to each node.
	CPUCount int
	// MemorySizeMiB is the amount of memory to allocate to each node, in MiB.
	MemorySizeMiB int
	// IPRangeStart is the first IP address in the IP range to allocate to the cluster.
	ImagePath string
	// ImageFormat is the format of the image from ImagePath.
	ImageFormat string
	// MetadataAPIImage is the container image to use for the metadata API.
	MetadataAPIImage string
	// MetadataLibvirtURI is the libvirt connection URI used by the metadata container.
	// In case of unix socket, this should be "qemu:///system".
	// Other wise it should be the same as LibvirtURI.
	MetadataLibvirtURI string
	// NVRAM is the path to the NVRAM template.
	NVRAM string
	// Firmware is the path to the firmware.
	Firmware string
}

QEMUVariables is user configuration for creating a QEMU cluster with Terraform.

func (*QEMUVariables) String

func (v *QEMUVariables) String() string

String returns a string representation of the variables, formatted as Terraform variables.

type Variables

type Variables interface {
	fmt.Stringer
}

Variables is a struct that holds all variables that are passed to Terraform.

Jump to

Keyboard shortcuts

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