Skip to content

Commit

Permalink
Merge branch 'main' into plan_summary_for_plan_file
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Dec 25, 2024
2 parents e7c642a + 337bf8e commit ca3cb1e
Show file tree
Hide file tree
Showing 13 changed files with 1,312 additions and 1,220 deletions.
1 change: 1 addition & 0 deletions docs/plugin-protocol/tfplugin5.8.proto
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ message ValidateResourceTypeConfig {
message Request {
string type_name = 1;
DynamicValue config = 2;
ClientCapabilities client_capabilities = 3;
}
message Response {
repeated Diagnostic diagnostics = 1;
Expand Down
1 change: 1 addition & 0 deletions docs/plugin-protocol/tfplugin6.8.proto
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ message ValidateResourceConfig {
message Request {
string type_name = 1;
DynamicValue config = 2;
ClientCapabilities client_capabilities = 3;
}
message Response {
repeated Diagnostic diagnostics = 1;
Expand Down
3 changes: 3 additions & 0 deletions internal/grpcwrap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (p *provider) ValidateResourceTypeConfig(_ context.Context, req *tfplugin5.
validateResp := p.provider.ValidateResourceConfig(providers.ValidateResourceConfigRequest{
TypeName: req.TypeName,
Config: configVal,
ClientCapabilities: providers.ClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
})

resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, validateResp.Diagnostics)
Expand Down
56 changes: 26 additions & 30 deletions internal/plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ func (p *GRPCProvider) ValidateResourceConfig(r providers.ValidateResourceConfig
}

protoReq := &proto.ValidateResourceTypeConfig_Request{
TypeName: r.TypeName,
Config: &proto.DynamicValue{Msgpack: mp},
TypeName: r.TypeName,
Config: &proto.DynamicValue{Msgpack: mp},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.ValidateResourceTypeConfig(p.ctx, protoReq)
Expand Down Expand Up @@ -355,9 +356,7 @@ func (p *GRPCProvider) ConfigureProvider(r providers.ConfigureProviderRequest) (
Config: &proto.DynamicValue{
Msgpack: mp,
},
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.Configure(p.ctx, protoReq)
Expand Down Expand Up @@ -407,12 +406,10 @@ func (p *GRPCProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
}

protoReq := &proto.ReadResource_Request{
TypeName: r.TypeName,
CurrentState: &proto.DynamicValue{Msgpack: mp},
Private: r.Private,
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
CurrentState: &proto.DynamicValue{Msgpack: mp},
Private: r.Private,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -488,14 +485,12 @@ func (p *GRPCProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
}

protoReq := &proto.PlanResourceChange_Request{
TypeName: r.TypeName,
PriorState: &proto.DynamicValue{Msgpack: priorMP},
Config: &proto.DynamicValue{Msgpack: configMP},
ProposedNewState: &proto.DynamicValue{Msgpack: propMP},
PriorPrivate: r.PriorPrivate,
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
PriorState: &proto.DynamicValue{Msgpack: priorMP},
Config: &proto.DynamicValue{Msgpack: configMP},
ProposedNewState: &proto.DynamicValue{Msgpack: propMP},
PriorPrivate: r.PriorPrivate,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -625,11 +620,9 @@ func (p *GRPCProvider) ImportResourceState(r providers.ImportResourceStateReques
}

protoReq := &proto.ImportResourceState_Request{
TypeName: r.TypeName,
Id: r.ID,
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
Id: r.ID,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.ImportResourceState(p.ctx, protoReq)
Expand Down Expand Up @@ -740,9 +733,7 @@ func (p *GRPCProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
Config: &proto.DynamicValue{
Msgpack: config,
},
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -833,9 +824,7 @@ func (p *GRPCProvider) OpenEphemeralResource(r providers.OpenEphemeralResourceRe
Config: &proto.DynamicValue{
Msgpack: config,
},
ClientCapabilities: &proto.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.OpenEphemeralResource(p.ctx, protoReq)
Expand Down Expand Up @@ -1026,3 +1015,10 @@ func decodeDynamicValue(v *proto.DynamicValue, ty cty.Type) (cty.Value, error) {
}
return res, err
}

func clientCapabilitiesToProto(c providers.ClientCapabilities) *proto.ClientCapabilities {
return &proto.ClientCapabilities{
DeferralAllowed: c.DeferralAllowed,
WriteOnlyAttributesAllowed: c.WriteOnlyAttributesAllowed,
}
}
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
57 changes: 26 additions & 31 deletions internal/plugin6/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ func (p *GRPCProvider) ValidateResourceConfig(r providers.ValidateResourceConfig
}

protoReq := &proto6.ValidateResourceConfig_Request{
TypeName: r.TypeName,
Config: &proto6.DynamicValue{Msgpack: mp},
TypeName: r.TypeName,
Config: &proto6.DynamicValue{Msgpack: mp},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.ValidateResourceConfig(p.ctx, protoReq)
Expand Down Expand Up @@ -344,10 +345,7 @@ func (p *GRPCProvider) ConfigureProvider(r providers.ConfigureProviderRequest) (
Config: &proto6.DynamicValue{
Msgpack: mp,
},
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
WriteOnlyAttributesAllowed: r.ClientCapabilities.WriteOnlyAttributesAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.ConfigureProvider(p.ctx, protoReq)
Expand Down Expand Up @@ -397,12 +395,10 @@ func (p *GRPCProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
}

protoReq := &proto6.ReadResource_Request{
TypeName: r.TypeName,
CurrentState: &proto6.DynamicValue{Msgpack: mp},
Private: r.Private,
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
CurrentState: &proto6.DynamicValue{Msgpack: mp},
Private: r.Private,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -478,14 +474,12 @@ func (p *GRPCProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
}

protoReq := &proto6.PlanResourceChange_Request{
TypeName: r.TypeName,
PriorState: &proto6.DynamicValue{Msgpack: priorMP},
Config: &proto6.DynamicValue{Msgpack: configMP},
ProposedNewState: &proto6.DynamicValue{Msgpack: propMP},
PriorPrivate: r.PriorPrivate,
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
PriorState: &proto6.DynamicValue{Msgpack: priorMP},
Config: &proto6.DynamicValue{Msgpack: configMP},
ProposedNewState: &proto6.DynamicValue{Msgpack: propMP},
PriorPrivate: r.PriorPrivate,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -615,11 +609,9 @@ func (p *GRPCProvider) ImportResourceState(r providers.ImportResourceStateReques
}

protoReq := &proto6.ImportResourceState_Request{
TypeName: r.TypeName,
Id: r.ID,
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
TypeName: r.TypeName,
Id: r.ID,
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.ImportResourceState(p.ctx, protoReq)
Expand Down Expand Up @@ -730,9 +722,7 @@ func (p *GRPCProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
Config: &proto6.DynamicValue{
Msgpack: config,
},
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

if metaSchema.Block != nil {
Expand Down Expand Up @@ -823,9 +813,7 @@ func (p *GRPCProvider) OpenEphemeralResource(r providers.OpenEphemeralResourceRe
Config: &proto6.DynamicValue{
Msgpack: config,
},
ClientCapabilities: &proto6.ClientCapabilities{
DeferralAllowed: r.ClientCapabilities.DeferralAllowed,
},
ClientCapabilities: clientCapabilitiesToProto(r.ClientCapabilities),
}

protoResp, err := p.client.OpenEphemeralResource(p.ctx, protoReq)
Expand Down Expand Up @@ -1016,3 +1004,10 @@ func decodeDynamicValue(v *proto6.DynamicValue, ty cty.Type) (cty.Value, error)
}
return res, err
}

func clientCapabilitiesToProto(c providers.ClientCapabilities) *proto6.ClientCapabilities {
return &proto6.ClientCapabilities{
DeferralAllowed: c.DeferralAllowed,
WriteOnlyAttributesAllowed: c.WriteOnlyAttributesAllowed,
}
}
3 changes: 3 additions & 0 deletions internal/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ type ValidateResourceConfigRequest struct {
// Config is the configuration value to validate, which may contain unknown
// values.
Config cty.Value

// ClientCapabilities contains information about the client's capabilities.
ClientCapabilities ClientCapabilities
}

type ValidateResourceConfigResponse struct {
Expand Down
3 changes: 3 additions & 0 deletions internal/terraform/node_resource_abstract_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ func (n *NodeAbstractResourceInstance) plan(
providers.ValidateResourceConfigRequest{
TypeName: n.Addr.Resource.Resource.Type,
Config: unmarkedConfigVal,
ClientCapabilities: providers.ClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
},
)
diags = diags.Append(validateResp.Diagnostics.InConfigBody(config.Config, n.Addr.String()))
Expand Down
Loading

0 comments on commit ca3cb1e

Please sign in to comment.