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)
| 27 | // the returned module tree may be incomplete but can still be used carefully |
| 28 | // for static analysis. |
| 29 | func 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 | |
| 52 | func buildTestModules(ctx context.Context, root *Config, walker ModuleWalker) hcl.Diagnostics { |
| 53 | var diags hcl.Diagnostics |