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 InitOptions
- type MockTerraformClient
- func (m *MockTerraformClient) Apply(ctx context.Context, stdout, stderr io.Writer, opts *ApplyOptions) (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) 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 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) 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) 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 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 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 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) }
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 ¶
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 ¶
TerraformResponse is the response from running a terraform command.
type ValidateOptions ¶
ValidateOptions are the set of options for running a terraform validate.