From 953c448f9acf1a3f420ab1b73e89be90358640f3 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 28 Jun 2022 13:13:20 -0400 Subject: [PATCH] add simple error indicating backend removal There are no good options for inserting diagnostics into the backend lookup, or creating a backend which reports it's removal because none of the init or GetSchema functions return any errors. Keep a registry of the removed backend so that we can at least notify users that a backend was removed vs an invalid name. --- internal/backend/init/init.go | 8 ++++++++ internal/builtin/providers/terraform/data_source_state.go | 7 ++++++- internal/command/init.go | 7 ++++++- internal/command/meta_backend.go | 7 ++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/backend/init/init.go b/internal/backend/init/init.go index 0e0e1bf86e..34bb90462a 100644 --- a/internal/backend/init/init.go +++ b/internal/backend/init/init.go @@ -43,6 +43,10 @@ import ( var backends map[string]backend.InitFn var backendsLock sync.Mutex +// RemovedBackends is a record of previously supported backends which have +// since been deprecated and removed. +var RemovedBackends map[string]string + // Init initializes the backends map with all our hardcoded backends. func Init(services *disco.Disco) { backendsLock.Lock() @@ -101,6 +105,10 @@ func Init(services *disco.Disco) { ) }, } + + RemovedBackends = map[string]string{ + "etcd": `The "etcd" backend is not supported in Terraform v1.3 or later.`, + } } // Backend returns the initialization factory for the given backend, or diff --git a/internal/builtin/providers/terraform/data_source_state.go b/internal/builtin/providers/terraform/data_source_state.go index c2088c8f31..f69a835343 100644 --- a/internal/builtin/providers/terraform/data_source_state.go +++ b/internal/builtin/providers/terraform/data_source_state.go @@ -193,10 +193,15 @@ func getBackend(cfg cty.Value) (backend.Backend, cty.Value, tfdiags.Diagnostics) log.Printf("[DEBUG] Initializing remote state backend: %s", backendType) f := getBackendFactory(backendType) if f == nil { + detail := fmt.Sprintf("There is no backend type named %q.", backendType) + if msg, removed := backendInit.RemovedBackends[backendType]; removed { + detail = msg + } + diags = diags.Append(tfdiags.AttributeValue( tfdiags.Error, "Invalid backend configuration", - fmt.Sprintf("There is no backend type named %q.", backendType), + detail, cty.Path(nil).GetAttr("backend"), )) return nil, cty.NilVal, diags diff --git a/internal/command/init.go b/internal/command/init.go index 415cbe06d9..e4950ed8ba 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -424,10 +424,15 @@ func (c *InitCommand) initBackend(root *configs.Module, extraConfig rawFlags) (b bf := backendInit.Backend(backendType) if bf == nil { + detail := fmt.Sprintf("There is no backend type named %q.", backendType) + if msg, removed := backendInit.RemovedBackends[backendType]; removed { + detail = msg + } + diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Unsupported backend type", - Detail: fmt.Sprintf("There is no backend type named %q.", backendType), + Detail: detail, Subject: &root.Backend.TypeRange, }) return nil, true, diags diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index 638be81df1..43e49152cf 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -466,10 +466,15 @@ func (m *Meta) backendConfig(opts *BackendOpts) (*configs.Backend, int, tfdiags. bf := backendInit.Backend(c.Type) if bf == nil { + detail := fmt.Sprintf("There is no backend type named %q.", c.Type) + if msg, removed := backendInit.RemovedBackends[c.Type]; removed { + detail = msg + } + diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Invalid backend type", - Detail: fmt.Sprintf("There is no backend type named %q.", c.Type), + Detail: detail, Subject: &c.TypeRange, }) return nil, 0, diags