From 078e63ebe7fe5b1366b622e4da54bfef0387740c Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Mon, 28 Oct 2024 14:46:04 -0700 Subject: [PATCH] Allow for a Type: 'boolean' to validate when property value is a stringified bool --- pkg/tfbridge/typechecker/typechecker.go | 3 ++- pkg/tfbridge/typechecker/typechecker_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/tfbridge/typechecker/typechecker.go b/pkg/tfbridge/typechecker/typechecker.go index c84cbb7a7..3a96a4101 100644 --- a/pkg/tfbridge/typechecker/typechecker.go +++ b/pkg/tfbridge/typechecker/typechecker.go @@ -161,7 +161,8 @@ func (v *TypeChecker) validatePropertyValue( switch typeSpec.Type { case "boolean": - if !propertyValue.IsBool() { + // The bridge permits the strings "true" and "false" to read as boolean, so allow strings. + if !propertyValue.IsBool() && !propertyValue.IsString() { return []Failure{newTypeFailure(propertyPath, typeSpec.Type, propertyValue)} } return nil diff --git a/pkg/tfbridge/typechecker/typechecker_test.go b/pkg/tfbridge/typechecker/typechecker_test.go index a8007a3ad..f9f6a5ebb 100644 --- a/pkg/tfbridge/typechecker/typechecker_test.go +++ b/pkg/tfbridge/typechecker/typechecker_test.go @@ -1631,6 +1631,11 @@ func TestValidateConfigType(t *testing.T) { })), }), }, + { + name: "allows_bool_strings", + inputName: "skipMetadataApiCheck", + input: resource.PropertyValue{V: "true"}, + }, } for _, tc := range testCases { tc := tc @@ -1661,6 +1666,11 @@ func TestValidateConfigType(t *testing.T) { }, }, }, + "skipMetadataApiCheck": { + TypeSpec: pschema.TypeSpec{ + Type: "boolean", + }, + }, }, }, }