Skip to content

Commit

Permalink
fix(core): issue with partial module resolution and module templates
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed May 24, 2024
1 parent 11059b7 commit c58f13b
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions core/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = <string[]>templateRefs.filter((d) => d[1] !== rawConfig.name).map((d) => d[1])
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c58f13b

Please sign in to comment.