From 0771a214d8e19513bdaac338b7b28c8b50eaa202 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 6 Dec 2021 14:28:34 -0500 Subject: [PATCH] skip provider resolution when there are errors If there are errors loading the configuration, don't try to resolve the provider names, as those names may not even be valid. --- internal/configs/config_build.go | 10 +++++++--- .../config-diagnostics/invalid-provider/errors | 1 + .../config-diagnostics/invalid-provider/main.tf | 3 +++ .../config-diagnostics/invalid-provider/mod/main.tf | 2 ++ .../config-diagnostics/invalid-provider/warnings | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 internal/configs/testdata/config-diagnostics/invalid-provider/errors create mode 100644 internal/configs/testdata/config-diagnostics/invalid-provider/main.tf create mode 100644 internal/configs/testdata/config-diagnostics/invalid-provider/mod/main.tf create mode 100644 internal/configs/testdata/config-diagnostics/invalid-provider/warnings diff --git a/internal/configs/config_build.go b/internal/configs/config_build.go index e7ebe5021..96dcbed25 100644 --- a/internal/configs/config_build.go +++ b/internal/configs/config_build.go @@ -23,9 +23,13 @@ func BuildConfig(root *Module, walker ModuleWalker) (*Config, hcl.Diagnostics) { cfg.Root = cfg // Root module is self-referential. cfg.Children, diags = buildChildModules(cfg, walker) - // Now that the config is built, we can connect the provider names to all - // the known types for validation. - cfg.resolveProviderTypes() + // Skip provider resolution if there are any errors, since the provider + // configurations themselves may not be valid. + if !diags.HasErrors() { + // Now that the config is built, we can connect the provider names to all + // the known types for validation. + cfg.resolveProviderTypes() + } diags = append(diags, validateProviderConfigs(nil, cfg, false)...) diff --git a/internal/configs/testdata/config-diagnostics/invalid-provider/errors b/internal/configs/testdata/config-diagnostics/invalid-provider/errors new file mode 100644 index 000000000..359d47600 --- /dev/null +++ b/internal/configs/testdata/config-diagnostics/invalid-provider/errors @@ -0,0 +1 @@ +main.tf:1,1-20: Invalid provider local name; crash_es is an invalid provider local name diff --git a/internal/configs/testdata/config-diagnostics/invalid-provider/main.tf b/internal/configs/testdata/config-diagnostics/invalid-provider/main.tf new file mode 100644 index 000000000..ba8468469 --- /dev/null +++ b/internal/configs/testdata/config-diagnostics/invalid-provider/main.tf @@ -0,0 +1,3 @@ +module "mod" { + source = "./mod" +} diff --git a/internal/configs/testdata/config-diagnostics/invalid-provider/mod/main.tf b/internal/configs/testdata/config-diagnostics/invalid-provider/mod/main.tf new file mode 100644 index 000000000..f50ced1fe --- /dev/null +++ b/internal/configs/testdata/config-diagnostics/invalid-provider/mod/main.tf @@ -0,0 +1,2 @@ +provider "crash_es" { +} diff --git a/internal/configs/testdata/config-diagnostics/invalid-provider/warnings b/internal/configs/testdata/config-diagnostics/invalid-provider/warnings new file mode 100644 index 000000000..8bdc68eeb --- /dev/null +++ b/internal/configs/testdata/config-diagnostics/invalid-provider/warnings @@ -0,0 +1 @@ +Empty provider configuration blocks are not required