Skip to content

Commit 953c448

Browse files
committed
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.
1 parent 799ab6c commit 953c448

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎internal/backend/init/init.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import (
4343
var backends map[string]backend.InitFn
4444
var backendsLock sync.Mutex
4545

46+
// RemovedBackends is a record of previously supported backends which have
47+
// since been deprecated and removed.
48+
var RemovedBackends map[string]string
49+
4650
// Init initializes the backends map with all our hardcoded backends.
4751
func Init(services *disco.Disco) {
4852
backendsLock.Lock()
@@ -101,6 +105,10 @@ func Init(services *disco.Disco) {
101105
)
102106
},
103107
}
108+
109+
RemovedBackends = map[string]string{
110+
"etcd": `The "etcd" backend is not supported in Terraform v1.3 or later.`,
111+
}
104112
}
105113

106114
// Backend returns the initialization factory for the given backend, or

‎internal/builtin/providers/terraform/data_source_state.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,15 @@ func getBackend(cfg cty.Value) (backend.Backend, cty.Value, tfdiags.Diagnostics)
193193
log.Printf("[DEBUG] Initializing remote state backend: %s", backendType)
194194
f := getBackendFactory(backendType)
195195
if f == nil {
196+
detail := fmt.Sprintf("There is no backend type named %q.", backendType)
197+
if msg, removed := backendInit.RemovedBackends[backendType]; removed {
198+
detail = msg
199+
}
200+
196201
diags = diags.Append(tfdiags.AttributeValue(
197202
tfdiags.Error,
198203
"Invalid backend configuration",
199-
fmt.Sprintf("There is no backend type named %q.", backendType),
204+
detail,
200205
cty.Path(nil).GetAttr("backend"),
201206
))
202207
return nil, cty.NilVal, diags

‎internal/command/init.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,15 @@ func (c *InitCommand) initBackend(root *configs.Module, extraConfig rawFlags) (b
424424

425425
bf := backendInit.Backend(backendType)
426426
if bf == nil {
427+
detail := fmt.Sprintf("There is no backend type named %q.", backendType)
428+
if msg, removed := backendInit.RemovedBackends[backendType]; removed {
429+
detail = msg
430+
}
431+
427432
diags = diags.Append(&hcl.Diagnostic{
428433
Severity: hcl.DiagError,
429434
Summary: "Unsupported backend type",
430-
Detail: fmt.Sprintf("There is no backend type named %q.", backendType),
435+
Detail: detail,
431436
Subject: &root.Backend.TypeRange,
432437
})
433438
return nil, true, diags

‎internal/command/meta_backend.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,15 @@ func (m *Meta) backendConfig(opts *BackendOpts) (*configs.Backend, int, tfdiags.
466466

467467
bf := backendInit.Backend(c.Type)
468468
if bf == nil {
469+
detail := fmt.Sprintf("There is no backend type named %q.", c.Type)
470+
if msg, removed := backendInit.RemovedBackends[c.Type]; removed {
471+
detail = msg
472+
}
473+
469474
diags = diags.Append(&hcl.Diagnostic{
470475
Severity: hcl.DiagError,
471476
Summary: "Invalid backend type",
472-
Detail: fmt.Sprintf("There is no backend type named %q.", c.Type),
477+
Detail: detail,
473478
Subject: &c.TypeRange,
474479
})
475480
return nil, 0, diags

0 commit comments

Comments
 (0)