@@ -8,10 +8,10 @@ import {
8
8
Agent ,
9
9
App ,
10
10
AppSharingLevel ,
11
- Parse_Complete ,
12
- Parse_Response ,
13
- Provision_Complete ,
14
- Provision_Response ,
11
+ Response ,
12
+ ParseComplete ,
13
+ PlanComplete ,
14
+ ApplyComplete ,
15
15
Resource ,
16
16
RichParameter ,
17
17
} from "./provisionerGenerated"
@@ -337,11 +337,11 @@ type RecursivePartial<T> = {
337
337
338
338
interface EchoProvisionerResponses {
339
339
// parse is for observing any Terraform variables
340
- parse ?: RecursivePartial < Parse_Response > [ ]
340
+ parse ?: RecursivePartial < Response > [ ]
341
341
// plan occurs when the template is imported
342
- plan ?: RecursivePartial < Provision_Response > [ ]
342
+ plan ?: RecursivePartial < Response > [ ]
343
343
// apply occurs when the workspace is built
344
- apply ?: RecursivePartial < Provision_Response > [ ]
344
+ apply ?: RecursivePartial < Response > [ ]
345
345
}
346
346
347
347
// createTemplateVersionTar consumes a series of echo provisioner protobufs and
@@ -353,109 +353,128 @@ const createTemplateVersionTar = async (
353
353
responses = { }
354
354
}
355
355
if ( ! responses . parse ) {
356
- responses . parse = [ { } ]
356
+ responses . parse = [ {
357
+ parse : { }
358
+ } ]
357
359
}
358
360
if ( ! responses . apply ) {
359
- responses . apply = [ { } ]
361
+ responses . apply = [ {
362
+ apply : { }
363
+ } ]
360
364
}
361
365
if ( ! responses . plan ) {
362
- responses . plan = responses . apply
366
+ responses . plan = responses . apply . map (
367
+ response => {
368
+ if ( response . log ) {
369
+ return response
370
+ }
371
+ return {
372
+ plan : {
373
+ error : response . apply ?. error ?? "" ,
374
+ resources : response . apply ?. resources ?? [ ] ,
375
+ parameters : response . apply ?. parameters ?? [ ] ,
376
+ gitAuthProviders : response . apply ?. gitAuthProviders ?? [ ] ,
377
+ }
378
+ }
379
+ } )
363
380
}
364
381
365
382
const tar = new TarWriter ( )
366
383
responses . parse . forEach ( ( response , index ) => {
367
- response . complete = {
384
+ response . parse = {
368
385
templateVariables : [ ] ,
369
- ...response . complete ,
370
- } as Parse_Complete
386
+ error : "" ,
387
+ readme : new Uint8Array ( ) ,
388
+ ...response . parse ,
389
+ } as ParseComplete
371
390
tar . addFile (
372
391
`${ index } .parse.protobuf` ,
373
- Parse_Response . encode ( response as Parse_Response ) . finish ( ) ,
392
+ Response . encode ( response as Response ) . finish ( ) ,
374
393
)
375
394
} )
376
395
377
- const fillProvisionResponse = (
378
- response : RecursivePartial < Provision_Response > ,
379
- ) => {
380
- response . complete = {
381
- error : "" ,
382
- state : new Uint8Array ( ) ,
383
- resources : [ ] ,
384
- parameters : [ ] ,
385
- gitAuthProviders : [ ] ,
386
- plan : new Uint8Array ( ) ,
387
- ...response . complete ,
388
- } as Provision_Complete
389
- response . complete . resources = response . complete . resources ?. map (
390
- ( resource ) => {
391
- if ( resource . agents ) {
392
- resource . agents = resource . agents ?. map ( ( agent ) => {
393
- if ( agent . apps ) {
394
- agent . apps = agent . apps ?. map ( ( app ) => {
395
- return {
396
- command : "" ,
397
- displayName : "example" ,
398
- external : false ,
399
- icon : "" ,
400
- sharingLevel : AppSharingLevel . PUBLIC ,
401
- slug : "example" ,
402
- subdomain : false ,
403
- url : "" ,
404
- ...app ,
405
- } as App
406
- } )
407
- }
396
+ const fillResource = ( resource : RecursivePartial < Resource > ) => {
397
+ if ( resource . agents ) {
398
+ resource . agents = resource . agents ?. map ( ( agent : RecursivePartial < Agent > ) => {
399
+ if ( agent . apps ) {
400
+ agent . apps = agent . apps ?. map ( ( app : RecursivePartial < App > ) => {
408
401
return {
409
- apps : [ ] ,
410
- architecture : "amd64" ,
411
- connectionTimeoutSeconds : 300 ,
412
- directory : "" ,
413
- env : { } ,
414
- id : randomUUID ( ) ,
415
- metadata : [ ] ,
416
- motdFile : "" ,
417
- name : "dev" ,
418
- operatingSystem : "linux" ,
419
- shutdownScript : "" ,
420
- shutdownScriptTimeoutSeconds : 0 ,
421
- startupScript : "" ,
422
- startupScriptBehavior : "" ,
423
- startupScriptTimeoutSeconds : 300 ,
424
- troubleshootingUrl : "" ,
425
- token : randomUUID ( ) ,
426
- ...agent ,
427
- } as Agent
402
+ command : "" ,
403
+ displayName : "example" ,
404
+ external : false ,
405
+ icon : "" ,
406
+ sharingLevel : AppSharingLevel . PUBLIC ,
407
+ slug : "example" ,
408
+ subdomain : false ,
409
+ url : "" ,
410
+ ...app ,
411
+ } as App
428
412
} )
429
413
}
430
414
return {
431
- agents : [ ] ,
432
- dailyCost : 0 ,
433
- hide : false ,
434
- icon : "" ,
435
- instanceType : "" ,
415
+ apps : [ ] ,
416
+ architecture : "amd64" ,
417
+ connectionTimeoutSeconds : 300 ,
418
+ directory : "" ,
419
+ env : { } ,
420
+ id : randomUUID ( ) ,
436
421
metadata : [ ] ,
422
+ motdFile : "" ,
437
423
name : "dev" ,
438
- type : "echo" ,
439
- ...resource ,
440
- } as Resource
441
- } ,
442
- )
424
+ operatingSystem : "linux" ,
425
+ shutdownScript : "" ,
426
+ shutdownScriptTimeoutSeconds : 0 ,
427
+ startupScript : "" ,
428
+ startupScriptBehavior : "" ,
429
+ startupScriptTimeoutSeconds : 300 ,
430
+ troubleshootingUrl : "" ,
431
+ token : randomUUID ( ) ,
432
+ ...agent ,
433
+ } as Agent
434
+ } )
435
+ }
436
+ return {
437
+ agents : [ ] ,
438
+ dailyCost : 0 ,
439
+ hide : false ,
440
+ icon : "" ,
441
+ instanceType : "" ,
442
+ metadata : [ ] ,
443
+ name : "dev" ,
444
+ type : "echo" ,
445
+ ...resource ,
446
+ } as Resource
443
447
}
444
448
445
449
responses . apply . forEach ( ( response , index ) => {
446
- fillProvisionResponse ( response )
450
+ response . apply = {
451
+ error : "" ,
452
+ state : new Uint8Array ( ) ,
453
+ resources : [ ] ,
454
+ parameters : [ ] ,
455
+ gitAuthProviders : [ ] ,
456
+ ...response . apply ,
457
+ } as ApplyComplete
458
+ response . apply . resources = response . apply . resources ?. map ( fillResource )
447
459
448
460
tar . addFile (
449
- `${ index } .provision. apply.protobuf` ,
450
- Provision_Response . encode ( response as Provision_Response ) . finish ( ) ,
461
+ `${ index } .apply.protobuf` ,
462
+ Response . encode ( response as Response ) . finish ( ) ,
451
463
)
452
464
} )
453
465
responses . plan . forEach ( ( response , index ) => {
454
- fillProvisionResponse ( response )
466
+ response . plan = {
467
+ error : "" ,
468
+ resources : [ ] ,
469
+ parameters : [ ] ,
470
+ gitAuthProviders : [ ] ,
471
+ ...response . plan ,
472
+ } as PlanComplete
473
+ response . plan . resources = response . plan . resources ?. map ( fillResource )
455
474
456
475
tar . addFile (
457
- `${ index } .provision. plan.protobuf` ,
458
- Provision_Response . encode ( response as Provision_Response ) . finish ( ) ,
476
+ `${ index } .plan.protobuf` ,
477
+ Response . encode ( response as Response ) . finish ( ) ,
459
478
)
460
479
} )
461
480
const tarFile = await tar . write ( )
@@ -512,16 +531,21 @@ export const echoResponsesWithParameters = (
512
531
richParameters : RichParameter [ ] ,
513
532
) : EchoProvisionerResponses => {
514
533
return {
534
+ parse : [
535
+ {
536
+ parse : { }
537
+ } ,
538
+ ] ,
515
539
plan : [
516
540
{
517
- complete : {
541
+ plan : {
518
542
parameters : richParameters ,
519
543
} ,
520
544
} ,
521
545
] ,
522
546
apply : [
523
547
{
524
- complete : {
548
+ apply : {
525
549
resources : [
526
550
{
527
551
name : "example" ,
0 commit comments