Documentation ¶
Overview ¶
Package Terraform defines an SDK for running Terraform commands using the Terraform CLI binary.
Index ¶
- Variables
- func FormatOutputForGitHubDiff(content string) string
- type ApplyOptions
- type FormatOptions
- type InitOptions
- type MockTerraformClient
- func (m *MockTerraformClient) Apply(ctx context.Context, stdout, stderr io.Writer, opts *ApplyOptions) (int, error)
- func (m *MockTerraformClient) Format(ctx context.Context, stdout, stderr io.Writer, opts *FormatOptions) (int, error)
- func (m *MockTerraformClient) Init(ctx context.Context, stdout, stderr io.Writer, opts *InitOptions) (int, error)
- func (m *MockTerraformClient) Plan(ctx context.Context, stdout, stderr io.Writer, opts *PlanOptions) (int, error)
- func (m *MockTerraformClient) Run(ctx context.Context, stdout, stderr io.Writer, subcommand string, ...) (int, error)
- func (m *MockTerraformClient) Show(ctx context.Context, stdout, stderr io.Writer, opts *ShowOptions) (int, error)
- func (m *MockTerraformClient) Validate(ctx context.Context, stdout, stderr io.Writer, opts *ValidateOptions) (int, error)
- type MockTerraformResponse
- type ModuleUsageGraph
- type Modules
- type PlanOptions
- type ShowOptions
- type Terraform
- type TerraformBackendConfig
- type TerraformClient
- func (t *TerraformClient) Apply(ctx context.Context, stdout, stderr io.Writer, opts *ApplyOptions) (int, error)
- func (t *TerraformClient) Format(ctx context.Context, stdout, stderr io.Writer, opts *FormatOptions) (int, error)
- func (t *TerraformClient) Init(ctx context.Context, stdout, stderr io.Writer, opts *InitOptions) (int, error)
- func (t *TerraformClient) Plan(ctx context.Context, stdout, stderr io.Writer, opts *PlanOptions) (int, error)
- func (t *TerraformClient) Run(ctx context.Context, stdout, stderr io.Writer, subcommand string, ...) (int, error)
- func (t *TerraformClient) Show(ctx context.Context, stdout, stderr io.Writer, opts *ShowOptions) (int, error)
- func (t *TerraformClient) Validate(ctx context.Context, stdout, stderr io.Writer, opts *ValidateOptions) (int, error)
- type TerraformEntrypoint
- type TerraformResponse
- type ValidateOptions
Constants ¶
This section is empty.
Variables ¶
var InitRequiredCommands = map[string]struct{}{
"validate": {},
"plan": {},
"apply": {},
"destroy": {},
"console": {},
"graph": {},
"import": {},
"output": {},
"providers": {},
"refresh": {},
"show": {},
"state": {},
"taint": {},
"untaint": {},
"workspace": {},
}
InitRequiredCommands are the Terraform commands that require terraform init to be run first.
var ModuleSchema = &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: "source",
},
{
Name: "version",
},
{
Name: "providers",
},
},
}
ModuleSchema is the schema for the module block.
var ResourceSchema = &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: "provider",
},
},
}
ResourceSchema is the schema for the resource block.
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.
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 ¶
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 FormatOptions ¶
type FormatOptions struct { Check *bool Diff *bool List *bool NoColor *bool Recursive *bool Write *bool }
FormatOptions are the set of options for running terraform format.
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 FormatResponse *MockTerraformResponse RunResponse *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) Format ¶
func (m *MockTerraformClient) Format(ctx context.Context, stdout, stderr io.Writer, opts *FormatOptions) (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 ModuleUsageGraph ¶
type ModuleUsageGraph struct { // EntrypointToModules is the complete list of all modules used by a terraform entrypoint at any depth. EntrypointToModules map[string]map[string]struct{} // ModulesToEntrypoints is the complete list of all terraform entrypoints that use a particular module at any depth. ModulesToEntrypoints map[string]map[string]struct{} }
ModuleUsageGraph describes which entrypoints use which modules and which modules are used by each entrypoint.
func ModuleUsage ¶
func ModuleUsage(ctx context.Context, rootDir string, maxDepth *int, skipUnresolvableModules bool) (*ModuleUsageGraph, error)
ModuleUsage locates all the usages of modules in all terraform entrypoints and vice versa.
type Modules ¶
type Modules struct { // ModulePaths is the list of all modules used in the particular terraform or module entrypoint. ModulePaths map[string]struct{} }
Modules represents the details of the modules used by a given module or terraform entrypoint.
func ExtractModules ¶
ExtractModules extracts the details about the modules used in a particular file.
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 ¶
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) // Format runs the terraform fmt command. Format(context.Context, io.Writer, io.Writer, *FormatOptions) (int, error) // Run runs a terraform command. Run(context.Context, io.Writer, io.Writer, string, ...string) (int, error) }
Terraform is the interface for working with the Terraform CLI.
type TerraformBackendConfig ¶
type TerraformBackendConfig struct { // GCSBucket is the GCS Bucket used in a terraform backend config block. GCSBucket *string `hcl:"bucket,attr"` // Prefix is the GCS Bucket prefix used in a terraform backend config block. 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) Format ¶
func (t *TerraformClient) Format(ctx context.Context, stdout, stderr io.Writer, opts *FormatOptions) (int, error)
Format runs the Terraform format 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) Run ¶
func (t *TerraformClient) Run(ctx context.Context, stdout, stderr io.Writer, subcommand string, args ...string) (int, error)
Run runs a Terraform 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 is the filesystem path to the entrypoint. Path string // BackendFile is the filename of the terraform file that contains the backend config block. BackendFile string }
TerraformEntrypoint describes a terraform entrypoint.
func GetEntrypointDirectories ¶
func GetEntrypointDirectories(rootDir string, maxDepth *int) ([]*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 ¶
TerraformResponse is the response from running a terraform command.
type ValidateOptions ¶
ValidateOptions are the set of options for running a terraform validate.