Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite48b106

Browse files
committed
fix(provisioner/terraform/tfparse): skip evaluating variables/parameters not referenced by workspace_tags
1 parente00c3f5 commite48b106

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

‎coderd/templateversions_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
358358
name:"main.tf with workspace tags and request tags",
359359
files:map[string]string{
360360
`main.tf`:`
361+
// This file is the same as the above, except for this comment.
361362
variable "a" {
362363
type = string
363364
default = "1"

‎provisioner/terraform/tfparse/tfparse.go‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ func (p *Parser) WorkspaceTagDefaults(ctx context.Context) (map[string]string, e
172172

173173
// To evaluate the expressions, we need to load the default values for
174174
// variables and parameters.
175-
varsDefaults,err:=p.VariableDefaults(ctx)
175+
varsDefaults,err:=p.VariableDefaults(ctx,tags)
176176
iferr!=nil {
177177
returnnil,xerrors.Errorf("load variable defaults: %w",err)
178178
}
179-
paramsDefaults,err:=p.CoderParameterDefaults(ctx,varsDefaults)
179+
paramsDefaults,err:=p.CoderParameterDefaults(ctx,varsDefaults,tags)
180180
iferr!=nil {
181181
returnnil,xerrors.Errorf("load parameter defaults: %w",err)
182182
}
@@ -251,28 +251,39 @@ func WriteArchive(bs []byte, mimetype string, path string) error {
251251
returnnil
252252
}
253253

254-
// VariableDefaults returns the default values for all variables passed to it.
255-
func (p*Parser)VariableDefaults(ctx context.Context) (map[string]string,error) {
254+
// VariableDefaults returns the default values for all variables referenced in the values of tags.
255+
func (p*Parser)VariableDefaults(ctx context.Context,tagsmap[string]string) (map[string]string,error) {
256+
varskipped []string
256257
// iterate through vars to get the default values for all
257-
// variables.
258+
//requiredvariables.
258259
m:=make(map[string]string)
259260
for_,v:=rangep.module.Variables {
260261
ifv==nil {
261262
continue
262263
}
264+
varfoundbool
265+
for_,tv:=rangetags {
266+
ifstrings.Contains(tv,v.Name) {
267+
found=true
268+
}
269+
}
270+
if!found {
271+
skipped=append(skipped,v.Name)
272+
continue
273+
}
263274
sv,err:=interfaceToString(v.Default)
264275
iferr!=nil {
265276
returnnil,xerrors.Errorf("can't convert variable default value to string: %v",err)
266277
}
267278
m[v.Name]=strings.Trim(sv,`"`)
268279
}
269-
p.logger.Debug(ctx,"found default values for variables",slog.F("defaults",m))
280+
p.logger.Debug(ctx,"found default values for variables",slog.F("defaults",m),slog.F("skipped",skipped))
270281
returnm,nil
271282
}
272283

273284
// CoderParameterDefaults returns the default values of all coder_parameter data sources
274285
// in the parsed module.
275-
func (p*Parser)CoderParameterDefaults(ctx context.Context,varsDefaultsmap[string]string) (map[string]string,error) {
286+
func (p*Parser)CoderParameterDefaults(ctx context.Context,varsDefaultsmap[string]string,tagsmap[string]string) (map[string]string,error) {
276287
defaultsM:=make(map[string]string)
277288
var (
278289
skipped []string
@@ -294,6 +305,17 @@ func (p *Parser) CoderParameterDefaults(ctx context.Context, varsDefaults map[st
294305
continue
295306
}
296307

308+
varfoundbool
309+
for_,tv:=rangetags {
310+
ifstrings.Contains(tv,dataResource.Name) {
311+
found=true
312+
}
313+
}
314+
if!found {
315+
skipped=append(skipped,dataResource.Name)
316+
continue
317+
}
318+
297319
// We know in which HCL file is the data resource defined.
298320
// NOTE: hclparse.Parser will cache multiple successive calls to parse the same file.
299321
file,diags=p.underlying.ParseHCLFile(dataResource.Pos.Filename)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp