Configurable
Warning
This content is part of the legacy version of Waypoint that is no longer actively maintained. For additional information on the new vision of Waypoint, check out this blog post and the HCP Waypoint documentation.
https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#Configurable
All plugins can receive the configuration from the waypoint.hcl
file by implementing the Configurable interface.
Configurable is always called before the main component methods and is available for any component which has a
definable config block, build, registry, deploy, and release.
To implement configuration for your plugins you implement the Configurable interface on your component. This has a single method Config which has two return parameters, interface{} and error. The first parameter is a reference to a Go struct which you would like Waypoint to populate with the details from a configuration stanza.
The caller of Config expects that you return a Go Struct which has been annotated with HCL tags. For example, if you look at the following configuration there are two parameters defined output_name and source.
To receive this information in your plugin you need to create a struct which is annotated with HCL tags as shown below.
You can then return a reference to an instance of this Struct from the Config function. The Waypoint SDK will call the Config function on your component and will set the configuration parameters to the fields on the returned struct based on the tag specified.
This process uses the standard HCL2 decoder and it is possible to create complex configuration which contains nested child blocks. An example showing more complex nested configuration blocks can be seen in the Google Cloud Run plugin.
For a general overview of HCL2 configuration please see the HCL github repo and documentation.