Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/internal/internalinter/internalinter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package internalinter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is public? :) So a determined user could still implement it?

Copy link
Contributor Author

@VenelinMartinov VenelinMartinov May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - this is in the internal directory, so no user outside of the bridge can use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay !


type InternalInterface interface {
noimplement()
}

type Internal struct{}

func (s Internal) noimplement() {}
6 changes: 6 additions & 0 deletions pkg/pf/internal/schemashim/attr_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
pfattr "github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
bridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
Expand All @@ -26,6 +27,11 @@ import (
type attrSchema struct {
key string
attr pfutils.Attr
internalinter.Internal
}

func newAttrSchema(key string, attr pfutils.Attr) *attrSchema {
return &attrSchema{key, attr, internalinter.Internal{}}
}

var _ shim.Schema = (*attrSchema)(nil)
Expand Down
4 changes: 3 additions & 1 deletion pkg/pf/internal/schemashim/block_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
bridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
Expand All @@ -28,10 +29,11 @@ import (
type blockSchema struct {
key string
block pfutils.Block
internalinter.Internal
}

func newBlockSchema(key string, block pfutils.Block) *blockSchema {
return &blockSchema{key, block}
return &blockSchema{key, block, internalinter.Internal{}}
}

var _ shim.Schema = (*blockSchema)(nil)
Expand Down
8 changes: 4 additions & 4 deletions pkg/pf/internal/schemashim/custom_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestCustomTypeEmbeddingObjectType(t *testing.T) {
},
}

shimmed := &blockSchema{"key", pfutils.FromBlockLike(raw)}
shimmed := newBlockSchema("key", pfutils.FromBlockLike(raw))
assert.Equal(t, shim.TypeMap, shimmed.Type())
assert.NotNil(t, shimmed.Elem())
_, isPseudoResource := shimmed.Elem().(shim.Resource)
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestCustomListType(t *testing.T) {
},
}

shimmed := &blockSchema{"key", pfutils.FromBlockLike(raw)}
shimmed := newBlockSchema("key", pfutils.FromBlockLike(raw))
assert.Equal(t, shim.TypeList, shimmed.Type())
assert.NotNil(t, shimmed.Elem())
_, isPseudoResource := shimmed.Elem().(shim.Resource)
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestCustomListAttribute(t *testing.T) {
},
}

shimmed := &attrSchema{"key", pfutils.FromAttrLike(raw)}
shimmed := newAttrSchema("key", pfutils.FromAttrLike(raw))
assert.Equal(t, shim.TypeList, shimmed.Type())
assert.NotNil(t, shimmed.Elem())
_, isPseudoResource := shimmed.Elem().(shim.Schema)
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestCustomSetType(t *testing.T) {
},
}

shimmed := &blockSchema{"key", pfutils.FromBlockLike(raw)}
shimmed := newBlockSchema("key", pfutils.FromBlockLike(raw))
assert.Equal(t, shim.TypeSet, shimmed.Type())
assert.NotNil(t, shimmed.Elem())
_, isPseudoResource := shimmed.Elem().(shim.Resource)
Expand Down
2 changes: 2 additions & 0 deletions pkg/pf/internal/schemashim/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package schemashim

import (
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

type schemaOnlyDataSource struct {
tf runtypes.Schema
internalinter.Internal
}

var _ shim.Resource = (*schemaOnlyDataSource)(nil)
Expand Down
3 changes: 2 additions & 1 deletion pkg/pf/internal/schemashim/datasource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package schemashim
import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)
Expand All @@ -27,7 +28,7 @@ func newSchemaOnlyDataSourceMap(dataSources runtypes.DataSources) schemaOnlyData
for _, name := range dataSources.All() {
key := string(name)
v := dataSources.Schema(name)
m[key] = &schemaOnlyDataSource{v}
m[key] = &schemaOnlyDataSource{v, internalinter.Internal{}}
}
return m
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/pf/internal/schemashim/object_pseudoresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)
Expand All @@ -38,6 +39,7 @@ type objectPseudoResource struct {
nestedAttrs map[string]pfutils.Attr
nestedBlocks map[string]pfutils.Block // should have disjoint keys from nestedAttrs
allAttrNames []string
internalinter.Internal
}

