Skip to content

Commit

Permalink
Merge pull request #36236 from hashicorp/jbardin/write-only-structura…
Browse files Browse the repository at this point in the history
…l-attrs

convert write-only structural attrs to and from protobuf
  • Loading branch information
jbardin authored Dec 18, 2024
2 parents e391c68 + 345a931 commit 337bf8e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/plugin6/convert/diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion internal/plugin6/convert/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions internal/plugin6/convert/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"`),
Expand All @@ -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{
Expand All @@ -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,
Expand All @@ -447,6 +499,11 @@ func TestConvertProtoSchemaBlocks(t *testing.T) {
Type: cty.Number,
Required: true,
},
"write_only": {
Type: cty.String,
Optional: true,
WriteOnly: true,
},
},
},
},
Expand Down

0 comments on commit 337bf8e

Please sign in to comment.