diff --git a/builtin/providers/terraform/data_source_state.go b/builtin/providers/terraform/data_source_state.go index accc356df..d245954f4 100644 --- a/builtin/providers/terraform/data_source_state.go +++ b/builtin/providers/terraform/data_source_state.go @@ -48,7 +48,7 @@ func dataSourceRemoteStateValidate(cfg cty.Value) tfdiags.Diagnostics { // Getting the backend implicitly validates the configuration for it, // but we can only do that if it's all known already. if cfg.GetAttr("config").IsWhollyKnown() && cfg.GetAttr("backend").IsKnown() { - _, moreDiags := getBackend(cfg) + _, _, moreDiags := getBackend(cfg) diags = diags.Append(moreDiags) } else { // Otherwise we'll just type-check the config object itself. @@ -81,9 +81,15 @@ func dataSourceRemoteStateValidate(cfg cty.Value) tfdiags.Diagnostics { func dataSourceRemoteStateRead(d cty.Value) (cty.Value, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics - b, moreDiags := getBackend(d) + b, cfg, moreDiags := getBackend(d) diags = diags.Append(moreDiags) - if diags.HasErrors() { + if moreDiags.HasErrors() { + return cty.NilVal, diags + } + + configureDiags := b.Configure(cfg) + if configureDiags.HasErrors() { + diags = diags.Append(configureDiags.Err()) return cty.NilVal, diags } @@ -152,7 +158,7 @@ func dataSourceRemoteStateRead(d cty.Value) (cty.Value, tfdiags.Diagnostics) { return cty.ObjectVal(newState), diags } -func getBackend(cfg cty.Value) (backend.Backend, tfdiags.Diagnostics) { +func getBackend(cfg cty.Value) (backend.Backend, cty.Value, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics backendType := cfg.GetAttr("backend").AsString() @@ -173,7 +179,7 @@ func getBackend(cfg cty.Value) (backend.Backend, tfdiags.Diagnostics) { fmt.Sprintf("There is no backend type named %q.", backendType), cty.Path(nil).GetAttr("backend"), )) - return nil, diags + return nil, cty.NilVal, diags } b := f() @@ -199,21 +205,14 @@ func getBackend(cfg cty.Value) (backend.Backend, tfdiags.Diagnostics) { tfdiags.FormatError(err)), cty.Path(nil).GetAttr("config"), )) - return nil, diags + return nil, cty.NilVal, diags } newVal, validateDiags := b.PrepareConfig(configVal) diags = diags.Append(validateDiags) if validateDiags.HasErrors() { - return nil, diags - } - configVal = newVal - - configureDiags := b.Configure(configVal) - if configureDiags.HasErrors() { - diags = diags.Append(configureDiags.Err()) - return nil, diags + return nil, cty.NilVal, diags } - return b, diags + return b, newVal, diags }