mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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.
This commit is contained in:
parent
799ab6c951
commit
953c448f9a
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user