Skip to content

Commit 9284425

Browse files
Fix PF WriteOnly attributes skip (#3043)
~This is a pure refactor. It removes a redundant internal interface from the PF bridge.~ This started as a refactor but is actually a bug fix. Looks like we did not implement the PF portion of #2933 correctly. We also had a test which asserted on the wrong behaviour. This PR fixes skipping PF WriteOnly attributes during tfgen. It also simplifies the PF code by removing a redundant interface. `AttrLike` is a copy of the PF `fwschema..Attribute` which has `WriteOnly` implemented. This makes the method non-optional and adding it to an internal interface is not a breaking change.
1 parent 4abc06e commit 9284425

File tree

4 files changed

+3
-25
lines changed

4 files changed

+3
-25
lines changed

pkg/pf/internal/pfutils/attr.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ type AttrLike interface {
4545
IsOptional() bool
4646
IsRequired() bool
4747
IsSensitive() bool
48+
IsWriteOnly() bool
4849
GetDeprecationMessage() string
4950
GetDescription() string
5051
GetMarkdownDescription() string
5152
GetType() attr.Type
5253
}
5354

54-
type AttrLikeWithWriteOnly interface {
55-
AttrLike
56-
IsWriteOnly() bool
57-
}
58-
5955
func FromProviderAttribute(x pschema.Attribute) Attr {
6056
return FromAttrLike(x)
6157
}

pkg/pf/internal/schemashim/attr_schema.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ func (s *attrSchema) Sensitive() bool {
142142
}
143143

144144
func (s *attrSchema) WriteOnly() bool {
145-
schema, ok := s.attr.(pfutils.AttrLikeWithWriteOnly)
146-
if ok {
147-
return schema.IsWriteOnly()
148-
}
149-
return false
145+
return s.attr.IsWriteOnly()
150146
}
151147

152148
func (*attrSchema) SetElement(config interface{}) (interface{}, error) {

pkg/pf/internal/schemashim/object_pseudoresource.go

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (tupElementAttr) IsOptional() bool { return false }
180180
func (tupElementAttr) IsRequired() bool { return true }
181181
func (tupElementAttr) IsSensitive() bool { return false }
182182
func (tupElementAttr) IsComputed() bool { return false }
183+
func (tupElementAttr) IsWriteOnly() bool { return false }
183184

184185
func (t tupElementAttr) GetType() attr.Type { return t.e }
185186

pkg/pf/tfgen/testdata/TestWriteOnlyOmit.golden

-15
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,8 @@
1212
},
1313
"resources": {
1414
"testprovider:index:Res": {
15-
"properties": {
16-
"a1": {
17-
"type": "string"
18-
}
19-
},
20-
"inputProperties": {
21-
"a1": {
22-
"type": "string"
23-
}
24-
},
2515
"stateInputs": {
2616
"description": "Input properties used for looking up and filtering Res resources.\n",
27-
"properties": {
28-
"a1": {
29-
"type": "string"
30-
}
31-
},
3217
"type": "object"
3318
}
3419
}

0 commit comments

Comments
 (0)