Fix GCS backend crash from encryption changes (#1618)

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh 2024-05-07 09:00:14 -04:00 committed by GitHub
parent 6065bc593f
commit 91561ca8e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 5 deletions

View File

@ -8,6 +8,7 @@ ENHANCEMENTS:
* Added `tofu test -json` types to website Machine-Readable UI documentation ([1408](https://github.com/opentofu/opentofu/issues/1408)) * Added `tofu test -json` types to website Machine-Readable UI documentation ([1408](https://github.com/opentofu/opentofu/issues/1408))
BUG FIXES: BUG FIXES:
* Fixed crash in gcs backend when using certain commands ([#1618](https://github.com/opentofu/opentofu/pull/1618))
* Added a check in the `tofu test` to validate that the names of test run blocks do not contain spaces. ([#1489](https://github.com/opentofu/opentofu/pull/1489)) * Added a check in the `tofu test` to validate that the names of test run blocks do not contain spaces. ([#1489](https://github.com/opentofu/opentofu/pull/1489))
* `tofu test` now supports accessing module outputs when the module has no resources. ([#1409](https://github.com/opentofu/opentofu/pull/1409)) * `tofu test` now supports accessing module outputs when the module has no resources. ([#1409](https://github.com/opentofu/opentofu/pull/1409))

View File

@ -55,9 +55,16 @@ func (m *Meta) completePredictWorkspaceName() complete.Predictor {
return nil return nil
} }
// Load the encryption configuration
enc, encDiags := m.Encryption()
if encDiags.HasErrors() {
m.showDiagnostics(encDiags)
return nil
}
b, diags := m.Backend(&BackendOpts{ b, diags := m.Backend(&BackendOpts{
Config: backendConfig, Config: backendConfig,
}, nil) // Don't need state encryption here. }, enc.State())
if diags.HasErrors() { if diags.HasErrors() {
return nil return nil
} }

View File

@ -57,8 +57,15 @@ func (c *ProvidersSchemaCommand) Run(args []string) int {
var diags tfdiags.Diagnostics var diags tfdiags.Diagnostics
enc, encDiags := c.Encryption()
diags = diags.Append(encDiags)
if encDiags.HasErrors() {
c.showDiagnostics(diags)
return 1
}
// Load the backend // Load the backend
b, backendDiags := c.Backend(nil, nil) // Encryption not needed here b, backendDiags := c.Backend(nil, enc.State())
diags = diags.Append(backendDiags) diags = diags.Append(backendDiags)
if backendDiags.HasErrors() { if backendDiags.HasErrors() {
c.showDiagnostics(diags) c.showDiagnostics(diags)
@ -84,7 +91,7 @@ func (c *ProvidersSchemaCommand) Run(args []string) int {
} }
// Build the operation // Build the operation
opReq := c.Operation(b, arguments.ViewJSON, nil) // Encryption not needed here opReq := c.Operation(b, arguments.ViewJSON, enc)
opReq.ConfigDir = cwd opReq.ConfigDir = cwd
opReq.ConfigLoader, err = c.initConfigLoader() opReq.ConfigLoader, err = c.initConfigLoader()
opReq.AllowUnsetVariables = true opReq.AllowUnsetVariables = true

View File

@ -52,6 +52,13 @@ func (c *UnlockCommand) Run(args []string) int {
return 1 return 1
} }
// Load the encryption configuration
enc, encDiags := c.EncryptionFromPath(configPath)
if encDiags.HasErrors() {
c.showDiagnostics(encDiags)
return 1
}
var diags tfdiags.Diagnostics var diags tfdiags.Diagnostics
backendConfig, backendDiags := c.loadBackendConfig(configPath) backendConfig, backendDiags := c.loadBackendConfig(configPath)
@ -64,7 +71,7 @@ func (c *UnlockCommand) Run(args []string) int {
// Load the backend // Load the backend
b, backendDiags := c.Backend(&BackendOpts{ b, backendDiags := c.Backend(&BackendOpts{
Config: backendConfig, Config: backendConfig,
}, nil) // Should not be needed for an unlock }, enc.State())
diags = diags.Append(backendDiags) diags = diags.Append(backendDiags)
if backendDiags.HasErrors() { if backendDiags.HasErrors() {
c.showDiagnostics(diags) c.showDiagnostics(diags)

View File

@ -38,6 +38,13 @@ func (c *WorkspaceListCommand) Run(args []string) int {
return 1 return 1
} }
// Load the encryption configuration
enc, encDiags := c.EncryptionFromPath(configPath)
if encDiags.HasErrors() {
c.showDiagnostics(encDiags)
return 1
}
var diags tfdiags.Diagnostics var diags tfdiags.Diagnostics
backendConfig, backendDiags := c.loadBackendConfig(configPath) backendConfig, backendDiags := c.loadBackendConfig(configPath)
@ -50,7 +57,7 @@ func (c *WorkspaceListCommand) Run(args []string) int {
// Load the backend // Load the backend
b, backendDiags := c.Backend(&BackendOpts{ b, backendDiags := c.Backend(&BackendOpts{
Config: backendConfig, Config: backendConfig,
}, nil) }, enc.State())
diags = diags.Append(backendDiags) diags = diags.Append(backendDiags)
if backendDiags.HasErrors() { if backendDiags.HasErrors() {
c.showDiagnostics(diags) c.showDiagnostics(diags)