From 871ecda1a35e2d8dfa48d831f2f18529371137d3 Mon Sep 17 00:00:00 2001 From: VenelinMartinov Date: Mon, 3 Mar 2025 17:22:30 +0200 Subject: [PATCH] Fix PF Int32 types being mistranslated to Floats (#2926) In the PF bridge, we would previously translate PF Int32 types as Float. This PR adds explicit handling for it as well as tests. fixes https://github.com/pulumi/pulumi-terraform-bridge/issues/2924 --- pkg/pf/internal/schemashim/convert_type.go | 2 ++ pkg/pf/internal/schemashim/type_schema_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/pf/internal/schemashim/convert_type.go b/pkg/pf/internal/schemashim/convert_type.go index d1ddb1f2e..0708b118b 100644 --- a/pkg/pf/internal/schemashim/convert_type.go +++ b/pkg/pf/internal/schemashim/convert_type.go @@ -34,6 +34,8 @@ func convertType(typ pfattr.Type) (shim.ValueType, error) { switch { case is(tftypes.Bool): return shim.TypeBool, nil + case typ.Equal(basetypes.Int32Type{}): + return shim.TypeInt, nil case typ.Equal(basetypes.Int64Type{}): // We special case int, since it is a stable type but not present on the wire. return shim.TypeInt, nil diff --git a/pkg/pf/internal/schemashim/type_schema_test.go b/pkg/pf/internal/schemashim/type_schema_test.go index 7cb6e85b2..670baa43a 100644 --- a/pkg/pf/internal/schemashim/type_schema_test.go +++ b/pkg/pf/internal/schemashim/type_schema_test.go @@ -28,3 +28,21 @@ func assertIsMapType(t *testing.T, shimmed shim.Schema) { schema, isTypeSchema := shimmed.Elem().(*typeSchema) assert.Truef(t, isTypeSchema, "expected shim.Elem() to be of type %T", *schema) } + +func TestInt32Type(t *testing.T) { + t.Parallel() + shimmed := &typeSchema{basetypes.Int32Type{}, nil} + assert.Equal(t, shim.TypeInt, shimmed.Type()) +} + +func TestInt64Type(t *testing.T) { + t.Parallel() + shimmed := &typeSchema{basetypes.Int64Type{}, nil} + assert.Equal(t, shim.TypeInt, shimmed.Type()) +} + +func TestNumberType(t *testing.T) { + t.Parallel() + shimmed := &typeSchema{basetypes.NumberType{}, nil} + assert.Equal(t, shim.TypeFloat, shimmed.Type()) +}