* feat: Allow reading state store configuration from a planfile and using it to prepare a Local backend that uses the state store
* test: Assert that we can get and use state store configuration from a plan file
* test: Add integration test showing that an apply command can use a plan file to configure and use a state store
* test: Add E2E test showing pluggable state storage being used with the full init-plan-apply workflow
* feat: A plan file will report the state storage provider among its required providers, if PSS is in use.
See the code comment added in this commit. This addition does not impact an apply command as the missing provider will be detected before this code is executed. However I'm making this change so that the method is still accurate is being able to return a complete list of providers needed by the plan.
* fix: Include error messages when there is a problem parsing provider or state store config when getting a backend from a planfile
* feat: Add trace logs to BackendForLocalPlan indicating when the provider is launched and the state store is configured
* chore: Small grammar change in error diagnostic
* refactor: Remove suggestions when the plan's state store doesn't match the implementations in the provider
* test: Add test coverage of what happens when the contents of a plan file using PSS doesn't match the resources available in the project
// Should never happen; always indicates a bug in the creation of the plan file
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to read plan from plan file",
"The given plan file does not have a valid backend configuration. This is a bug in the Terraform command that generated this plan file.",
"The given plan file has neither a valid backend nor state store configuration. This is a bug in the Terraform command that generated this plan file.",
))
returnnil,diags
}
// TODO: Update BackendForLocalPlan to use state storage, and plan to be able to contain State Store config details
Detail:fmt.Sprintf("The provider %s (%q) is required to initialize the %q state store, but the matching provider factory is missing. This is a bug in Terraform and should be reported.",
settings.Provider.Source.Type,
settings.Provider.Source,
settings.Type,
),
})
}
configureDiags:=b.Configure(newVal)
diags=diags.Append(configureDiags)
ifconfigureDiags.HasErrors(){
returnnil,diags
provider,err:=factory()
iferr!=nil{
diags=diags.Append(fmt.Errorf("error when obtaining provider instance during state store initialization: %w",err))
returnnil,diags
}
log.Printf("[TRACE] Meta.BackendForLocalPlan: launched instance of provider %s (%q)",
settings.Provider.Source.Type,
settings.Provider.Source,
)
// We purposefully don't have a deferred call to the provider's Close method here because the calling code needs a
// running provider instance inside the returned backend.Backend instance.
// Stopping the provider process is the responsibility of the calling code.
resp:=provider.GetProviderSchema()
iflen(resp.StateStores)==0{
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Provider does not support pluggable state storage",
Detail:fmt.Sprintf("There are no state stores implemented by provider %s (%q)",