-
Notifications
You must be signed in to change notification settings - Fork 10.1k
PSS: Update how commands access backends, so both backend and state_store configuration can be used
#37569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
PSS: Update how commands access backends, so both backend and state_store configuration can be used
#37569
Changes from 13 commits
229f42f
082f481
70c4f39
44b9e4a
5bacdce
7d5f88d
323b179
1afde44
5ba4a6f
ae6db5c
be43ec6
823c5b4
96269e9
b71931c
9ca9710
c8b001c
6698109
84fb3f0
733618f
7497796
0cf0769
b07a903
99fc261
e9b15ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1580,6 +1580,63 @@ func (m *Meta) updateSavedBackendHash(cHash int, sMgr *clistate.LocalState) tfdi | |
| return diags | ||
| } | ||
|
|
||
| // prepareBackend returns an operations backend that may use a backend, cloud, or state_store block for state storage. | ||
| // This method should be used in NON-init operations only; it's incapable of processing new init command CLI flags used | ||
| // for partial configuration, however it will use the backend state file to use partial configuration from a previous | ||
| // init command. | ||
| func (m *Meta) prepareBackend(root *configs.Module) (backendrun.OperationsBackend, tfdiags.Diagnostics) { | ||
|
||
| var diags tfdiags.Diagnostics | ||
|
|
||
| var opts *BackendOpts | ||
| switch { | ||
| case root.Backend != nil: | ||
| opts = &BackendOpts{ | ||
| BackendConfig: root.Backend, | ||
| } | ||
| case root.CloudConfig != nil: | ||
| backendConfig := root.CloudConfig.ToBackendConfig() | ||
| opts = &BackendOpts{ | ||
| BackendConfig: &backendConfig, | ||
| } | ||
| case root.StateStore != nil: | ||
| // In addition to config, use of a state_store requires | ||
| // provider factory and provider locks data | ||
| locks, lDiags := m.lockedDependencies() | ||
| diags = diags.Append(lDiags) | ||
| if lDiags.HasErrors() { | ||
| return nil, diags | ||
| } | ||
|
|
||
| factory, fDiags := m.GetStateStoreProviderFactory(root.StateStore, locks) | ||
| diags = diags.Append(fDiags) | ||
| if fDiags.HasErrors() { | ||
| return nil, diags | ||
| } | ||
|
|
||
| opts = &BackendOpts{ | ||
| StateStoreConfig: root.StateStore, | ||
| ProviderFactory: factory, | ||
| Locks: locks, | ||
| } | ||
| default: | ||
| // there is no config; defaults to local state storage | ||
| opts = &BackendOpts{} | ||
| } | ||
|
|
||
| // This method should not be used for init commands, | ||
| // so we always set this value as false. | ||
| opts.Init = false | ||
|
|
||
| // Load the backend | ||
| be, beDiags := m.Backend(opts) | ||
| diags = diags.Append(beDiags) | ||
| if beDiags.HasErrors() { | ||
| return nil, diags | ||
| } | ||
|
|
||
| return be, diags | ||
| } | ||
|
|
||
| //------------------------------------------------------------------- | ||
| // State Store Config Scenarios | ||
| // The functions below cover handling all the various scenarios that | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is scoped to this ticket: https://hashicorp.atlassian.net/browse/TF-28374
I've linked here from that ticket.