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 backends map[string]backend.InitFn
|
||||||
var backendsLock sync.Mutex
|
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.
|
// Init initializes the backends map with all our hardcoded backends.
|
||||||
func Init(services *disco.Disco) {
|
func Init(services *disco.Disco) {
|
||||||
backendsLock.Lock()
|
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
|
// 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)
|
log.Printf("[DEBUG] Initializing remote state backend: %s", backendType)
|
||||||
f := getBackendFactory(backendType)
|
f := getBackendFactory(backendType)
|
||||||
if f == nil {
|
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(
|
diags = diags.Append(tfdiags.AttributeValue(
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
"Invalid backend configuration",
|
"Invalid backend configuration",
|
||||||
fmt.Sprintf("There is no backend type named %q.", backendType),
|
detail,
|
||||||
cty.Path(nil).GetAttr("backend"),
|
cty.Path(nil).GetAttr("backend"),
|
||||||
))
|
))
|
||||||
return nil, cty.NilVal, diags
|
return nil, cty.NilVal, diags
|
||||||
|
@ -424,10 +424,15 @@ func (c *InitCommand) initBackend(root *configs.Module, extraConfig rawFlags) (b
|
|||||||
|
|
||||||
bf := backendInit.Backend(backendType)
|
bf := backendInit.Backend(backendType)
|
||||||
if bf == nil {
|
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{
|
diags = diags.Append(&hcl.Diagnostic{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Unsupported backend type",
|
Summary: "Unsupported backend type",
|
||||||
Detail: fmt.Sprintf("There is no backend type named %q.", backendType),
|
Detail: detail,
|
||||||
Subject: &root.Backend.TypeRange,
|
Subject: &root.Backend.TypeRange,
|
||||||
})
|
})
|
||||||
return nil, true, diags
|
return nil, true, diags
|
||||||
|
@ -466,10 +466,15 @@ func (m *Meta) backendConfig(opts *BackendOpts) (*configs.Backend, int, tfdiags.
|
|||||||
|
|
||||||
bf := backendInit.Backend(c.Type)
|
bf := backendInit.Backend(c.Type)
|
||||||
if bf == nil {
|
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{
|
diags = diags.Append(&hcl.Diagnostic{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Invalid backend type",
|
Summary: "Invalid backend type",
|
||||||
Detail: fmt.Sprintf("There is no backend type named %q.", c.Type),
|
Detail: detail,
|
||||||
Subject: &c.TypeRange,
|
Subject: &c.TypeRange,
|
||||||
})
|
})
|
||||||
return nil, 0, diags
|
return nil, 0, diags
|
||||||
|
Loading…
Reference in New Issue
Block a user