• Infrastructure
    • terraform
    • packer
  • Networking
    • consul
  • Security
    • vault
    • boundary
  • Applications
    • nomad
    • waypoint
    • vagrant
  • HashiCorp Cloud Platform

    A fully managed platform to automate infrastructure on any cloud with HashiCorp products.

    • consul
    • terraform
    • vault
    • packerbeta
    Visit cloud.hashicorp.com
  • Overview
  • Tutorials
  • Docs
  • CLI
  • Plugins
  • Community
GitHub
Download
    • Overview
      • Overview
      • Helm
      • Heroku, Vercel, etc.
      • Kubernetes
  • Getting Started
    • Overview
    • Compatibility Promise
    • Protocol Version Table
    • Release Notifications
      • Overview
      • Upgrade to 0.2.0
      • Upgrade to 0.3.0
      • Upgrade to 0.4.0
      • Upgrade to 0.5.0
      • Upgrade to 0.6.0
      • Upgrade to 0.7.0
      • Upgrade to 0.8.0
      • Upgrade to 0.9.0

    • Install
    • Externally Built Images
    • Building Container Images
    • Helm Deployment
    • YAML-Free Deployment
    • YAML Directory Deployment
    • Resource Status
    • ConfigMaps and Secrets

    • Overview
    • Git Integration
    • Remote Operations
    • Overview
    • Build
    • Deploy
    • Release
    • Hooks
    • Labels
    • Workspace and Label Scoping
    • Overview
      • Overview
      • Input Variables
      • External Data
      • artifact
      • deploy
      • entrypoint
      • labels
      • path
      • workspace
      • Overview
      • Full Reference
      • Templating
      • Overview
      • Expressions
      • JSON Syntax
    • app
    • build
    • config
    • deploy
    • hook
    • plugin
    • registry
    • release
    • runner
    • url
    • use
    • variable
  • URL Service
  • Logs
  • Exec
    • Overview
    • Dynamic Values
    • Files
    • Internal Values
    • Workspace and Label Scoping
    • Overview
      • Overview
      • OIDC
      • Tokens
      • Overview
      • Maintenance
      • Production
      • Security
    • Express Server Install
    • Overview
    • Configuration
    • Profiles
    • On-Demand Runner
    • Additional Runners
  • Workspaces
  • Plugins
  • Triggers

    • Overview
      • Overview
      • Registering Plugin Components
      • Handling Configuration
      • Implementing the Builder Interface
      • Compiling the Plugin
      • Creating an Example Application
      • Testing the Plugin
    • Initializing the SDK
    • Passing Values Between Components
      • Overview
      • Authenticator
      • ConfigSourcer
      • Configurable
      • ConfigurableNotify
      • Builder
      • Registry
      • Platform
      • ReleaseManager
      • Destroy
      • Status
      • Default Parameters
      • Overview
    • Overview
    • Disable
    • Overview
    • GitHub Actions
    • GitLab CI/CD
    • CircleCI
    • Jenkins
  • Troubleshooting
  • Glossary

    • Overview
    • Architecture
    • Operation Execution
  • Roadmap
Type '/' to Search

»ConfigSourcer

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

ConfigSourcer can be implemented to dynamically load configs from external sources such as Vault and Terraform Cloud. Waypoint uses dynamic config sourcers to run alongside the application. The plugin interface expects a ReadFunc() for reading configuration and a StopFunc() for stopping configuration sourcing.