func newObjectPseudoResource(t basetypes.ObjectTypable,
Expand Down Expand Up @@ -127,7 +129,7 @@ func (r *objectPseudoResource) GetOk(key string) (shim.Schema, bool) {
// and recurse using attrSchema. This information may be coming out of band from the ObjectTypeable value itself
// when using blocks, see TestCustomTypeEmbeddingObjectType.
if attr, ok := r.nestedAttrs[key]; ok {
return &attrSchema{key, attr}, true
return newAttrSchema(key, attr), true
}

// Nested blocks are similar to attributes:
Expand Down Expand Up @@ -169,6 +171,7 @@ type tuplePseudoResource struct {
schemaOnly
attrs map[string]pfutils.Attr
tuple attr.TypeWithElementTypes
internalinter.Internal
}

type tupElementAttr struct{ e attr.Type }
Expand Down
8 changes: 4 additions & 4 deletions pkg/pf/internal/schemashim/object_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestObjectAttribute(t *testing.T) {
"s": basetypes.StringType{},
},
}
shimmed := &attrSchema{"key", pfutils.FromAttrLike(objectAttr)}
shimmed := newAttrSchema("key", pfutils.FromAttrLike(objectAttr))
assertIsObjectType(t, shimmed)
s := shimmed.Elem().(shim.Resource).Schema().Get("s")
assert.Equal(t, shim.TypeString, s.Type())
Expand All @@ -57,7 +57,7 @@ func TestSingleNestedBlock(t *testing.T) {
b := schema.SingleNestedBlock{
Attributes: simpleObjectAttributes(),
}
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)}
shimmed := newBlockSchema("key", pfutils.FromResourceBlock(b))
assertIsObjectType(t, shimmed)
assert.Equal(t, "obj[c=str,co=str,desc=str,o=str,r=str]", schemaLogicalType(shimmed).String())
r, ok := shimmed.Elem().(shim.Resource)
Expand All @@ -72,7 +72,7 @@ func TestListNestedBlock(t *testing.T) {
Attributes: simpleObjectAttributes(),
},
}
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)}
shimmed := newBlockSchema("key", pfutils.FromResourceBlock(b))
assert.Equal(t, "list[obj[c=str,co=str,desc=str,o=str,r=str]]", schemaLogicalType(shimmed).String())
r, ok := shimmed.Elem().(shim.Resource)
require.True(t, ok, "List-nested TF blocks should be represented as Elem() shim.Resource")
Expand All @@ -86,7 +86,7 @@ func TestSetNestedBlock(t *testing.T) {
Attributes: simpleObjectAttributes(),
},
}
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)}
shimmed := newBlockSchema("key", pfutils.FromResourceBlock(b))
assert.Equal(t, "set[obj[c=str,co=str,desc=str,o=str,r=str]]", schemaLogicalType(shimmed).String())
r, ok := shimmed.Elem().(shim.Resource)
require.True(t, ok, "Set-nested TF blocks should be represented as Elem() shim.Resource")
Expand Down
2 changes: 2 additions & 0 deletions pkg/pf/internal/schemashim/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
Expand All @@ -36,6 +37,7 @@ type SchemaOnlyProvider struct {
tf pfprovider.Provider
resourceMap schemaOnlyResourceMap
dataSourceMap schemaOnlyDataSourceMap
internalinter.Internal
}

func (p *SchemaOnlyProvider) Server(ctx context.Context) (tfprotov6.ProviderServer, error) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/pf/internal/schemashim/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
package schemashim

