MCPcopy
hub / github.com/opentofu/opentofu / BuildConfig

Function BuildConfig

internal/configs/config_build.go:29–50  ·  view source on GitHub ↗

BuildConfig constructs a Config from a root module by loading all of its descendent modules via the given ModuleWalker. The result is a module tree that has so far only had basic module- and file-level invariants validated. If the returned diagnostics contains errors, the returned module tree may b

(ctx context.Context, root *Module, walker ModuleWalker)

Source from the content-addressed store, hash-verified

27// the returned module tree may be incomplete but can still be used carefully
28// for static analysis.
29func BuildConfig(ctx context.Context, root *Module, walker ModuleWalker) (*Config, hcl.Diagnostics) {
30 var diags hcl.Diagnostics
31 cfg := &Config{
32 Module: root,
33 }
34 cfg.Root = cfg // Root module is self-referential.
35 cfg.Children, diags = buildChildModules(ctx, cfg, walker)
36 diags = append(diags, buildTestModules(ctx, cfg, walker)...)
37
38 // Skip provider resolution if there are any errors, since the provider
39 // configurations themselves may not be valid.
40 if !diags.HasErrors() {
41 // Now that the config is built, we can connect the provider names to all
42 // the known types for validation.
43 providers := cfg.resolveProviderTypes()
44 cfg.resolveProviderTypesForTests(providers)
45 diags = append(diags, validateProviderConfigs(nil, cfg, nil)...)
46 diags = append(diags, validateProviderConfigsForTests(cfg)...)
47 }
48
49 return cfg, diags
50}
51
52func buildTestModules(ctx context.Context, root *Config, walker ModuleWalker) hcl.Diagnostics {
53 var diags hcl.Diagnostics

Calls 7

HasErrorsMethod · 0.95
resolveProviderTypesMethod · 0.95
buildChildModulesFunction · 0.85
buildTestModulesFunction · 0.85
validateProviderConfigsFunction · 0.85