@@ -293,6 +293,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
293
293
type = string
294
294
default = "2"
295
295
}
296
+ data "coder_parameter" "unrelated" {
297
+ name = "unrelated"
298
+ type = "list(string)"
299
+ default = jsonencode(["a", "b"])
300
+ }
296
301
resource "null_resource" "test" {}` ,
297
302
},
298
303
wantTags : map [string ]string {"owner" : "" , "scope" : "organization" },
@@ -301,18 +306,23 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
301
306
name : "main.tf with empty workspace tags" ,
302
307
files : map [string ]string {
303
308
`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
+ }` ,
316
326
},
317
327
wantTags : map [string ]string {"owner" : "" , "scope" : "organization" },
318
328
},
@@ -328,6 +338,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
328
338
type = string
329
339
default = "2"
330
340
}
341
+ data "coder_parameter" "unrelated" {
342
+ name = "unrelated"
343
+ type = "list(string)"
344
+ default = jsonencode(["a", "b"])
345
+ }
331
346
resource "null_resource" "test" {}
332
347
data "coder_workspace_tags" "tags" {
333
348
tags = {
@@ -343,22 +358,28 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
343
358
name : "main.tf with workspace tags and request tags" ,
344
359
files : map [string ]string {
345
360
`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"
360
369
}
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
+ }` ,
362
383
},
363
384
reqTags : map [string ]string {"baz" : "zap" , "foo" : "noclobber" },
364
385
wantTags : map [string ]string {"owner" : "" , "scope" : "organization" , "foo" : "bar" , "baz" : "zap" , "a" : "1" , "b" : "2" },
@@ -375,6 +396,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
375
396
type = string
376
397
default = "2"
377
398
}
399
+ data "coder_parameter" "unrelated" {
400
+ name = "unrelated"
401
+ type = "list(string)"
402
+ default = jsonencode(["a", "b"])
403
+ }
378
404
resource "null_resource" "test" {
379
405
name = "foo"
380
406
}
@@ -401,6 +427,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
401
427
type = string
402
428
default = "2"
403
429
}
430
+ data "coder_parameter" "unrelated" {
431
+ name = "unrelated"
432
+ type = "list(string)"
433
+ default = jsonencode(["a", "b"])
434
+ }
404
435
resource "null_resource" "test" {
405
436
name = "foo"
406
437
}
@@ -423,6 +454,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
423
454
name : "main.tf with workspace tags that attempts to set user scope" ,
424
455
files : map [string ]string {
425
456
`main.tf` : `
457
+ data "coder_parameter" "unrelated" {
458
+ name = "unrelated"
459
+ type = "list(string)"
460
+ default = jsonencode(["a", "b"])
461
+ }
426
462
resource "null_resource" "test" {}
427
463
data "coder_workspace_tags" "tags" {
428
464
tags = {
@@ -437,6 +473,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
437
473
name : "main.tf with workspace tags that attempt to clobber org ID" ,
438
474
files : map [string ]string {
439
475
`main.tf` : `
476
+ data "coder_parameter" "unrelated" {
477
+ name = "unrelated"
478
+ type = "list(string)"
479
+ default = jsonencode(["a", "b"])
480
+ }
440
481
resource "null_resource" "test" {}
441
482
data "coder_workspace_tags" "tags" {
442
483
tags = {
@@ -451,6 +492,11 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
451
492
name : "main.tf with workspace tags that set scope=user" ,
452
493
files : map [string ]string {
453
494
`main.tf` : `
495
+ data "coder_parameter" "unrelated" {
496
+ name = "unrelated"
497
+ type = "list(string)"
498
+ default = jsonencode(["a", "b"])
499
+ }
454
500
resource "null_resource" "test" {}
455
501
data "coder_workspace_tags" "tags" {
456
502
tags = {
@@ -460,6 +506,19 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
460
506
},
461
507
wantTags : map [string ]string {"owner" : templateAdminUser .ID .String (), "scope" : "user" },
462
508
},
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
+ },
463
522
} {
464
523
tt := tt
465
524
t .Run (tt .name , func (t * testing.T ) {
0 commit comments