Merge pull request #36236 from hashicorp/jbardin/write-only-structural-attrs

convert write-only structural attrs to and from protobuf
pull/36230/head^2
James Bardin 1 year ago committed by GitHub
commit 337bf8e11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -19,6 +19,7 @@ var ignoreUnexported = cmpopts.IgnoreUnexported(
proto.Schema_Block{},
proto.Schema_NestedBlock{},
proto.Schema_Attribute{},
proto.Schema_Object{},
)
func TestProtoDiagnostics(t *testing.T) {

@ -215,6 +215,7 @@ func protoObjectToConfigSchema(b *proto.Schema_Object) *configschema.Object {
Computed: a.Computed,
Sensitive: a.Sensitive,
Deprecated: a.Deprecated,
WriteOnly: a.WriteOnly,
}
if a.Type != nil {
@ -268,7 +269,6 @@ func configschemaObjectToProto(b *configschema.Object) *proto.Schema_Object {
for _, name := range sortedKeys(b.Attributes) {
a := b.Attributes[name]
attr := &proto.Schema_Attribute{
Name: name,
Description: a.Description,
@ -278,6 +278,7 @@ func configschemaObjectToProto(b *configschema.Object) *proto.Schema_Object {
Required: a.Required,
Sensitive: a.Sensitive,
Deprecated: a.Deprecated,
WriteOnly: a.WriteOnly,
}
if a.Type != cty.NilType {

@ -110,6 +110,12 @@ func TestConvertSchemaBlocks(t *testing.T) {
Type: []byte(`"number"`),
Required: true,
},
{
Name: "write_only",
Type: []byte(`"string"`),
Optional: true,
WriteOnly: true,
},
},
},
Computed: true,
@ -230,6 +236,11 @@ func TestConvertSchemaBlocks(t *testing.T) {
Type: cty.Number,
Required: true,
},
"write_only": {
Type: cty.String,
Optional: true,
WriteOnly: true,
},
},
},
Computed: true,
@ -410,6 +421,25 @@ func TestConvertProtoSchemaBlocks(t *testing.T) {
Type: []byte(`["list","bool"]`),
Computed: true,
},
{
Name: "object",
NestedType: &proto.Schema_Object{
Nesting: proto.Schema_Object_SINGLE,
Attributes: []*proto.Schema_Attribute{
{
Name: "optional",
Type: []byte(`"string"`),
Optional: true,
},
{
Name: "write_only",
Type: []byte(`"string"`),
Optional: true,
WriteOnly: true,
},
},
},
},
{
Name: "optional",
Type: []byte(`"string"`),
@ -426,6 +456,12 @@ func TestConvertProtoSchemaBlocks(t *testing.T) {
Type: []byte(`"number"`),
Required: true,
},
{
Name: "write_only",
Type: []byte(`"string"`),
Optional: true,
WriteOnly: true,
},
},
},
&configschema.Block{
@ -434,6 +470,22 @@ func TestConvertProtoSchemaBlocks(t *testing.T) {
Type: cty.List(cty.Bool),
Computed: true,
},
"object": {
NestedType: &configschema.Object{
Nesting: configschema.NestingSingle,
Attributes: map[string]*configschema.Attribute{
"optional": {
Type: cty.String,
Optional: true,
},
"write_only": {
Type: cty.String,
Optional: true,
WriteOnly: true,
},
},
},
},
"optional": {
Type: cty.String,
Optional: true,
@ -447,6 +499,11 @@ func TestConvertProtoSchemaBlocks(t *testing.T) {
Type: cty.Number,
Required: true,
},
"write_only": {
Type: cty.String,
Optional: true,
WriteOnly: true,
},
},
},
},

Loading…
Cancel
Save