Documentation
¶
Index ¶
- Constants
- type ApplyOutput
- type DestroyOutput
- type ImportInput
- type ImportKind
- type ImportOutput
- type Manager
- type OutputResult
- type PlanOutput
- type TFEnvironment
- type Terraform
- func (t *Terraform) Apply(ctx context.Context, env env.Environment, refreshOnly bool) (ApplyOutput, error)
- func (t *Terraform) Cleanup()
- func (t *Terraform) Destroy(ctx context.Context, env env.Environment) (DestroyOutput, error)
- func (t *Terraform) Import(ctx context.Context, input ImportInput) (ImportOutput, 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, refreshOnly bool) (PlanOutput, error)
- func (t *Terraform) WorkDir() string
Constants ¶
const ( // TerraformVersion is the version of Terraform to use in CI/CD workflows. // This should be kept in sync with: // - .github/actions/setup/action.yaml // - platform/terraform/base/main.tf (required_version) TerraformVersion = "1.13.0" )
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 ImportInput ¶ added in v0.0.9
type ImportInput struct {
// Kind specifies what type of item is being imported.
Kind ImportKind
// Name is the name of the resource or app in app.json (empty for projects).
Name string
// ID is the provider-specific ID (e.g., DigitalOcean cluster ID, app ID, project ID).
ID string
// Environment specifies which environment to import into.
Environment env.Environment
}
ImportInput contains the configuration for importing existing resources or apps.
type ImportKind ¶ added in v0.0.29
type ImportKind int
ImportKind represents the type of item being imported.
const ( // ImportKindResource indicates importing a resource (database, storage, etc.). ImportKindResource ImportKind = iota // ImportKindApp indicates importing an app. ImportKindApp // ImportKindProject indicates importing a DigitalOcean project. ImportKindProject )
type ImportOutput ¶ added in v0.0.9
type ImportOutput struct {
// ImportedResources lists the Terraform addresses that were imported.
ImportedResources []string
// Output contains the human-readable output from the import operations.
Output string
}
ImportOutput contains the results of an import operation.
type Manager ¶
type Manager interface {
Init(ctx context.Context) error
Plan(ctx context.Context, env env.Environment, refreshOnly bool) (PlanOutput, error)
Apply(ctx context.Context, env env.Environment, refreshOnly bool) (ApplyOutput, error)
Destroy(ctx context.Context, env env.Environment) (DestroyOutput, error)
Output(ctx context.Context, env env.Environment) (OutputResult, error)
Import(ctx context.Context, input ImportInput) (ImportOutput, error)
Cleanup()
WorkDir() string
}
Manager defines the interface for managing infrastructure operations.
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"`
HetznerToken string `env:"HETZNER_TOKEN,required"`
BackBlazeBucket string `env:"BACK_BLAZE_BUCKET,required"`
BackBlazeKeyID string `env:"BACK_BLAZE_KEY_ID,required"`
BackBlazeApplicationKey string `env:"BACK_BLAZE_APPLICATION_KEY,required"`
TursoToken string `env:"TURSO_TOKEN,required"`
GithubToken string `env:"GITHUB_TOKEN,required"`
GithubTokenClassic string `env:"GITHUB_TOKEN_CLASSIC,required"`
SlackBotToken string `env:"SLACK_BOT_TOKEN,required"`
SlackUserToken string `env:"SLACK_USER_TOKEN,required"`
SlackWebhookURL string `env:"SLACK_WEBHOOK_URL"`
PeekapingEndpoint string `env:"PEEKAPING_ENDPOINT"`
PeekapingAPIKey string `env:"PEEKAPING_API_KEY"`
}
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, refreshOnly bool) (ApplyOutput, error)
Apply executes terraform apply to provision infrastructure based on the app definition provided. If refreshOnly is true, it uses 'terraform apply -refresh-only' to sync state without making changes.
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) Import ¶ added in v0.0.9
func (t *Terraform) Import(ctx context.Context, input ImportInput) (ImportOutput, error)
Import imports an existing infrastructure resource or app into the Terraform state. This allows webkit to manage resources/apps that were created manually or outside of Terraform.
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, refreshOnly bool) (PlanOutput, error)
Plan generates a Terraform execution plan showing what actions Terraform will take to reach the desired state defined in the definition. If refreshOnly is true, it uses 'terraform plan -refresh-only' to show what state changes would occur from refreshing.
Must be called after Init().