Documentation
¶
Index ¶
- type ApplyOutput
- type DestroyOutput
- type Manager
- type OutputResult
- type PlanOutput
- type TFEnvironment
- type Terraform
- func (t *Terraform) Apply(ctx context.Context, env env.Environment) (ApplyOutput, error)
- func (t *Terraform) Cleanup()
- func (t *Terraform) Destroy(ctx context.Context, env env.Environment) (DestroyOutput, error)
- func (t *Terraform) Init(ctx context.Context) error
- func (t *Terraform) Output(ctx context.Context, env env.Environment) (OutputResult, error)
- func (t *Terraform) Plan(ctx context.Context, env env.Environment) (PlanOutput, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyOutput ¶
type ApplyOutput struct {
// Human-readable output (the output that's usually
// in the terminal when running terraform apply).
Output string
}
ApplyOutput is the result of calling Apply.
type DestroyOutput ¶
type DestroyOutput struct {
// Human-readable output (the output that's usually
// in the terminal when running terraform destroy).
Output string
}
DestroyOutput is the result of calling Destroy.
type Manager ¶
type Manager interface {
Init(ctx context.Context) error
Plan(ctx context.Context, env env.Environment) (PlanOutput, error)
Apply(ctx context.Context, env env.Environment) (ApplyOutput, error)
Destroy(ctx context.Context, env env.Environment) (DestroyOutput, error)
Output(ctx context.Context, env env.Environment) (OutputResult, error)
Cleanup()
}
type OutputResult ¶
type OutputResult struct {
Resources map[string]map[string]any `json:"resources"`
Apps map[string]map[string]any `json:"apps"`
Extra map[string]any `json:"extra"`
}
OutputResult is the result of calling Output. It contains a structured map of all Terraform outputs. See platform/terraform/base/outputs.tf for spercifics.
Resources: Maps resource names to their fields and values. Example: "store": { "bucket_name": "my-website-store-temp", "bucket_url": "my-website-store-temp.nyc3.digitaloceanspaces.com", }
Apps: Maps app names to their fields and values. Example (empty if no apps provisioned): "web-app": { "app_url": "https://web-app.example.com", "platform_provider": "digitalocean" }
Extra: Contains all other outputs that don’t fit into Resources or Apps.
type PlanOutput ¶
type PlanOutput struct {
// Determines if there has been any changes to
// the plan since running last.
HasChanges bool
// Human-readable output (the output that's usually
// in the terminal when running terraform plan).
Output string
// The JSON contents of the plan for more of a
// detailed look.
Plan *tfjson.Plan
}
PlanOutput is the result of calling Plan.
type TFEnvironment ¶
type TFEnvironment struct {
DigitalOceanAPIKey string `env:"DO_API_KEY,required"`
DigitalOceanSpacesAccessKey string `env:"DO_SPACES_ACCESS_KEY,required"`
DigitalOceanSpacesSecretKey string `env:"DO_SPACES_SECRET_KEY,required"`
BackBlazeBucket string `env:"BACK_BLAZE_BUCKET,required"`
BackBlazeKeyID string `env:"BACK_BLAZE_KEY_ID,required"`
BackBlazeApplicationKey string `env:"BACK_BLAZE_APPLICATION_KEY,required"`
GithubToken string `env:"GITHUB_TOKEN,required"`
}
TFEnvironment holds the required environment variables for Terraform operations. Plan and Apply cannot be ran without them as they are backend configs.
func ParseTFEnvironment ¶
func ParseTFEnvironment() (TFEnvironment, error)
ParseTFEnvironment reads and validates Terraform-related environment variables.
type Terraform ¶
type Terraform struct {
// contains filtered or unexported fields
}
Terraform represents the type for interacting with the terraform exec CLI.
func NewTerraform ¶
func NewTerraform(ctx context.Context, appDef *appdef.Definition, manifest *manifest.Tracker) (*Terraform, error)
NewTerraform creates a new Terraform manager by locating the terraform binary on the system.
Returns an error if terraform cannot be found in PATH.
func (*Terraform) Apply ¶
func (t *Terraform) Apply(ctx context.Context, env env.Environment) (ApplyOutput, error)
Apply executes terraform apply to provision infrastructure based on the app definition provided.
Must be called after Init().
func (*Terraform) Cleanup ¶
func (t *Terraform) Cleanup()
Cleanup removes all the temporary directories that we're created during the terraform init process.
Ideally should be called after Init().
func (*Terraform) Destroy ¶
func (t *Terraform) Destroy(ctx context.Context, env env.Environment) (DestroyOutput, error)
Destroy executes terraform destroy to tear down infrastructure based on the app definition provided.
Must be called after Init().
func (*Terraform) Init ¶
Init initialises the WebKit terraform provider by copying all the terraform embedded templates to a temporary directory on the filesystem.
Backend configuration and provider config are also written as part of this process.
Must be called before Plan() or Apply()
func (*Terraform) Output ¶
func (t *Terraform) Output(ctx context.Context, env env.Environment) (OutputResult, error)
Output retrieves all Terraform outputs for the specified environment. This reads the current terraform state and returns all output values.
Must be called after Init().
func (*Terraform) Plan ¶
func (t *Terraform) Plan(ctx context.Context, env env.Environment) (PlanOutput, error)
Plan generates a Terraform execution plan showing what actions Terraform will take to reach the desired state defined in the definition.
Must be called after Init().