Skip to content

Commit

Permalink
fix: fix handling of missing encryption block
Browse files Browse the repository at this point in the history
  • Loading branch information
norman-zon committed Dec 13, 2024
1 parent 7d62483 commit c36b97b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ func (remoteState *remoteStateConfigFile) toConfig() (*remote.RemoteState, error
}

config.Encryption = remoteStateEncryption
} else {
config.Encryption = nil
}

if remoteState.DisableInit != nil {
Expand Down
39 changes: 24 additions & 15 deletions remote/remote_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,33 @@ func (state *RemoteState) GenerateTerraformCode(terragruntOptions *options.Terra
config := state.Config

// Initialize the encryption config based on the key provider
keyProvider, ok := state.Encryption["key_provider"].(string)
if !ok {
return errors.New("key_provider not found in encryption config")
}
var encryption map[string]interface{}

switch {
case state.Encryption == nil:
terragruntOptions.Logger.Debugf("No encryption block in remote_state config")
case len(state.Encryption) == 0:
terragruntOptions.Logger.Debugf("Empty encryption block in remote_state config")
default:
keyProvider, ok := state.Encryption["key_provider"].(string)
if !ok {
return errors.New("key_provider not found in encryption config")
}

encryptionProvider, err := NewRemoteEncryptionKeyProvider(keyProvider)
if err != nil {
return fmt.Errorf("error creating provider: %w", err)
}
encryptionProvider, err := NewRemoteEncryptionKeyProvider(keyProvider)
if err != nil {
return fmt.Errorf("error creating provider: %w", err)
}

err = encryptionProvider.UnmarshalConfig(state.Encryption)
if err != nil {
return err
}
err = encryptionProvider.UnmarshalConfig(state.Encryption)
if err != nil {
return err
}

encryption, err := encryptionProvider.ToMap()
if err != nil {
return fmt.Errorf("error decoding struct to map: %w", err)
encryption, err = encryptionProvider.ToMap()
if err != nil {
return fmt.Errorf("error decoding struct to map: %w", err)
}
}

initializer, hasInitializer := remoteStateInitializers[state.Backend]
Expand Down

0 comments on commit c36b97b

Please sign in to comment.