// ConfigSourcer can be implemented by plugins that support sourcing
// dynamic configuration for running applications.
//
// This plugin type runs alongside the application. The initial config loading
// will block the application start so authors should attempt to source
// configuration as quickly as possible.
type ConfigSourcer interface {
  // ReadFunc returns the function for reading configuration.
  //
  // The returned function can start a background goroutine to more efficiently
  // watch for changes. The entrypoint will periodically call Read to check for
  // updates.
  //
  // If the configuration changes for any dynamic configuration variable,
  // the entrypoint will call Stop followed by Read, so plugins DO NOT need
  // to implement config diffing. Plugins may safely assume if Read is called
  // after a Stop that the config is new, and that subsequent calls have the
  // same config.
  //
  // Read is called for ALL defined configuration variables for this source.
  // If ANY change, Stop is called followed by Read again. Only one sourcer
  // is active for a set of configs.
  ReadFunc() interface{}

  // StopFunc returns a function for stopping configuration sourcing.
  // You can return nil if stopping is not necessary or supported for
  // this sourcer.
  //
  // The stop function should stop any background processes started with Read.
  StopFunc() interface{}
}
// ConfigSourcer can be implemented by plugins that support sourcing
// dynamic configuration for running applications.
//
// This plugin type runs alongside the application. The initial config loading
// will block the application start so authors should attempt to source
// configuration as quickly as possible.
type ConfigSourcer interface {
  // ReadFunc returns the function for reading configuration.
  //
  // The returned function can start a background goroutine to more efficiently
  // watch for changes. The entrypoint will periodically call Read to check for
  // updates.
  //
  // If the configuration changes for any dynamic configuration variable,
  // the entrypoint will call Stop followed by Read, so plugins DO NOT need
  // to implement config diffing. Plugins may safely assume if Read is called
  // after a Stop that the config is new, and that subsequent calls have the
  // same config.
  //
  // Read is called for ALL defined configuration variables for this source.
  // If ANY change, Stop is called followed by Read again. Only one sourcer
  // is active for a set of configs.
  ReadFunc() interface{}

  // StopFunc returns a function for stopping configuration sourcing.
  // You can return nil if stopping is not necessary or supported for
  // this sourcer.
  //
  // The stop function should stop any background processes started with Read.
  StopFunc() interface{}
}

Below is an abbreviated example of the Terraform Cloud ConfigSourcer ReadFunc().

// ReadFunc implements component.ConfigSourcer
func (cs *ConfigSourcer) ReadFunc() interface{} {
        return cs.read
}


func (cs *ConfigSourcer) read(
        ctx context.Context,
        log hclog.Logger,
        reqs []*component.ConfigRequest,
) ([]*pb.ConfigSource_Value, error) {
        // Setup our lock
        cs.cacheMu.Lock()
        defer cs.cacheMu.Unlock()

        // Set up client to read from Terraform Cloud

        // Then iterate over each request in `reqs` to load the value from TFC

        // Return the results
}
// ReadFunc implements component.ConfigSourcer
func (cs *ConfigSourcer) ReadFunc() interface{} {
        return cs.read
}


func (cs *ConfigSourcer) read(
        ctx context.Context,
        log hclog.Logger,
        reqs []*component.ConfigRequest,
) ([]*pb.ConfigSource_Value, error) {
        // Setup our lock
        cs.cacheMu.Lock()
        defer cs.cacheMu.Unlock()

        // Set up client to read from Terraform Cloud

        // Then iterate over each request in `reqs` to load the value from TFC

        // Return the results
}

»Getting your plugin into the CEB

To write your own config sourcer, the Waypoint entrypoint needs to be able to load and run your plugin. Unfortunately today there is no supported way for the CEB to automatically load your plugin. This means if you wish you write your own config sourcer plugin, you'll need to add the plugin in your own fork of Waypoint and build it from your fork to have your plugin included. You can also make a pull request to the main repository of Waypoint if you think your plugin makes sense.

We intend to provide a better way for the entrypoint to load custom plugins in the future that does not require users building their own version of Waypoint with their custom config sourcer plugin.

github logoEdit this page

Using Waypoint

The best way to understand what Waypoint can enable for your projects is to give it a try.

Waypoint tutorials
Waypoint documentation
Tutorial

Get Started - Kubernetes

Build, deploy, and release applications to a Kubernetes cluster.

View
Tutorial

Introduction to Waypoint

Waypoint enables you to publish any application to any platform with a single file and a single command.

View

Waypoint is maintained by HashiCorp, Inc.

View Code of Conduct
DocumentationCLI ReferenceTutorialsIntegrations
All systems normal