@@ -293,6 +293,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
293293type = string
294294default = "2"
295295}
296+ data "coder_parameter" "unrelated" {
297+ name = "unrelated"
298+ type = "list(string)"
299+ default = jsonencode(["a", "b"])
300+ }
296301resource "null_resource" "test" {}` ,
297302},
298303wantTags :map [string ]string {"owner" :"" ,"scope" :"organization" },
@@ -301,18 +306,23 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
301306name :"main.tf with empty workspace tags" ,
302307files :map [string ]string {
303308`main.tf` :`
304- variable "a" {
305- type = string
306- default = "1"
307- }
308- data "coder_parameter" "b" {
309- type = string
310- default = "2"
311- }
312- resource "null_resource" "test" {}
313- data "coder_workspace_tags" "tags" {
314- tags = {}
315- }` ,
309+ variable "a" {
310+ type = string
311+ default = "1"
312+ }
313+ data "coder_parameter" "b" {
314+ type = string
315+ default = "2"
316+ }
317+ data "coder_parameter" "unrelated" {
318+ name = "unrelated"
319+ type = "list(string)"
320+ default = jsonencode(["a", "b"])
321+ }
322+ resource "null_resource" "test" {}
323+ data "coder_workspace_tags" "tags" {
324+ tags = {}
325+ }` ,
316326},
317327wantTags :map [string ]string {"owner" :"" ,"scope" :"organization" },
318328},
@@ -328,6 +338,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
328338type = string
329339default = "2"
330340}
341+ data "coder_parameter" "unrelated" {
342+ name = "unrelated"
343+ type = "list(string)"
344+ default = jsonencode(["a", "b"])
345+ }
331346resource "null_resource" "test" {}
332347data "coder_workspace_tags" "tags" {
333348tags = {
@@ -343,22 +358,28 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
343358name :"main.tf with workspace tags and request tags" ,
344359files :map [string ]string {
345360`main.tf` :`
346- variable "a" {
347- type = string
348- default = "1"
349- }
350- data "coder_parameter" "b" {
351- type = string
352- default = "2"
353- }
354- resource "null_resource" "test" {}
355- data "coder_workspace_tags" "tags" {
356- tags = {
357- "foo": "bar",
358- "a": var.a,
359- "b": data.coder_parameter.b.value,
361+ // This file is the same as the above, except for this comment.
362+ variable "a" {
363+ type = string
364+ default = "1"
365+ }
366+ data "coder_parameter" "b" {
367+ type = string
368+ default = "2"
360369}
361- }` ,
370+ data "coder_parameter" "unrelated" {
371+ name = "unrelated"
372+ type = "list(string)"
373+ default = jsonencode(["a", "b"])
374+ }
375+ resource "null_resource" "test" {}
376+ data "coder_workspace_tags" "tags" {
377+ tags = {
378+ "foo": "bar",
379+ "a": var.a,
380+ "b": data.coder_parameter.b.value,
381+ }
382+ }` ,
362383},
363384reqTags :map [string ]string {"baz" :"zap" ,"foo" :"noclobber" },
364385wantTags :map [string ]string {"owner" :"" ,"scope" :"organization" ,"foo" :"bar" ,"baz" :"zap" ,"a" :"1" ,"b" :"2" },
@@ -375,6 +396,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
375396type = string
376397default = "2"
377398}
399+ data "coder_parameter" "unrelated" {
400+ name = "unrelated"
401+ type = "list(string)"
402+ default = jsonencode(["a", "b"])
403+ }
378404resource "null_resource" "test" {
379405name = "foo"
380406}
@@ -401,6 +427,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
401427type = string
402428default = "2"
403429}
430+ data "coder_parameter" "unrelated" {
431+ name = "unrelated"
432+ type = "list(string)"
433+ default = jsonencode(["a", "b"])
434+ }
404435resource "null_resource" "test" {
405436name = "foo"
406437}
@@ -423,6 +454,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
423454name :"main.tf with workspace tags that attempts to set user scope" ,
424455files :map [string ]string {
425456`main.tf` :`
457+ data "coder_parameter" "unrelated" {
458+ name = "unrelated"
459+ type = "list(string)"
460+ default = jsonencode(["a", "b"])
461+ }
426462resource "null_resource" "test" {}
427463data "coder_workspace_tags" "tags" {
428464tags = {
@@ -437,6 +473,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
437473name :"main.tf with workspace tags that attempt to clobber org ID" ,
438474files :map [string ]string {
439475`main.tf` :`
476+ data "coder_parameter" "unrelated" {
477+ name = "unrelated"
478+ type = "list(string)"
479+ default = jsonencode(["a", "b"])
480+ }
440481resource "null_resource" "test" {}
441482data "coder_workspace_tags" "tags" {
442483tags = {
@@ -451,6 +492,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
451492name :"main.tf with workspace tags that set scope=user" ,
452493files :map [string ]string {
453494`main.tf` :`
495+ data "coder_parameter" "unrelated" {
496+ name = "unrelated"
497+ type = "list(string)"
498+ default = jsonencode(["a", "b"])
499+ }
454500resource "null_resource" "test" {}
455501data "coder_workspace_tags" "tags" {
456502tags = {
@@ -460,6 +506,19 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
460506},
461507wantTags :map [string ]string {"owner" :templateAdminUser .ID .String (),"scope" :"user" },
462508},
509+ // Ref: https://github.com/coder/coder/issues/16021
510+ {
511+ name :"main.tf with no workspace_tags and a function call in a parameter default" ,
512+ files :map [string ]string {
513+ `main.tf` :`
514+ data "coder_parameter" "unrelated" {
515+ name = "unrelated"
516+ type = "list(string)"
517+ default = jsonencode(["a", "b"])
518+ }` ,
519+ },
520+ wantTags :map [string ]string {"owner" :"" ,"scope" :"organization" },
521+ },
463522} {
464523tt := tt
465524t .Run (tt .name ,func (t * testing.T ) {