@@ -45,6 +45,10 @@ type Loader struct {
45
45
terraformValues * database.TemplateVersionTerraformValue
46
46
}
47
47
48
+ // Prepare is the entrypoint for this package. It is broken into 2 steps to allow
49
+ // prepopulating some of the existing data and saving some database queries.
50
+ //
51
+ // Usage: dynamicparameters.Prepare(...).Renderer(...)
48
52
func Prepare (versionID uuid.UUID ) * Loader {
49
53
return & Loader {
50
54
templateVersionID : versionID ,
@@ -127,7 +131,7 @@ func (r *Loader) Renderer(ctx context.Context, db database.Store, cache *files.C
127
131
128
132
// Renderer caches all the necessary files when rendering a template version's
129
133
// parameters. It must be closed after use to release the cached files.
130
- func (r * Loader ) dynamicRenderer (ctx context.Context , db database.Store , cache * files.Cache ) (* DynamicRenderer , error ) {
134
+ func (r * Loader ) dynamicRenderer (ctx context.Context , db database.Store , cache * files.Cache ) (* dynamicRenderer , error ) {
131
135
// If they can read the template version, then they can read the file for
132
136
// parameter loading purposes.
133
137
//nolint:gocritic
@@ -152,7 +156,7 @@ func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *
152
156
plan = r .terraformValues .CachedPlan
153
157
}
154
158
155
- return & DynamicRenderer {
159
+ return & dynamicRenderer {
156
160
data : r ,
157
161
templateFS : templateFS ,
158
162
db : db ,
@@ -167,7 +171,7 @@ func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *
167
171
}, nil
168
172
}
169
173
170
- type DynamicRenderer struct {
174
+ type dynamicRenderer struct {
171
175
db database.Store
172
176
data * Loader
173
177
templateFS fs.FS
@@ -180,7 +184,7 @@ type DynamicRenderer struct {
180
184
close func ()
181
185
}
182
186
183
- func (r * DynamicRenderer ) Render (ctx context.Context , ownerID uuid.UUID , values map [string ]string ) (* preview.Output , hcl.Diagnostics ) {
187
+ func (r * dynamicRenderer ) Render (ctx context.Context , ownerID uuid.UUID , values map [string ]string ) (* preview.Output , hcl.Diagnostics ) {
184
188
// Always start with the cached error, if we have one.
185
189
ownerErr := r .ownerErrors [ownerID ]
186
190
if ownerErr == nil {
@@ -210,7 +214,7 @@ func (r *DynamicRenderer) Render(ctx context.Context, ownerID uuid.UUID, values
210
214
return preview .Preview (ctx , input , r .templateFS )
211
215
}
212
216
213
- func (r * DynamicRenderer ) getWorkspaceOwnerData (ctx context.Context , ownerID uuid.UUID ) error {
217
+ func (r * dynamicRenderer ) getWorkspaceOwnerData (ctx context.Context , ownerID uuid.UUID ) error {
214
218
if r .currentOwner != nil && r .currentOwner .ID == ownerID .String () {
215
219
return nil // already fetched
216
220
}
@@ -318,7 +322,7 @@ func (r *DynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uui
318
322
return nil
319
323
}
320
324
321
- func (r * DynamicRenderer ) Close () {
325
+ func (r * dynamicRenderer ) Close () {
322
326
r .once .Do (r .close )
323
327
}
324
328
0 commit comments