@@ -20,6 +20,12 @@ import (
20
20
"github.com/hashicorp/hcl/v2"
21
21
)
22
22
23
+ // Renderer is able to execute and evaluate terraform with the given inputs.
24
+ // It may use the database to fetch additional state, such as a user's groups,
25
+ // roles, etc. Therefore, it requires an authenticated `ctx`.
26
+ //
27
+ // 'Close()' **must** be called once the renderer is no longer needed.
28
+ // Forgetting to do so will result in a memory leak.
23
29
type Renderer interface {
24
30
Render (ctx context.Context , ownerID uuid.UUID , values map [string ]string ) (* preview.Output , hcl.Diagnostics )
25
31
Close ()
31
37
32
38
// Loader is used to load the necessary coder objects for rendering a template
33
39
// version's parameters. The output is a Renderer, which is the object that uses
34
- // the cached objects to render the template version's parameters. Closing the
35
- // Renderer will release the cached files.
40
+ // the cached objects to render the template version's parameters.
36
41
type Loader struct {
37
42
templateVersionID uuid.UUID
38
43
@@ -106,6 +111,13 @@ func (r *Loader) loaded() bool {
106
111
return r .templateVersion != nil && r .job != nil && r .terraformValues != nil
107
112
}
108
113
114
+ // Renderer returns a Renderer that can be used to render the template version's
115
+ // parameters. It automatically determines whether to use a static or dynamic
116
+ // renderer based on the template version's state.
117
+ //
118
+ // Static parameter rendering is required to support older template versions that
119
+ // do not have the database state to support dynamic parameters. A constant
120
+ // warning will be displayed for these template versions.
109
121
func (r * Loader ) Renderer (ctx context.Context , db database.Store , cache * files.Cache ) (Renderer , error ) {
110
122
if ! r .loaded () {
111
123
return nil , xerrors .New ("Load() must be called before Renderer()" )
0 commit comments