Skip to content
Closed
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
189 changes: 0 additions & 189 deletions pkg/pf/internal/pfutils/value_to_json.go

This file was deleted.

10 changes: 10 additions & 0 deletions pkg/pf/internal/schemashim/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
package schemashim

import (
"context"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

type schemaOnlyDataSource struct {
Expand All @@ -25,6 +29,12 @@ type schemaOnlyDataSource struct {

var _ shim.Resource = (*schemaOnlyDataSource)(nil)

func (r *schemaOnlyDataSource) SchemaType() valueshim.Type {
protoSchema, err := r.tf.ResourceProtoSchema(context.Background())
contract.AssertNoErrorf(err, "ResourceProtoSchema failed")
return valueshim.FromTType(protoSchema.ValueType())
}

func (r *schemaOnlyDataSource) Schema() shim.SchemaMap {
return r.tf.Shim()
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/pf/internal/schemashim/object_pseudoresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

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

// An Object type that masquerades as a Resource. This is a workaround to reusing tfgen code for generating schemas,
Expand Down Expand Up @@ -75,6 +76,10 @@ func (r *objectPseudoResource) Schema() shim.SchemaMap {
return r
}

func (r *objectPseudoResource) SchemaType() valueshim.Type {
return valueshim.FromTType(tftypes.Object{})
}

func (*objectPseudoResource) SchemaVersion() int {
panic("This is an Object type encoded as a shim.Resource, and " +
"SchemaVersion() should not be called on this entity during schema generation")
Expand Down Expand Up @@ -197,6 +202,10 @@ func newTuplePseudoResource(t attr.TypeWithElementTypes) shim.Resource {
}
}

func (r *tuplePseudoResource) SchemaType() valueshim.Type {
return valueshim.FromTType(tftypes.Object{})
}

func (*tuplePseudoResource) SchemaVersion() int { panic("TODO") }
func (*tuplePseudoResource) DeprecationMessage() string { panic("TODO") }

Expand Down
10 changes: 10 additions & 0 deletions pkg/pf/internal/schemashim/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
package schemashim

import (
"context"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

type schemaOnlyResource struct {
Expand All @@ -37,6 +41,12 @@ func (r *schemaOnlyResource) DeprecationMessage() string {
return r.tf.DeprecationMessage()
}

func (r *schemaOnlyResource) SchemaType() valueshim.Type {
s, err := r.tf.ResourceProtoSchema(context.Background())
contract.AssertNoErrorf(err, "failed to extract schema")
return valueshim.FromTType(s.ValueType())
}

func (*schemaOnlyResource) Importer() shim.ImportFunc {
panic("schemaOnlyResource does not implement runtime operation ImporterFunc")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/pf/proto/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-go/tftypes"

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

var (
Expand Down Expand Up @@ -101,6 +102,10 @@ func (o elementObject) Schema() shim.SchemaMap {
return elementObjectMap(o.typ)
}

func (o elementObject) SchemaType() valueshim.Type {
return valueshim.FromTType(o.typ)
}

func (m elementObjectMap) Len() int { return len(m.AttributeTypes) }

func (m elementObjectMap) Get(key string) shim.Schema { return getSchemaMap(m, key) }
Expand Down
6 changes: 6 additions & 0 deletions pkg/pf/proto/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

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

var (
Expand All @@ -31,6 +32,11 @@ type object struct {
obj tfprotov6.SchemaObject
}

func (o object) SchemaType() valueshim.Type {
ty := o.obj.ValueType()
return valueshim.FromTType(ty)
}

func (o object) Schema() shim.SchemaMap {
contract.Assertf(o.obj.Nesting != tfprotov6.SchemaObjectNestingModeMap,
"%T cannot be a map, since that would require `o` to represent a Map<Object> type", o)
Expand Down
6 changes: 6 additions & 0 deletions pkg/pf/proto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

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

var (
Expand Down Expand Up @@ -62,6 +63,11 @@ func (m resourceMap) Set(key string, value shim.Resource) {

type resource struct{ r *tfprotov6.Schema }

func (r resource) SchemaType() valueshim.Type {
ty := r.r.Block.ValueType()
return valueshim.FromTType(ty)
}

func (r resource) Schema() shim.SchemaMap {
return blockMap{r.r.Block}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/pf/proto/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ package proto
import (
// "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/hashicorp/terraform-plugin-go/tftypes"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
)

// pseudoResource represents a type that must pretent to be a [shim.Resource], but does not represent a resource.
type pseudoResource struct{}

func (pseudoResource) SchemaType() valueshim.Type {
return valueshim.FromTType(tftypes.Object{}) // not a top-level resource
}

func (pseudoResource) SchemaVersion() int { return 0 }
func (pseudoResource) Importer() shim.ImportFunc { return nil }
func (pseudoResource) Timeouts() *shim.ResourceTimeout { return nil }
Expand Down
Loading