terraform

package
v0.1.0-alpha3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package Terraform defines an SDK for running Terraform commands using the Terraform CLI binary.

Index

Constants

This section is empty.

Variables

View Source
var ModuleSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name: "source",
		},
		{
			Name: "version",
		},
		{
			Name: "providers",
		},
	},
}

ModuleSchema is the schema for the module block.

View Source
var ResourceSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name: "provider",
		},
	},
}

ResourceSchema is the schema for the resource block.

View Source
var RootSchema = &hcl.BodySchema{
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "terraform",
			LabelNames: nil,
		},
		{
			Type: "locals",
		},
		{
			Type:       "variable",
			LabelNames: []string{"name"},
		},
		{
			Type:       "output",
			LabelNames: []string{"name"},
		},
		{
			Type:       "provider",
			LabelNames: []string{"name"},
		},
		{
			Type:       "resource",
			LabelNames: []string{"type", "name"},
		},
		{
			Type:       "data",
			LabelNames: []string{"type", "name"},
		},
		{
			Type:       "module",
			LabelNames: []string{"name"},
		},
	},
}

RootSchema is the Terraform root schema.

View Source
var TerraformSchema = &hcl.BodySchema{
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "backend",
			LabelNames: []string{"type"},
		},
		{
			Type: "required_providers",
		},
	},
}

TerraformSchema is the schema for the terraform block.

Functions

func FormatOutputForGitHubDiff

func FormatOutputForGitHubDiff(content string) string

FormatOutputForGitHubDiff formats the Terraform diff output for use with GitHub diff markdown formatting.

Types

type ApplyOptions

type ApplyOptions struct {
	File            *string
	AutoApprove     *bool
	CompactWarnings *bool
	Lock            *bool
	LockTimeout     *string
	Input           *bool
	NoColor         *bool
}

ApplyOptions are the set of options for running a terraform apply.

type InitOptions

type InitOptions struct {
	Backend     *bool
	Input       *bool
	NoColor     *bool
	Lock        *bool
	LockTimeout *string
	Lockfile    *string
}

InitOptions are the set of options for running a terraform init.

type MockTerraformClient

type MockTerraformClient struct {
	InitResponse     *MockTerraformResponse
	ValidateResponse *MockTerraformResponse
	PlanResponse     *MockTerraformResponse
	ApplyResponse    *MockTerraformResponse
	ShowResponse     *MockTerraformResponse
}

MockTerraformClient creates a mock TerraformClient for use with testing.

func (*MockTerraformClient) Apply

func (m *MockTerraformClient) Apply(ctx context.Context, stdout, stderr io.Writer, opts *ApplyOptions) (int, error)

func (*MockTerraformClient) Init

func (m *MockTerraformClient) Init(ctx context.Context, stdout, stderr io.Writer, opts *InitOptions) (int, error)

func (*MockTerraformClient) Plan

func (m *MockTerraformClient) Plan(ctx context.Context, stdout, stderr io.Writer, opts *PlanOptions) (int, error)

func (*MockTerraformClient) Show

func (m *MockTerraformClient) Show(ctx context.Context, stdout, stderr io.Writer, opts *ShowOptions) (int, error)

func (*MockTerraformClient) Validate

func (m *MockTerraformClient) Validate(ctx context.Context, stdout, stderr io.Writer, opts *ValidateOptions) (int, error)

type MockTerraformResponse

type MockTerraformResponse struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Err      error
}

type PlanOptions

type PlanOptions struct {
	CompactWarnings  *bool
	DetailedExitcode *bool
	NoColor          *bool
	Input            *bool
	Lock             *bool
	LockTimeout      *string
	Out              *string
}

PlanOptions are the set of options for running a terraform plan.

type ShowOptions

type ShowOptions struct {
	File    *string
	NoColor *bool
	JSON    *bool
}

ShowOptions are the set of options for running a terraform show.

type Terraform

type Terraform interface {
	// Init runs the terraform init command.
	Init(context.Context, io.Writer, io.Writer, *InitOptions) (int, error)

	// Validate runs the terraform validate command.
	Validate(context.Context, io.Writer, io.Writer, *ValidateOptions) (int, error)

	// Plan runs the terraform plan command.
	Plan(context.Context, io.Writer, io.Writer, *PlanOptions) (int, error)

	// Apply runs the terraform apply command.
	Apply(context.Context, io.Writer, io.Writer, *ApplyOptions) (int, error)

	// Show runs the terraform show command.
	Show(context.Context, io.Writer, io.Writer, *ShowOptions) (int, error)
}

Terraform is the interface for working with the Terraform CLI.

type TerraformBackendConfig

type TerraformBackendConfig struct {
	GCSBucket *string `hcl:"bucket,attr"`
	Prefix    *string `hcl:"prefix,attr"`
}

TerraformBackendConfig represents the terraform backend config block.

func ExtractBackendConfig

func ExtractBackendConfig(path string) (*TerraformBackendConfig, hcl.Diagnostics, error)

ExtractBackendConfig extracts the backend configuration from the backend block.

type TerraformClient

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

TerraformClient implements the Terraform interface.

func NewTerraformClient

func NewTerraformClient(workingDir string) *TerraformClient

NewTerraformClient creates a new Terraform client.

func (*TerraformClient) Apply

func (t *TerraformClient) Apply(ctx context.Context, stdout, stderr io.Writer, opts *ApplyOptions) (int, error)

Apply runs the Terraform apply command.

func (*TerraformClient) Init

func (t *TerraformClient) Init(ctx context.Context, stdout, stderr io.Writer, opts *InitOptions) (int, error)

Init runs the terraform init command.

func (*TerraformClient) Plan

func (t *TerraformClient) Plan(ctx context.Context, stdout, stderr io.Writer, opts *PlanOptions) (int, error)

Plan runs the Terraform plan command.

func (*TerraformClient) Show

func (t *TerraformClient) Show(ctx context.Context, stdout, stderr io.Writer, opts *ShowOptions) (int, error)

Show runs the Terraform show command.

func (*TerraformClient) Validate

func (t *TerraformClient) Validate(ctx context.Context, stdout, stderr io.Writer, opts *ValidateOptions) (int, error)

Validate runs the terraform validate command.

type TerraformEntrypoint

type TerraformEntrypoint struct {
	Path        string
	BackendFile string
}

func GetEntrypointDirectories

func GetEntrypointDirectories(rootDir string) ([]*TerraformEntrypoint, error)

GetEntrypointDirectories gets all the directories that have Terraform config files containing a backend block to be used as an entrypoint module.

type TerraformResponse

type TerraformResponse struct {
	Stdout   io.Reader
	Stderr   io.Reader
	ExitCode int
}

TerraformResponse is the response from running a terraform command.

type ValidateOptions

type ValidateOptions struct {
	NoColor *bool
	JSON    *bool
}

ValidateOptions are the set of options for running a terraform validate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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