From c58f13b70a251d943c41c3c4dffb6e87b3be2b2a Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Fri, 24 May 2024 17:57:44 +0200 Subject: [PATCH] fix(core): issue with partial module resolution and module templates --- core/src/resolve-module.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/core/src/resolve-module.ts b/core/src/resolve-module.ts index 7e2a485fc00..25382850c3e 100644 --- a/core/src/resolve-module.ts +++ b/core/src/resolve-module.ts @@ -487,7 +487,7 @@ export class ModuleResolver { * as well as any immediately resolvable declared build dependencies. */ private getModuleDependenciesFromConfig(rawConfig: ModuleConfig, buildPath: string) { - const configContext = new ModuleConfigContext({ + const contextParams = { garden: this.garden, variables: this.garden.variables, resolvedProviders: this.resolvedProviders, @@ -496,11 +496,16 @@ export class ModuleResolver { buildPath, parentName: rawConfig.parentName, templateName: rawConfig.templateName, - inputs: rawConfig.inputs, + inputs: {}, modules: [], graphResults: this.graphResults, partialRuntimeResolution: true, - }) + } + + // Template inputs are commonly used in module deps, so we need to resolve them first + contextParams.inputs = this.resolveInputs(rawConfig, new ModuleConfigContext(contextParams)) + + const configContext = new ModuleConfigContext(contextParams) const templateRefs = getModuleTemplateReferences(rawConfig, configContext) const templateDeps = templateRefs.filter((d) => d[1] !== rawConfig.name).map((d) => d[1]) @@ -541,6 +546,22 @@ export class ModuleResolver { return getLinkedSources(this.garden, "module") } + private resolveInputs(config: ModuleConfig, configContext: ModuleConfigContext) { + const inputs = cloneDeep(config.inputs || {}) + + if (!config.templateName) { + return inputs + } + + return resolveTemplateStrings({ + value: inputs, + context: configContext, + contextOpts: { allowPartial: true }, + // Note: We're not implementing the YAML source mapping for modules + source: undefined, + }) + } + /** * Resolves and validates a single module configuration. */ @@ -574,14 +595,7 @@ export class ModuleResolver { if (templateName) { const template = this.garden.configTemplates[templateName] - inputs = resolveTemplateStrings({ - value: inputs, - context: new ModuleConfigContext(templateContextParams), - // Not all inputs may need to be resolvable - contextOpts: { allowPartial: true }, - // Note: We're not implementing the YAML source mapping for modules - source: undefined, - }) + inputs = this.resolveInputs(config, new ModuleConfigContext(templateContextParams)) inputs = validateWithPath({ config: inputs,