From 196e009c764d59deccd8356dac03f04829501e62 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Aug 2024 10:32:13 -0400 Subject: [PATCH] validate config generation Have the resource validation node check if config generation is possible when there is no config given. We can't check the output path here because that is a plan option, so a final suggestion to use -generate-config-out will have to wait until plan. --- internal/terraform/transform_config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/terraform/transform_config.go b/internal/terraform/transform_config.go index 198366a803..81c13f8ba2 100644 --- a/internal/terraform/transform_config.go +++ b/internal/terraform/transform_config.go @@ -192,9 +192,14 @@ func (t *ConfigTransformer) transformSingle(g *Graph, config *configs.Config) er toDiags = toDiags.Append(hd) to, td := addrs.ParseAbsResourceInstance(traversal) toDiags = toDiags.Append(td) - canGenerate := !toDiags.HasErrors() && to.Resource.Key == addrs.NoKey - if t.generateConfigPathForImportTargets != "" && canGenerate { + // Check if we can generate config for this target. During + // validation we won't have a valid config path, but we should still + // add the Node since it will only be used for further validation. + canGenerate := !toDiags.HasErrors() && to.Resource.Key == addrs.NoKey && + (t.op == walkValidate || t.generateConfigPathForImportTargets != "") + + if canGenerate { log.Printf("[DEBUG] ConfigTransformer: adding config generation node for %s", i.Config.ToResource) // TODO: if config generation is ever supported for for_each