import (
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

type schemaOnlyResource struct {
tf runtypes.Schema
internalinter.Internal
}

func newSchemaOnlyResource(tf runtypes.Schema) *schemaOnlyResource {
return &schemaOnlyResource{tf, internalinter.Internal{}}
}

var _ shim.Resource = (*schemaOnlyResource)(nil)
Expand Down
28 changes: 16 additions & 12 deletions pkg/pf/internal/schemashim/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,47 @@ package schemashim
import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

// Resource map needs to support Set (mutability) for RenameResourceWithAlias.
func newSchemaOnlyResourceMap(resources runtypes.Resources) schemaOnlyResourceMap {
m := schemaOnlyResourceMap{}
m := schemaOnlyResourceMap{Map: make(map[string]*schemaOnlyResource)}
for _, name := range resources.All() {
key := string(name)
v := resources.Schema(name)
m[key] = &schemaOnlyResource{v}
m.Map[key] = newSchemaOnlyResource(v)
}
return m
}

type schemaOnlyResourceMap map[string]*schemaOnlyResource
type schemaOnlyResourceMap struct {
internalinter.Internal
Map map[string]*schemaOnlyResource
}

var (
_ shim.ResourceMap = schemaOnlyResourceMap{}
_ runtypes.Resources = schemaOnlyResourceMap{}
)

func (m schemaOnlyResourceMap) Len() int {
return len(m)
return len(m.Map)
}

func (m schemaOnlyResourceMap) Get(key string) shim.Resource {
return m[key]
return m.Map[key]
}

func (m schemaOnlyResourceMap) GetOk(key string) (shim.Resource, bool) {
v, ok := m[key]
v, ok := m.Map[key]
return v, ok
}

func (m schemaOnlyResourceMap) Range(each func(key string, value shim.Resource) bool) {
for k, v := range m {
for k, v := range m.Map {
if !each(k, v) {
return
}
Expand All @@ -63,24 +67,24 @@ func (m schemaOnlyResourceMap) Range(each func(key string, value shim.Resource)
func (m schemaOnlyResourceMap) Set(key string, value shim.Resource) {
v, ok := value.(*schemaOnlyResource)
contract.Assertf(ok, "Set must be a %T, found a %T", v, value)
m[key] = v
m.Map[key] = v
}

func (m schemaOnlyResourceMap) All() []runtypes.TypeOrRenamedEntityName {
arr := make([]runtypes.TypeOrRenamedEntityName, 0, len(m))
for k := range m {
arr := make([]runtypes.TypeOrRenamedEntityName, 0, len(m.Map))
for k := range m.Map {
arr = append(arr, runtypes.TypeOrRenamedEntityName(k))
}
return arr
}

func (m schemaOnlyResourceMap) Has(key runtypes.TypeOrRenamedEntityName) bool {
_, ok := m[string(key)]
_, ok := m.Map[string(key)]
return ok
}

func (m schemaOnlyResourceMap) Schema(key runtypes.TypeOrRenamedEntityName) runtypes.Schema {
return m[string(key)].tf
return m.Map[string(key)].tf
}

func (m schemaOnlyResourceMap) IsResources() {}
2 changes: 2 additions & 0 deletions pkg/pf/internal/schemashim/type_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
bridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
Expand All @@ -29,6 +30,7 @@ type typeSchema struct {

// Object types record attr metadata for each field here, if available.
nested map[string]pfutils.Attr
internalinter.Internal
}

var _ shim.Schema = (*typeSchema)(nil)
Expand Down
9 changes: 5 additions & 4 deletions pkg/pf/internal/schemashim/type_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/stretchr/testify/assert"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

Expand All @@ -16,7 +17,7 @@ func TestMapAttribute(t *testing.T) {
Optional: true,
ElementType: basetypes.StringType{},
}
shimmed := &typeSchema{mapAttr.GetType(), nil}
shimmed := &typeSchema{mapAttr.GetType(), nil, internalinter.Internal{}}
assertIsMapType(t, shimmed)
s := shimmed.Elem().(*typeSchema)
assert.Equal(t, shim.TypeString, s.Type())
Expand All @@ -31,18 +32,18 @@ func assertIsMapType(t *testing.T, shimmed shim.Schema) {

func TestInt32Type(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.Int32Type{}, nil}
shimmed := &typeSchema{basetypes.Int32Type{}, nil, internalinter.Internal{}}
assert.Equal(t, shim.TypeInt, shimmed.Type())
}

func TestInt64Type(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.Int64Type{}, nil}
shimmed := &typeSchema{basetypes.Int64Type{}, nil, internalinter.Internal{}}
assert.Equal(t, shim.TypeInt, shimmed.Type())
}

func TestNumberType(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.NumberType{}, nil}
shimmed := &typeSchema{basetypes.NumberType{}, nil, internalinter.Internal{}}
assert.Equal(t, shim.TypeFloat, shimmed.Type())
}
12 changes: 10 additions & 2 deletions pkg/pf/proto/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/internalinter"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

Expand All @@ -26,7 +27,14 @@ var (
_ = shim.SchemaWithWriteOnly(attribute{})
)

type attribute struct{ attr tfprotov6.SchemaAttribute }
type attribute struct {
attr tfprotov6.SchemaAttribute
internalinter.Internal
}

func newAttribute(attr tfprotov6.SchemaAttribute) *attribute {
return &attribute{attr, internalinter.Internal{}}
}

// Simple schema options

Expand Down Expand Up @@ -85,7 +93,7 @@ func (a attribute) Elem() interface{} {
contract.Failf("Invalid attribute nesting: %s", a.attr.NestedType.Nesting)
}
}
return element{a.attr.ValueType(), a.Optional()}.Elem()
return newElement(a.attr.ValueType(), a.Optional()).Elem()
}

// Defaults are applied in the provider binary, not here
Expand Down
Loading