Skip to content

Commit 6290ace

Browse files
committed
add some comments
1 parent b4374a0 commit 6290ace

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

coderd/dynamicparameters/render.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import (
2020
"github.com/hashicorp/hcl/v2"
2121
)
2222

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.
2329
type Renderer interface {
2430
Render(ctx context.Context, ownerID uuid.UUID, values map[string]string) (*preview.Output, hcl.Diagnostics)
2531
Close()
@@ -31,8 +37,7 @@ var (
3137

3238
// Loader is used to load the necessary coder objects for rendering a template
3339
// 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.
3641
type Loader struct {
3742
templateVersionID uuid.UUID
3843

@@ -106,6 +111,13 @@ func (r *Loader) loaded() bool {
106111
return r.templateVersion != nil && r.job != nil && r.terraformValues != nil
107112
}
108113

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.
109121
func (r *Loader) Renderer(ctx context.Context, db database.Store, cache *files.Cache) (Renderer, error) {
110122
if !r.loaded() {
111123
return nil, xerrors.New("Load() must be called before Renderer()")

0 commit comments

Comments
 (0)