Skip to content

Commit 0b9e04a

Browse files
Merge commit '74af4a3' into vvm/fix_dynamic_parsing_pf
2 parents fe827b3 + 74af4a3 commit 0b9e04a

28 files changed

+720
-377
lines changed

pkg/pf/internal/pfutils/value_to_json.go

Lines changed: 0 additions & 189 deletions
This file was deleted.

pkg/pf/internal/schemashim/datasource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
package schemashim
1616

1717
import (
18+
"context"
19+
1820
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
1921
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
22+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
23+
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
2024
)
2125

2226
type schemaOnlyDataSource struct {
@@ -25,6 +29,12 @@ type schemaOnlyDataSource struct {
2529

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

32+
func (r *schemaOnlyDataSource) SchemaType() valueshim.Type {
33+
protoSchema, err := r.tf.ResourceProtoSchema(context.Background())
34+
contract.AssertNoErrorf(err, "ResourceProtoSchema failed")
35+
return valueshim.FromTType(protoSchema.ValueType())
36+
}
37+
2838
func (r *schemaOnlyDataSource) Schema() shim.SchemaMap {
2939
return r.tf.Shim()
3040
}

pkg/pf/internal/schemashim/object_pseudoresource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/pfutils"
2929
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
30+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
3031
)
3132

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

79+
func (r *objectPseudoResource) SchemaType() valueshim.Type {
80+
return valueshim.FromTType(tftypes.Object{})
81+
}
82+
7883
func (*objectPseudoResource) SchemaVersion() int {
7984
panic("This is an Object type encoded as a shim.Resource, and " +
8085
"SchemaVersion() should not be called on this entity during schema generation")
@@ -197,6 +202,10 @@ func newTuplePseudoResource(t attr.TypeWithElementTypes) shim.Resource {
197202
}
198203
}
199204

205+
func (r *tuplePseudoResource) SchemaType() valueshim.Type {
206+
return valueshim.FromTType(tftypes.Object{})
207+
}
208+
200209
func (*tuplePseudoResource) SchemaVersion() int { panic("TODO") }
201210
func (*tuplePseudoResource) DeprecationMessage() string { panic("TODO") }
202211

pkg/pf/internal/schemashim/resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
package schemashim
1616

1717
import (
18+
"context"
19+
1820
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes"
1921
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
22+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
23+
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
2024
)
2125

2226
type schemaOnlyResource struct {
@@ -37,6 +41,12 @@ func (r *schemaOnlyResource) DeprecationMessage() string {
3741
return r.tf.DeprecationMessage()
3842
}
3943

44+
func (r *schemaOnlyResource) SchemaType() valueshim.Type {
45+
s, err := r.tf.ResourceProtoSchema(context.Background())
46+
contract.AssertNoErrorf(err, "failed to extract schema")
47+
return valueshim.FromTType(s.ValueType())
48+
}
49+
4050
func (*schemaOnlyResource) Importer() shim.ImportFunc {
4151
panic("schemaOnlyResource does not implement runtime operation ImporterFunc")
4252
}

pkg/pf/proto/element.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hashicorp/terraform-plugin-go/tftypes"
1919

2020
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
21+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
2122
)
2223

2324
var (
@@ -101,6 +102,10 @@ func (o elementObject) Schema() shim.SchemaMap {
101102
return elementObjectMap(o.typ)
102103
}
103104

105+
func (o elementObject) SchemaType() valueshim.Type {
106+
return valueshim.FromTType(o.typ)
107+
}
108+
104109
func (m elementObjectMap) Len() int { return len(m.AttributeTypes) }
105110

106111
func (m elementObjectMap) Get(key string) shim.Schema { return getSchemaMap(m, key) }

pkg/pf/proto/object.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
2020

2121
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
22+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
2223
)
2324

2425
var (
@@ -31,6 +32,11 @@ type object struct {
3132
obj tfprotov6.SchemaObject
3233
}
3334

35+
func (o object) SchemaType() valueshim.Type {
36+
ty := o.obj.ValueType()
37+
return valueshim.FromTType(ty)
38+
}
39+
3440
func (o object) Schema() shim.SchemaMap {
3541
contract.Assertf(o.obj.Nesting != tfprotov6.SchemaObjectNestingModeMap,
3642
"%T cannot be a map, since that would require `o` to represent a Map<Object> type", o)

pkg/pf/proto/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
2020

2121
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
22+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
2223
)
2324

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

6364
type resource struct{ r *tfprotov6.Schema }
6465

66+
func (r resource) SchemaType() valueshim.Type {
67+
ty := r.r.Block.ValueType()
68+
return valueshim.FromTType(ty)
69+
}
70+
6571
func (r resource) Schema() shim.SchemaMap {
6672
return blockMap{r.r.Block}
6773
}

pkg/pf/proto/schema.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ package proto
1717
import (
1818
// "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
1919

20+
"github.com/hashicorp/terraform-plugin-go/tftypes"
2021
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
22+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim"
2123
)
2224

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

28+
func (pseudoResource) SchemaType() valueshim.Type {
29+
return valueshim.FromTType(tftypes.Object{}) // not a top-level resource
30+
}
31+
2632
func (pseudoResource) SchemaVersion() int { return 0 }
2733
func (pseudoResource) Importer() shim.ImportFunc { return nil }
2834
func (pseudoResource) Timeouts() *shim.ResourceTimeout { return nil }

0 commit comments

Comments
 (0)