From e2ecbe74e599d713a19c4d41d946af0c7f3db322 Mon Sep 17 00:00:00 2001 From: Norman Stetter <85173861+norman-zon@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:36:26 +0100 Subject: [PATCH] fix: filter zero values --- codegen/generate.go | 12 +++++++++++- remote/remote_encryption_test.go | 29 +++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/codegen/generate.go b/codegen/generate.go index 61e1a2ba4..0fdb50ab2 100644 --- a/codegen/generate.go +++ b/codegen/generate.go @@ -343,7 +343,17 @@ func RemoteStateConfigToTerraformCode(backend string, config map[string]interfac continue } - ctyVal, err := convertValue(encryption[key]) + value, ok := encryption[key] + if !ok { + continue + } + + // Skip basic types with zero values + if value == "" || value == 0 { + continue + } + + ctyVal, err := convertValue(value) if err != nil { return nil, errors.New(err) } diff --git a/remote/remote_encryption_test.go b/remote/remote_encryption_test.go index e029673ae..b01a46e30 100644 --- a/remote/remote_encryption_test.go +++ b/remote/remote_encryption_test.go @@ -18,7 +18,7 @@ func TestUnmarshalConfig(t *testing.T) { expectedError bool }{ { - name: "PBKDF2 valid config", + name: "PBKDF2 full config", providerType: "pbkdf2", encryptionConfig: map[string]interface{}{ "key_provider": "pbkdf2", @@ -49,7 +49,7 @@ func TestUnmarshalConfig(t *testing.T) { expectedError: true, }, { - name: "AWSKMS valid config", + name: "AWSKMS full config", providerType: "aws_kms", encryptionConfig: map[string]interface{}{ "key_provider": "aws_kms", @@ -78,7 +78,7 @@ func TestUnmarshalConfig(t *testing.T) { expectedError: true, }, { - name: "GCPKMS valid config", + name: "GCPKMS full config", providerType: "gcp_kms", encryptionConfig: map[string]interface{}{ "key_provider": "gcp_kms", @@ -139,7 +139,7 @@ func TestToMap(t *testing.T) { expectedError bool }{ { - name: "PBKDF2 valid config", + name: "PBKDF2 full config", providerType: "pbkdf2", encryptionConfig: map[string]interface{}{ "key_provider": "pbkdf2", @@ -160,7 +160,24 @@ func TestToMap(t *testing.T) { expectedError: false, }, { - name: "AWSKMS valid config", + name: "PBKDF2 partial config", + providerType: "pbkdf2", + encryptionConfig: map[string]interface{}{ + "key_provider": "pbkdf2", + "passphrase": "passphrase", + }, + expectedMap: map[string]interface{}{ + "key_provider": "pbkdf2", + "passphrase": "passphrase", + "key_length": 0, + "iterations": 0, + "salt_length": 0, + "hash_function": "", + }, + expectedError: false, + }, + { + name: "AWSKMS full config", providerType: "aws_kms", encryptionConfig: map[string]interface{}{ "key_provider": "aws_kms", @@ -175,7 +192,7 @@ func TestToMap(t *testing.T) { expectedError: false, }, { - name: "GCPKMS valid config", + name: "GCPKMS full config", providerType: "gcp_kms", encryptionConfig: map[string]interface{}{ "key_provider": "gcp_kms",