Skip to content

Commit

Permalink
fix: filter zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
norman-zon committed Dec 12, 2024
1 parent 46604be commit 54cf362
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 11 additions & 1 deletion codegen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
29 changes: 23 additions & 6 deletions remote/remote_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 54cf362

Please sign in to comment.