»Default Parameters

In addition to user defined return values you can also request waypoint injects default parameters. At present there are 11 possible parameters which you can inject, these are:

  • context.Context
  • *component.Source
  • *component.JobInfo
  • *component.DeploymentConfig
  • *datadir.Project
  • *datadir.App
  • *datadir.Component
  • hclog.Logger
  • terminal.UI
  • *component.LabelSet

»context.Context

https://pkg.go.dev/context#Context

Context is a default parameter and is used by Waypoint to notify you when the work that component is performing should be cancelled. As with any Go code calling the Err() function on the Context will return an error if the Context has already been cancelled, you can also use the channel returned by the Done() function to notify you when Waypoint cancels the current operation.

if ctx.Err() != nil {
  return nil, status.Error(codes.Internal, "Context cancelled error message")
}

»*component.Source

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#Source

Source is a data struct which provides the current application name App, and Path which is the directory containing the current Waypoint file.

type Source struct {
  App  string
  Path string
}

»*component.JobInfo

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#JobInfo

JobInfo is a data struct which provides details related to the current Job.

type JobInfo struct {
  // Id is the ID of the job that is executing this plugin operation.
  // If this is empty then it means that the execution is happening
  // outside of a job.
  Id string

  // Local is true if the operation is running locally on a machine
  // alongside the invocation. This can be used to determine if you can
  // do things such as open browser windows, read user files, etc.
  Local bool

  // Workspace is the workspace that this job is executing in. This should
  // be used by plugins to properly isolate resources from each other.
  Workspace string
}

»*component.DeploymentConfig

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#DeploymentConfig

DeploymentConfig contains configuration which the entrypoint binary requires in order to run correctly. For example if you deploy an application to Google Cloud Run which is using the builtin Docker builder, the entrypoint is automatically bundled into the container. In order for the entrypoint to function correctly it needs to be configured correctly.

type DeploymentConfig struct {
  Id                    string
  ServerAddr            string
  ServerTls             bool
  ServerTlsSkipVerify   bool
  EntrypointInviteToken string
}

To simplify the configuration of the entrypoint environment variables DeploymentConfig also has a function which returns a map of the correct environment variables and their values.

func (c *DeploymentConfig) Env() map[string]string

»*datadir.Project

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/datadir#Project

Project exposes information regarding data and cache directories for the current project, Project implements the Dir interface which has the following two methods.

CacheDir returns the absolute path of the project directory which can be used to store assets like built applications between operations.

CacheDir() string

DataDir returns the absolute path of the project directory which can be used to persist data between operations.

DataDir() string

To obtain the specific folders related to an individual application in the project you can use the App function. App which is returned from this function also implements the Dir interface and has the CacheDir and DataDir methods.

func (p *Project) App(name string) (*App, error)

»*datadir.App

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/datadir#App

App exposes information regarding data and cache directories for the current application within the project. App implements the Dir interface.

»*datadir.Component

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/datadir#Component

Component exposes information regarding data and cache directories which are scoped to the individual component.

»hclog.Logger

https://pkg.go.dev/github.com/hashicorp/go-hclog#Logger

Logger provides you with the ability to write to the Waypoint standard logger using different log levels such as Info, Debug, Trace, etc. By default, log output is disabled when running a waypoint command. The environment variable WAYPOINT_LOG_LEVEL=[debug, trace, info, warning] can be set to enable log output in the CLI.

  log.Info(
    "Start build",
    "src", src,
    "job", job,
    "projectDataDir", projectDir.DataDir(),
    "projectCacheDir", projectDir.CacheDir(),
    "appDataDir", appDir.DataDir(),
    "appCacheDir", appDir.CacheDir(),
    "componentDataDir", componentDir.DataDir(),
    "componentCacheDir", componentDir.CacheDir(),
    "labels", labels,
  )

»terminal.UI

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/terminal#UI

UI allows you to build rich output for your plugin, more details on using terminal.UI can be found in the Interacting with the UI section.

»*component.LabelSet

https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#LabelSet

LabelSet allows you to read the labels defined at an app level on your Waypoint configuration.

app "wpmini" {
  labels = {
    "service" = "wpmini",
    "env"     = "dev"
  }
#...

The LabelSet struct exposes a single field Labels which is of type map[string]string, this collection contains all the labels defined in the configuration.

Labels map[string]string