Skip to content

Commit

Permalink
Enable typechecker to allow stringified boolean property values on Ty…
Browse files Browse the repository at this point in the history
…pe: "boolean" (#2519)

This pull request allows for strings called "true" or "false" that are
set on the "boolean" type to pass the type checker.

This change is necessary because the JSON-style config encoding, which
powers the TypeScript, Python, .NET, and Java SDKS,
returns a string for config values with a type override to "boolean".
The engine can handle this regarding functionality,
but the type checker sends an unnecessary warning to affected SDKs.

Fixes #2339

For additional context, see changes made in
#2310.
  • Loading branch information
guineveresaenger authored Oct 29, 2024
2 parents bbb5f5c + 05c8368 commit 2cdff49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/tfbridge/typechecker/typechecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@ func (v *TypeChecker) validatePropertyValue(

switch typeSpec.Type {
case "boolean":
if !propertyValue.IsBool() {
// Check for strings that are values "true" or "false".
//TODO: Remove the boolString condition when https://github.com/pulumi/pulumi-terraform-bridge/issues/2520
// is resolved. This is a workaround for the config encoding not honoring type overrides.
var boolString bool
if propertyValue.IsString() {
if propertyValue.StringValue() == "true" || propertyValue.StringValue() == "false" {
boolString = true
}
}
if !propertyValue.IsBool() && !boolString {
return []Failure{newTypeFailure(propertyPath, typeSpec.Type, propertyValue)}
}
return nil
Expand Down
13 changes: 13 additions & 0 deletions pkg/tfbridge/typechecker/typechecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,14 @@ func TestValidateConfigType(t *testing.T) {
})),
}),
},
{
//TODO: Remove this test when https://github.com/pulumi/pulumi-terraform-bridge/issues/2520 is resolved.
// This tests a workaround path to keep the type checker from tripping on missing functionality in the
// config encoding and will fail once that is fixed.
name: "allows_bool_strings",
inputName: "skipMetadataApiCheck",
input: resource.PropertyValue{V: "true"},
},
}
for _, tc := range testCases {
tc := tc
Expand Down Expand Up @@ -1661,6 +1669,11 @@ func TestValidateConfigType(t *testing.T) {
},
},
},
"skipMetadataApiCheck": {
TypeSpec: pschema.TypeSpec{
Type: "boolean",
},
},
},
},
}
Expand Down

0 comments on commit 2cdff49

Please sign in to comment.