Skip to content

Commit 11f23c8

Browse files
Clean up unnecessary shim interfaces
1 parent d0ef58b commit 11f23c8

File tree

15 files changed

+105
-63
lines changed

15 files changed

+105
-63
lines changed

pkg/pf/internal/schemashim/attr_schema.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ func newAttrSchema(key string, attr pfutils.Attr) *attrSchema {
3636

3737
var _ shim.Schema = (*attrSchema)(nil)
3838

39-
var _ shim.SchemaWithWriteOnly = (*attrSchema)(nil)
40-
41-
var _ shim.SchemaWithHasDefault = (*attrSchema)(nil)
42-
4339
func (s *attrSchema) Type() shim.ValueType {
4440
ty := s.attr.GetType()
4541
vt, err := convertType(ty)
@@ -164,3 +160,11 @@ func (*attrSchema) SetElement(config interface{}) (interface{}, error) {
164160
func (*attrSchema) SetHash(v interface{}) int {
165161
panic("SetHash() should not be called during schema generation")
166162
}
163+
164+
func (*attrSchema) SetElementHash(v interface{}) (int, error) {
165+
panic("SetElementHash() should not be called during schema generation")
166+
}
167+
168+
func (*attrSchema) NewSet(v []interface{}) interface{} {
169+
panic("NewSet() should not be called during schema generation")
170+
}

pkg/pf/internal/schemashim/block_schema.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func (*blockSchema) DefaultValue() (interface{}, error) {
136136
return nil, bridge.ErrSchemaDefaultValue
137137
}
138138

139+
func (s *blockSchema) HasDefault() bool {
140+
return false
141+
}
142+
139143
func (*blockSchema) ExactlyOneOf() []string {
140144
panic("ExactlyOneOf() should not be called during schema generation")
141145
}
@@ -148,6 +152,18 @@ func (*blockSchema) SetHash(v interface{}) int {
148152
panic("SetHash() should not be called during schema generation")
149153
}
150154

155+
func (*blockSchema) SetElementHash(v interface{}) (int, error) {
156+
panic("SetElementHash() should not be called during schema generation")
157+
}
158+
159+
func (*blockSchema) NewSet(v []interface{}) interface{} {
160+
panic("NewSet() should not be called during schema generation")
161+
}
162+
151163
func (*blockSchema) StateFunc() shim.SchemaStateFunc {
152164
panic("StateFunc() should not be called during schema generation")
153165
}
166+
167+
func (*blockSchema) WriteOnly() bool {
168+
return false
169+
}

pkg/pf/internal/schemashim/type_schema.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func (*typeSchema) DefaultValue() (interface{}, error) {
9494
return nil, bridge.ErrSchemaDefaultValue
9595
}
9696

97+
func (*typeSchema) HasDefault() bool {
98+
return false
99+
}
100+
97101
func (*typeSchema) Description() string {
98102
return ""
99103
}
@@ -120,3 +124,15 @@ func (*typeSchema) SetElement(config interface{}) (interface{}, error) {
120124
func (*typeSchema) SetHash(v interface{}) int {
121125
panic("SetHash() should not be called during schema generation")
122126
}
127+
128+
func (*typeSchema) SetElementHash(v interface{}) (int, error) {
129+
panic("SetElementHash() should not be called during schema generation")
130+
}
131+
132+
func (*typeSchema) NewSet(v []interface{}) interface{} {
133+
panic("NewSet() should not be called during schema generation")
134+
}
135+
136+
func (*typeSchema) WriteOnly() bool {
137+
return false
138+
}

pkg/pf/proto/attribute.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ import (
2222
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
2323
)
2424

25-
var (
26-
_ = shim.Schema(attribute{})
27-
_ = shim.SchemaWithWriteOnly(attribute{})
28-
)
25+
var _ = shim.Schema(attribute{})
2926

3027
type attribute struct {
3128
attr tfprotov6.SchemaAttribute
@@ -101,6 +98,7 @@ func (a attribute) Elem() interface{} {
10198
func (a attribute) Default() interface{} { return nil }
10299
func (a attribute) DefaultFunc() shim.SchemaDefaultFunc { return nil }
103100
func (a attribute) DefaultValue() (interface{}, error) { return nil, nil }
101+
func (a attribute) HasDefault() bool { return false }
104102

105103
func (a attribute) StateFunc() shim.SchemaStateFunc { return nil }
106104
func (a attribute) ConflictsWith() []string { return nil }
@@ -110,4 +108,6 @@ func (a attribute) SetElement(config interface{}) (interface{}, error) {
110108
panic("UNIMPLIMENTED")
111109
}
112110

113-
func (a attribute) SetHash(v interface{}) int { panic("UNIMPLIMENTED") }
111+
func (a attribute) SetHash(v interface{}) int { panic("UNIMPLIMENTED") }
112+
func (a attribute) SetElementHash(v interface{}) (int, error) { panic("UNIMPLIMENTED") }
113+
func (a attribute) NewSet(v []interface{}) interface{} { panic("UNIMPLIMENTED") }

pkg/pf/proto/block.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (m blockSchema) Required() bool {
134134
func (m blockSchema) Default() interface{} { return nil }
135135
func (m blockSchema) DefaultFunc() shim.SchemaDefaultFunc { return nil }
136136
func (m blockSchema) DefaultValue() (interface{}, error) { return nil, nil }
137+
func (m blockSchema) HasDefault() bool { return false }
137138
func (m blockSchema) Description() string { return m.block.Block.Description }
138139
func (m blockSchema) Computed() bool { return false }
139140
func (m blockSchema) ForceNew() bool { return false }
@@ -150,3 +151,12 @@ func (m blockSchema) SetElement(config interface{}) (interface{}, error) {
150151
panic("Cannot set a an element for a map type")
151152
}
152153
func (m blockSchema) SetHash(v interface{}) int { panic("Cannot set an hash for an object type") }
154+
func (m blockSchema) SetElementHash(v interface{}) (int, error) {
155+
panic("UNIMPLIMENTED")
156+
}
157+
158+
func (m blockSchema) NewSet(v []interface{}) interface{} {
159+
panic("UNIMPLIMENTED")
160+
}
161+
162+
func (m blockSchema) WriteOnly() bool { return false }

pkg/pf/proto/element.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (e element) Required() bool { return false }
9090
func (e element) Default() interface{} { return nil }
9191
func (e element) DefaultFunc() shim.SchemaDefaultFunc { return nil }
9292
func (e element) DefaultValue() (interface{}, error) { return nil, nil }
93+
func (e element) HasDefault() bool { return false }
9394
func (e element) Description() string { return "" }
9495
func (e element) Computed() bool { return false }
9596
func (e element) ForceNew() bool { return false }
@@ -103,6 +104,9 @@ func (e element) Removed() string { return "" }
103104
func (e element) Sensitive() bool { return false }
104105
func (e element) SetElement(interface{}) (interface{}, error) { return nil, nil }
105106
func (e element) SetHash(interface{}) int { return 0 }
107+
func (e element) SetElementHash(interface{}) (int, error) { return 0, nil }
108+
func (e element) NewSet([]interface{}) interface{} { return nil }
109+
func (e element) WriteOnly() bool { return false }
106110

107111
func (o elementObject) DeprecationMessage() string { return "" }
108112
func (o elementObject) Schema() shim.SchemaMap {

pkg/tfbridge/detailed_diff.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ func (differ detailedDiffer) calculateSetHashIndexMap(
363363
convertedElements = append(convertedElements, convertedElem)
364364
}
365365

366-
tfsh, ok := tfs.(shim.SchemaWithSetElementHash)
367-
contract.Assertf(ok, "expected SchemaWithSetElementHash")
368-
369366
// Calculate the identity of each element. Note that the SetHash function can panic
370367
// in the case of custom SetHash functions which get unexpected inputs.
371368
for i, newElem := range convertedElements {
@@ -377,7 +374,7 @@ func (differ detailedDiffer) calculateSetHashIndexMap(
377374
path.String(), r))
378375
}
379376
}()
380-
setHash, err := tfsh.SetElementHash(newElem)
377+
setHash, err := tfs.SetElementHash(newElem)
381378
contract.AssertNoErrorf(
382379
err, "Failed to calculate preview for element in %s: Failed to convert set element", path.String())
383380
return setHash

pkg/tfbridge/diff.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"strings"
2222

2323
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
24-
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
2524
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
2625

2726
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
@@ -109,9 +108,6 @@ func visitPropertyValue(
109108
}
110109

111110
if !e.IsComputed() && !e.IsOutput() {
112-
tfs, ok := tfs.(shim.SchemaWithSetElementHash)
113-
contract.Assertf(ok, "expected SchemaWithSetElementHash")
114-
115111
// We cannot compute the hash for computed values because they are represented by the UnknownVariableValue
116112
// sentinel string, which may not be a legal value of the corresponding schema type, and SetHash does not
117113
// account for computed values. Skipping this for unknown values will result in computing a diff only on the

pkg/tfbridge/schema.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ type conversionContext struct {
291291
// UseTFSetTypes will output TF Set types when converting sets.
292292
// For example, if called on []string{"val1", "val2"}, it will output a TF Set with
293293
// the same values: schema.NewSet([]interface{}{"val1", "val2"}).
294-
// Note that this only works for schemas which implement shim.SchemaWithNewSet.
295294
UseTFSetTypes bool
296295
// DropUnknowns will drop unknown values from the input.
297296
DropUnknowns bool
@@ -471,9 +470,8 @@ func (ctx *conversionContext) makeTerraformInput(
471470
}
472471
}
473472

474-
newSetSchema, ok := tfs.(shim.SchemaWithNewSet)
475-
if ok && tfs.Type() == shim.TypeSet && ctx.UseTFSetTypes {
476-
return newSetSchema.NewSet(arr), nil
473+
if tfs.Type() == shim.TypeSet && ctx.UseTFSetTypes {
474+
return tfs.NewSet(arr), nil
477475
}
478476

479477
return arr, nil

pkg/tfgen/generate.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,18 +1876,16 @@ func (g *Generator) propertyVariable(parentPath paths.TypePath, key string,
18761876
}
18771877
// Suppress write-only attributes via SchemaInfo.Omit
18781878
// TODO[pulumi/pulumi-terraform-bridge#2938] remove when the bridge fully supports write-only fields.
1879-
schemaWithWriteOnly, ok := shimSchema.(shim.SchemaWithWriteOnly)
1880-
if ok {
1881-
if schemaWithWriteOnly.WriteOnly() {
1882-
if info == nil {
1883-
info = make(map[string]*tfbridge.SchemaInfo)
1884-
}
1885-
if val, ok := info[key]; ok {
1886-
val.Omit = true
1887-
} else {
1888-
info[key] = &tfbridge.SchemaInfo{
1889-
Omit: true,
1890-
}
1879+
1880+
if shimSchema.WriteOnly() {
1881+
if info == nil {
1882+
info = make(map[string]*tfbridge.SchemaInfo)
1883+
}
1884+
if val, ok := info[key]; ok {
1885+
val.Omit = true
1886+
} else {
1887+
info[key] = &tfbridge.SchemaInfo{
1888+
Omit: true,
18911889
}
18921890
}
18931891
}

0 commit comments

Comments
 (0)