Skip to content

Commit 7eff859

Browse files
committed
fix(provisioner/terraform/tfparse): skip evaluation of defaults if no workspace_tags found
1 parent 3f1795f commit 7eff859

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

coderd/templateversions_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,20 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
460460
},
461461
wantTags: map[string]string{"owner": templateAdminUser.ID.String(), "scope": "user"},
462462
},
463+
// Ref: https://github.com/coder/coder/issues/16021
464+
{
465+
name: "main.tf with no workspace_tags and a function call in a parameter default",
466+
files: map[string]string{
467+
`main.tf`: `
468+
data "coder_parameter" "foo" {
469+
name = "foo"
470+
type = "list(string)"
471+
default = jsonencode(["1", "2", "3", "4"])
472+
mutable = true
473+
}`,
474+
},
475+
wantTags: map[string]string{"owner": "", "scope": "organization"},
476+
},
463477
} {
464478
tt := tt
465479
t.Run(tt.name, func(t *testing.T) {

provisioner/terraform/tfparse/tfparse.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func New(workdir string, opts ...Option) (*Parser, tfconfig.Diagnostics) {
8080
}
8181

8282
// WorkspaceTags looks for all coder_workspace_tags datasource in the module
83-
// and returns the raw values for the tags. Use
83+
// and returns the raw values for the tags.
8484
func (p *Parser) WorkspaceTags(ctx context.Context) (map[string]string, error) {
8585
tags := map[string]string{}
8686
var skipped []string
@@ -166,6 +166,11 @@ func (p *Parser) WorkspaceTagDefaults(ctx context.Context) (map[string]string, e
166166
return nil, xerrors.Errorf("extract workspace tags: %w", err)
167167
}
168168

169+
if len(tags) == 0 {
170+
//nolint: nilnil
171+
return nil, nil
172+
}
173+
169174
// To evaluate the expressions, we need to load the default values for
170175
// variables and parameters.
171176
varsDefaults, err := p.VariableDefaults(ctx)

0 commit comments

Comments
 (0)