Skip to content

Commit 2cdff49

Browse files
Enable typechecker to allow stringified boolean property values on Type: "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.
2 parents bbb5f5c + 05c8368 commit 2cdff49

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pkg/tfbridge/typechecker/typechecker.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ func (v *TypeChecker) validatePropertyValue(
161161

162162
switch typeSpec.Type {
163163
case "boolean":
164-
if !propertyValue.IsBool() {
164+
// Check for strings that are values "true" or "false".
165+
//TODO: Remove the boolString condition when https://github.com/pulumi/pulumi-terraform-bridge/issues/2520
166+
// is resolved. This is a workaround for the config encoding not honoring type overrides.
167+
var boolString bool
168+
if propertyValue.IsString() {
169+
if propertyValue.StringValue() == "true" || propertyValue.StringValue() == "false" {
170+
boolString = true
171+
}
172+
}
173+
if !propertyValue.IsBool() && !boolString {
165174
return []Failure{newTypeFailure(propertyPath, typeSpec.Type, propertyValue)}
166175
}
167176
return nil

pkg/tfbridge/typechecker/typechecker_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,14 @@ func TestValidateConfigType(t *testing.T) {
16311631
})),
16321632
}),
16331633
},
1634+
{
1635+
//TODO: Remove this test when https://github.com/pulumi/pulumi-terraform-bridge/issues/2520 is resolved.
1636+
// This tests a workaround path to keep the type checker from tripping on missing functionality in the
1637+
// config encoding and will fail once that is fixed.
1638+
name: "allows_bool_strings",
1639+
inputName: "skipMetadataApiCheck",
1640+
input: resource.PropertyValue{V: "true"},
1641+
},
16341642
}
16351643
for _, tc := range testCases {
16361644
tc := tc
@@ -1661,6 +1669,11 @@ func TestValidateConfigType(t *testing.T) {
16611669
},
16621670
},
16631671
},
1672+
"skipMetadataApiCheck": {
1673+
TypeSpec: pschema.TypeSpec{
1674+
Type: "boolean",
1675+
},
1676+
},
16641677
},
16651678
},
16661679
}

0 commit comments

Comments
 (0)