-
Notifications
You must be signed in to change notification settings - Fork 10k
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?
Conversation
…nfig parsing needs to be explicitly added
… can use already parsed config
…eds to be refactored
func (c *ShowCommand) getDataFromCloudPlan(plan *cloudplan.SavedPlanBookmark, redacted bool) (*cloudplan.RemotePlanJSON, error) { | ||
mod, diags := c.Meta.loadSingleModule(".") | ||
if diags.HasErrors() { | ||
return nil, diags.Err() | ||
} | ||
|
||
// Set up the backend | ||
b, backendDiags := c.Backend(nil) | ||
if backendDiags.HasErrors() { | ||
return nil, errUnusable(backendDiags.Err(), "cloud plan") | ||
b, diags := c.Meta.prepareBackend(mod) | ||
if diags.HasErrors() { | ||
return nil, errUnusable(diags.Err(), "cloud plan") | ||
} |
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.
This currently doesn't have any test coverage
// TODO(SarahFrench/radeksimko): Use locks from here in opts below | ||
_, lDiags := m.lockedDependencies() | ||
diags = diags.Append(lDiags) | ||
if lDiags.HasErrors() { | ||
return nil, diags | ||
} | ||
|
||
opts = &BackendOpts{ | ||
StateStoreConfig: root.StateStore, | ||
ProviderFactory: factory, | ||
// TODO(SarahFrench/radeksimko): update once other work is merged into main | ||
// Locks: locks, | ||
} |
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 have a (blocked) PR in draft that adds the ability to pass locks into the methods used for initialising an operations backend that uses state_store
. While that work is in progress there are some parts of this code that aren't possible yet but I think it's reasonable to get this completed version into main, to help make other subsequent PRs smaller.
Context / How code before this PR worked
Terraform command implementations access operations backends through the
(Meta).Backend
method. This operations backend may be used for accessing state and/or for running operations.When using the (Meta).Backend method, calling code may include parsed
backend
configuration in theBackendOpts
argument passed into theBackend
method:Or, the calling code could pass a
nil
value into theBackend
method and instead rely on downstream logic to parse anybackend
blocks in the configuration (this happens if the BackendOpts.BackendConfig value is missing).Changes in this PR
This PR adds two new methods:
*(m Meta) prepareBackend - see commit 2ecbed9. This method makes it easier to access an instance of an operations backend. This method parses any
backend
orstate_store
configuration in the root module, provides that input to the(Meta).Backend
method, and returns the operations backend from there.*(m Meta) getStateStoreProviderFactory - see commit 60d5333. This method makes it easy to quickly pull the factory needed for a state store from the available providers, or return the correct errors if data or a provider is missing.
Overall, this PR makes Terraform commands compatible with state stored via
state_store
. The exceptions are commands liketerraform cloud *
which expect a specific type of state storage to be present in the configuration when the user executes the command.Target Release
N/A
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry