template resource allows text templates using Go's template format
to be processed as part of the resource creation process. For example you can use the template resource
to prepare configuration files for your applications.
Variables can be defined as a map in the
vars attribute which are available for substitution using the root
Go template object
.Vars. For example to replace insert the value of the vars item
data_dir the following
syntax can be used.
All supported features o Go Templates such as variable substitution, loops and conditional statements are supported by the Shipyard implementation.
To ensure that Shipyard templates can produce content which could be interpreted by standard Go templates, and which
does not clash with the interpolation syntax, the delimters have been modifed from
The following example shows how the template can be embedded into the resource stanza using HereDoc syntax.
The file produced from this example would be as follows:
To leverage external files you can use the
file function which loads a file returning a string. This example
also shows how the
depends_on attribute can be used to ensure a template is processed before it is consumed.
In addtion to the Go template syntax when using HereDoc it is possible to direcly inline Shipyard variables and functions as shown by the following example.
Depends on allows you to specify resources which should be created before this one. In the instance of a destruction, this container will be destroyed before resources in.
The template source specified as a string, it is possible to leverage the
file function to load external files and HereDoc syntax for multi line templates.
The destination file that will be written by the template resource. If relative file is specified, Shipyard will replace this to be an absolute path relative to the config file containing the resource.