@@ -290,8 +290,17 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
290
290
resources := make ([]* proto.Resource , 0 )
291
291
agents := map [string ]* proto.Agent {}
292
292
293
+ tfResources := plan .Config .RootModule .Resources
294
+ var appendResources func (mod * tfjson.ConfigModule )
295
+ appendResources = func (mod * tfjson.ConfigModule ) {
296
+ for _ , module := range mod .ModuleCalls {
297
+ appendResources (module .Module )
298
+ }
299
+ tfResources = append (tfResources , mod .Resources ... )
300
+ }
301
+
293
302
// Store all agents inside the maps!
294
- for _ , resource := range plan . Config . RootModule . Resources {
303
+ for _ , resource := range tfResources {
295
304
if resource .Type != "coder_agent" {
296
305
continue
297
306
}
@@ -340,7 +349,7 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
340
349
agents [resource .Address ] = agent
341
350
}
342
351
343
- for _ , resource := range plan . PlannedValues . RootModule . Resources {
352
+ for _ , resource := range tfResources {
344
353
if resource .Mode == tfjson .DataResourceMode {
345
354
continue
346
355
}
@@ -407,8 +416,17 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
407
416
}
408
417
agents := map [string ]* proto.Agent {}
409
418
419
+ tfResources := state .Values .RootModule .Resources
420
+ var appendResources func (resource * tfjson.StateModule )
421
+ appendResources = func (mod * tfjson.StateModule ) {
422
+ for _ , module := range mod .ChildModules {
423
+ appendResources (module )
424
+ }
425
+ tfResources = append (tfResources , mod .Resources ... )
426
+ }
427
+
410
428
// Store all agents inside the maps!
411
- for _ , resource := range state . Values . RootModule . Resources {
429
+ for _ , resource := range tfResources {
412
430
if resource .Type != "coder_agent" {
413
431
continue
414
432
}
@@ -439,7 +457,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
439
457
}
440
458
441
459
// Manually associate agents with instance IDs.
442
- for _ , resource := range state . Values . RootModule . Resources {
460
+ for _ , resource := range tfResources {
443
461
if resource .Type != "coder_agent_instance" {
444
462
continue
445
463
}
@@ -471,7 +489,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
471
489
}
472
490
}
473
491
474
- for _ , resource := range state . Values . RootModule . Resources {
492
+ for _ , resource := range tfResources {
475
493
if resource .Mode == tfjson .DataResourceMode {
476
494
continue
477
495
}
0 commit comments