diff --git a/action/action.go b/action/action.go index e060c6a11..ab7b1f1a2 100644 --- a/action/action.go +++ b/action/action.go @@ -12,9 +12,8 @@ type Action interface { // Metadata should return the full name of the action, such as examplecloud_do_thing. Metadata(context.Context, MetadataRequest, *MetadataResponse) - // Invoke is called to run the logic of the action and update linked resources if applicable. - // Config, linked resource planned state, and linked resource prior state values should - // be read from the InvokeRequest and new linked resource state values set on the InvokeResponse. + // Invoke is called to run the logic of the action. Config values should be read from the InvokeRequest + // and potential diagnostics set in InvokeResponse. // // The [InvokeResponse.SendProgress] function can be called in the Invoke method to immediately // report progress events related to the invocation of the action to Terraform. diff --git a/action/invoke.go b/action/invoke.go index 14ddfe126..2cf18402e 100644 --- a/action/invoke.go +++ b/action/invoke.go @@ -8,13 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -// InvokeRequest represents a request for the provider to invoke the action and update -// the requested action's linked resources. +// InvokeRequest represents a request for the provider to invoke the action. type InvokeRequest struct { // Config is the configuration the user supplied for the action. Config tfsdk.Config - - // TODO:Actions: Add linked resources when new action schema types are introduced } // InvokeResponse represents a response to an InvokeRequest. An @@ -22,17 +19,14 @@ type InvokeRequest struct { // an argument to the action's Invoke function, in which the provider // should set values on the InvokeResponse as appropriate. type InvokeResponse struct { - // Diagnostics report errors or warnings related to invoking the action or updating - // the state of the requested action's linked resources. Returning an empty slice + // Diagnostics report errors or warnings related to invoking the action. Returning an empty slice // indicates a successful invocation with no warnings or errors // generated. Diagnostics diag.Diagnostics // SendProgress will immediately send a progress update to Terraform core during action invocation. - // This function is pre-populated by the framework and can be called multiple times while action logic is running. + // This function is provided by the framework and can be called multiple times while action logic is running. SendProgress func(event InvokeProgressEvent) - - // TODO:Actions: Add linked resources when new action schema types are introduced } // InvokeProgressEvent is the event returned to Terraform while an action is being invoked. diff --git a/action/modify_plan.go b/action/modify_plan.go index 86d4f7200..daeed0fa7 100644 --- a/action/modify_plan.go +++ b/action/modify_plan.go @@ -20,8 +20,9 @@ type ModifyPlanClientCapabilities struct { DeferralAllowed bool } -// ModifyPlanRequest represents a request for the provider to modify the -// planned new state that Terraform has generated for any linked resources. +// ModifyPlanRequest represents a request for the provider during planning. +// The plan can be used as an opportunity to raise early +// diagnostics to practitioners, such as validation errors. type ModifyPlanRequest struct { // Config is the configuration the user supplied for the action. // @@ -30,8 +31,6 @@ type ModifyPlanRequest struct { // from knowing the value at request time. Config tfsdk.Config - // TODO:Actions: Add linked resources when new action schema types are introduced - // ClientCapabilities defines optionally supported protocol features for the // PlanAction RPC, such as forward-compatible Terraform behavior changes. ClientCapabilities ModifyPlanClientCapabilities @@ -39,17 +38,13 @@ type ModifyPlanRequest struct { // ModifyPlanResponse represents a response to a // ModifyPlanRequest. An instance of this response struct is supplied -// as an argument to the action's ModifyPlan function, in which the provider -// should modify the Plan of any linked resources as appropriate. +// as an argument to the action's ModifyPlan function. type ModifyPlanResponse struct { - // Diagnostics report errors or warnings related to determining the - // planned state of the requested action's linked resources. Returning an empty slice - // indicates a successful plan modification with no warnings or errors - // generated. + // Diagnostics report early errors or warnings related action. + // Returning an empty slice indicates a successful plan modification + // with no warnings or errors generated. Diagnostics diag.Diagnostics - // TODO:Actions: Add linked resources when new action schema types are introduced - // Deferred indicates that Terraform should defer planning this // action until a follow-up apply operation. // diff --git a/action/schema.go b/action/schema.go index b6ba937d7..001bf7edb 100644 --- a/action/schema.go +++ b/action/schema.go @@ -19,11 +19,7 @@ type SchemaRequest struct{} type SchemaResponse struct { // Schema is the schema of the action. - // - // There is currently only one type of action, which defines how a practitioner can trigger an action, - // as well as what effect the action can have on the state. - // - [schema.UnlinkedSchema] actions are actions that cannot cause changes to resource states. - Schema schema.SchemaType + Schema schema.Schema // Diagnostics report errors or warnings related to retrieving the action schema. // An empty slice indicates success, with no warnings or errors generated. diff --git a/action/schema/doc.go b/action/schema/doc.go index 8fc552bec..7dbfc4954 100644 --- a/action/schema/doc.go +++ b/action/schema/doc.go @@ -4,8 +4,4 @@ // Package schema contains all available schema functionality for actions. // Action schemas define the structure and value types for configuration data. // Schemas are implemented via the action.Action type Schema method. -// -// There is currently one type of action schema, which defines how a practitioner can trigger an action, -// as well as what effect the action can have on the state. -// - [UnlinkedSchema] actions are actions that cannot cause changes to resource states. package schema diff --git a/action/schema/unlinked_schema.go b/action/schema/schema.go similarity index 80% rename from action/schema/unlinked_schema.go rename to action/schema/schema.go index 71af1a4f1..c07b03b5d 100644 --- a/action/schema/unlinked_schema.go +++ b/action/schema/schema.go @@ -6,18 +6,19 @@ package schema import ( "context" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) -var _ SchemaType = UnlinkedSchema{} +var _ fwschema.Schema = Schema{} -// UnlinkedSchema defines the structure and value types of an unlinked action. An unlinked action +// Schema defines the structure and value types of an action. An action currently // cannot cause changes to resource state. -type UnlinkedSchema struct { +type Schema struct { // Attributes is the mapping of underlying attribute names to attribute // definitions. // @@ -58,70 +59,68 @@ type UnlinkedSchema struct { DeprecationMessage string } -func (s UnlinkedSchema) isActionSchemaType() {} - // ApplyTerraform5AttributePathStep applies the given AttributePathStep to the // schema. -func (s UnlinkedSchema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (any, error) { +func (s Schema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (any, error) { return fwschema.SchemaApplyTerraform5AttributePathStep(s, step) } // AttributeAtPath returns the Attribute at the passed path. If the path points // to an element or attribute of a complex type, rather than to an Attribute, // it will return an ErrPathInsideAtomicAttribute error. -func (s UnlinkedSchema) AttributeAtPath(ctx context.Context, p path.Path) (fwschema.Attribute, diag.Diagnostics) { +func (s Schema) AttributeAtPath(ctx context.Context, p path.Path) (fwschema.Attribute, diag.Diagnostics) { return fwschema.SchemaAttributeAtPath(ctx, s, p) } // AttributeAtPath returns the Attribute at the passed path. If the path points // to an element or attribute of a complex type, rather than to an Attribute, // it will return an ErrPathInsideAtomicAttribute error. -func (s UnlinkedSchema) AttributeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (fwschema.Attribute, error) { +func (s Schema) AttributeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (fwschema.Attribute, error) { return fwschema.SchemaAttributeAtTerraformPath(ctx, s, p) } // GetAttributes returns the Attributes field value. -func (s UnlinkedSchema) GetAttributes() map[string]fwschema.Attribute { +func (s Schema) GetAttributes() map[string]fwschema.Attribute { return schemaAttributes(s.Attributes) } // GetBlocks returns the Blocks field value. -func (s UnlinkedSchema) GetBlocks() map[string]fwschema.Block { +func (s Schema) GetBlocks() map[string]fwschema.Block { return schemaBlocks(s.Blocks) } // GetDeprecationMessage returns the DeprecationMessage field value. -func (s UnlinkedSchema) GetDeprecationMessage() string { +func (s Schema) GetDeprecationMessage() string { return s.DeprecationMessage } // GetDescription returns the Description field value. -func (s UnlinkedSchema) GetDescription() string { +func (s Schema) GetDescription() string { return s.Description } // GetMarkdownDescription returns the MarkdownDescription field value. -func (s UnlinkedSchema) GetMarkdownDescription() string { +func (s Schema) GetMarkdownDescription() string { return s.MarkdownDescription } // GetVersion always returns 0 as action schemas cannot be versioned. -func (s UnlinkedSchema) GetVersion() int64 { +func (s Schema) GetVersion() int64 { return 0 } // Type returns the framework type of the schema. -func (s UnlinkedSchema) Type() attr.Type { +func (s Schema) Type() attr.Type { return fwschema.SchemaType(s) } // TypeAtPath returns the framework type at the given schema path. -func (s UnlinkedSchema) TypeAtPath(ctx context.Context, p path.Path) (attr.Type, diag.Diagnostics) { +func (s Schema) TypeAtPath(ctx context.Context, p path.Path) (attr.Type, diag.Diagnostics) { return fwschema.SchemaTypeAtPath(ctx, s, p) } // TypeAtTerraformPath returns the framework type at the given tftypes path. -func (s UnlinkedSchema) TypeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (attr.Type, error) { +func (s Schema) TypeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (attr.Type, error) { return fwschema.SchemaTypeAtTerraformPath(ctx, s, p) } @@ -129,7 +128,7 @@ func (s UnlinkedSchema) TypeAtTerraformPath(ctx context.Context, p *tftypes.Attr // implementation of the schema and underlying attributes and blocks to prevent // unexpected errors or panics. This logic runs during the GetProviderSchema RPC, // or via provider-defined unit testing, and should never include false positives. -func (s UnlinkedSchema) ValidateImplementation(ctx context.Context) diag.Diagnostics { +func (s Schema) ValidateImplementation(ctx context.Context) diag.Diagnostics { var diags diag.Diagnostics for attributeName, attribute := range s.GetAttributes() { diff --git a/action/schema/unlinked_schema_test.go b/action/schema/schema_test.go similarity index 91% rename from action/schema/unlinked_schema_test.go rename to action/schema/schema_test.go index 881e1d6a3..8c15e3ae2 100644 --- a/action/schema/unlinked_schema_test.go +++ b/action/schema/schema_test.go @@ -24,13 +24,13 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema step tftypes.AttributePathStep expected any expectedError error }{ "AttributeName-attribute": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -40,7 +40,7 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { expectedError: nil, }, "AttributeName-block": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "testblock": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -58,7 +58,7 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { expectedError: nil, }, "AttributeName-missing": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -68,7 +68,7 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { expectedError: fmt.Errorf("could not find attribute or block \"other\" in schema"), }, "ElementKeyInt": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -78,7 +78,7 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { expectedError: fmt.Errorf("cannot apply AttributePathStep tftypes.ElementKeyInt to schema"), }, "ElementKeyString": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -88,7 +88,7 @@ func TestSchemaApplyTerraform5AttributePathStep(t *testing.T) { expectedError: fmt.Errorf("cannot apply AttributePathStep tftypes.ElementKeyString to schema"), }, "ElementKeyValue": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -130,13 +130,13 @@ func TestSchemaAttributeAtPath(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema path path.Path expected fwschema.Attribute expectedDiags diag.Diagnostics }{ "empty-root": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Empty(), expected: nil, expectedDiags: diag.Diagnostics{ @@ -146,12 +146,12 @@ func TestSchemaAttributeAtPath(t *testing.T) { "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: \n"+ - "Original Error: got unexpected type schema.UnlinkedSchema", + "Original Error: got unexpected type schema.Schema", ), }, }, "root": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -165,12 +165,12 @@ func TestSchemaAttributeAtPath(t *testing.T) { "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: \n"+ - "Original Error: got unexpected type schema.UnlinkedSchema", + "Original Error: got unexpected type schema.Schema", ), }, }, "WithAttributeName-attribute": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "other": schema.BoolAttribute{}, "test": schema.StringAttribute{}, @@ -180,7 +180,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { expected: schema.StringAttribute{}, }, "WithAttributeName-block": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "other": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -208,7 +208,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, "WithElementKeyInt": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -227,7 +227,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, "WithElementKeyString": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -246,7 +246,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, "WithElementKeyValue": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -288,45 +288,45 @@ func TestSchemaAttributeAtTerraformPath(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema path *tftypes.AttributePath expected fwschema.Attribute expectedErr string }{ "empty-root": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath(), expected: nil, - expectedErr: "got unexpected type schema.UnlinkedSchema", + expectedErr: "got unexpected type schema.Schema", }, "empty-nil": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: nil, expected: nil, - expectedErr: "got unexpected type schema.UnlinkedSchema", + expectedErr: "got unexpected type schema.Schema", }, "root": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, }, path: tftypes.NewAttributePath(), expected: nil, - expectedErr: "got unexpected type schema.UnlinkedSchema", + expectedErr: "got unexpected type schema.Schema", }, "nil": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, }, path: nil, expected: nil, - expectedErr: "got unexpected type schema.UnlinkedSchema", + expectedErr: "got unexpected type schema.Schema", }, "WithAttributeName-attribute": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "other": schema.BoolAttribute{}, "test": schema.StringAttribute{}, @@ -336,7 +336,7 @@ func TestSchemaAttributeAtTerraformPath(t *testing.T) { expected: schema.StringAttribute{}, }, "WithAttributeName-block": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "other": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -355,7 +355,7 @@ func TestSchemaAttributeAtTerraformPath(t *testing.T) { expectedErr: fwschema.ErrPathIsBlock.Error(), }, "WithElementKeyInt": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -365,7 +365,7 @@ func TestSchemaAttributeAtTerraformPath(t *testing.T) { expectedErr: "ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to schema", }, "WithElementKeyString": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -375,7 +375,7 @@ func TestSchemaAttributeAtTerraformPath(t *testing.T) { expectedErr: "ElementKeyString(\"test\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to schema", }, "WithElementKeyValue": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{}, }, @@ -422,15 +422,15 @@ func TestSchemaGetAttributes(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected map[string]fwschema.Attribute }{ "no-attributes": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, expected: map[string]fwschema.Attribute{}, }, "attributes": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr1": schema.StringAttribute{}, "testattr2": schema.StringAttribute{}, @@ -460,15 +460,15 @@ func TestSchemaGetBlocks(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected map[string]fwschema.Block }{ "no-blocks": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, expected: map[string]fwschema.Block{}, }, "blocks": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "testblock1": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -514,11 +514,11 @@ func TestSchemaGetDeprecationMessage(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected string }{ "no-deprecation-message": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -526,7 +526,7 @@ func TestSchemaGetDeprecationMessage(t *testing.T) { expected: "", }, "deprecation-message": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ DeprecationMessage: "test deprecation message", }, expected: "test deprecation message", @@ -550,11 +550,11 @@ func TestSchemaGetDescription(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected string }{ "no-description": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -562,7 +562,7 @@ func TestSchemaGetDescription(t *testing.T) { expected: "", }, "description": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Description: "test description", }, expected: "test description", @@ -586,11 +586,11 @@ func TestSchemaGetMarkdownDescription(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected string }{ "no-markdown-description": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -598,7 +598,7 @@ func TestSchemaGetMarkdownDescription(t *testing.T) { expected: "", }, "markdown-description": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ MarkdownDescription: "test description", }, expected: "test description", @@ -622,11 +622,11 @@ func TestSchemaGetVersion(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected int64 }{ "no-version": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -652,11 +652,11 @@ func TestSchemaType(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expected attr.Type }{ "base": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "testattr": schema.StringAttribute{}, }, @@ -698,18 +698,18 @@ func TestSchemaTypeAtPath(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema path path.Path expected attr.Type expectedDiags diag.Diagnostics }{ "empty-schema-empty-path": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Empty(), expected: types.ObjectType{}, }, "empty-path": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "bool": schema.BoolAttribute{}, "string": schema.StringAttribute{}, @@ -724,7 +724,7 @@ func TestSchemaTypeAtPath(t *testing.T) { }, }, "AttributeName-Attribute": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "bool": schema.BoolAttribute{}, "string": schema.StringAttribute{}, @@ -734,7 +734,7 @@ func TestSchemaTypeAtPath(t *testing.T) { expected: types.StringType, }, "AttributeName-Block": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_block": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -751,7 +751,7 @@ func TestSchemaTypeAtPath(t *testing.T) { }, }, "AttributeName-non-existent": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Root("non-existent"), expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( @@ -764,7 +764,7 @@ func TestSchemaTypeAtPath(t *testing.T) { }, }, "ElementKeyInt": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Empty().AtListIndex(0), expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( @@ -777,7 +777,7 @@ func TestSchemaTypeAtPath(t *testing.T) { }, }, "ElementKeyString": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Empty().AtMapKey("invalid"), expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( @@ -790,7 +790,7 @@ func TestSchemaTypeAtPath(t *testing.T) { }, }, "ElementKeyValue": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: path.Empty().AtSetValue(types.StringNull()), expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( @@ -825,23 +825,23 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema path *tftypes.AttributePath expected attr.Type expectedError error }{ "empty-schema-nil-path": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: nil, expected: types.ObjectType{}, }, "empty-schema-empty-path": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath(), expected: types.ObjectType{}, }, "nil-path": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "bool": schema.BoolAttribute{}, "string": schema.StringAttribute{}, @@ -856,7 +856,7 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) { }, }, "empty-path": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "bool": schema.BoolAttribute{}, "string": schema.StringAttribute{}, @@ -871,7 +871,7 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) { }, }, "AttributeName-Attribute": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "bool": schema.BoolAttribute{}, "string": schema.StringAttribute{}, @@ -881,7 +881,7 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) { expected: types.StringType, }, "AttributeName-Block": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_block": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -898,22 +898,22 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) { }, }, "AttributeName-non-existent": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath().WithAttributeName("non-existent"), expectedError: fmt.Errorf("AttributeName(\"non-existent\") still remains in the path: could not find attribute or block \"non-existent\" in schema"), }, "ElementKeyInt": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath().WithElementKeyInt(0), expectedError: fmt.Errorf("ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to schema"), }, "ElementKeyString": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath().WithElementKeyString("invalid"), expectedError: fmt.Errorf("ElementKeyString(\"invalid\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to schema"), }, "ElementKeyValue": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, path: tftypes.NewAttributePath().WithElementKeyValue(tftypes.NewValue(tftypes.String, nil)), expectedError: fmt.Errorf("ElementKeyValue(tftypes.String) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to schema"), }, @@ -950,14 +950,14 @@ func TestSchemaValidateImplementation(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema schema.UnlinkedSchema + schema schema.Schema expectedDiags diag.Diagnostics }{ "empty-schema": { - schema: schema.UnlinkedSchema{}, + schema: schema.Schema{}, }, "attribute-using-reserved-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "depends_on": schema.StringAttribute{}, }, @@ -973,7 +973,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "block-using-reserved-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "connection": schema.SingleNestedBlock{}, }, @@ -989,7 +989,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-attribute-using-nested-reserved-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "single_nested_attribute": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ @@ -1000,7 +1000,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-block-using-nested-reserved-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_nested_block": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -1011,7 +1011,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "attribute-and-blocks-using-reserved-field-names": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "depends_on": schema.StringAttribute{}, }, @@ -1037,7 +1037,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "attribute-using-invalid-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "^": schema.StringAttribute{}, }, @@ -1053,7 +1053,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "block-using-invalid-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "^": schema.SingleNestedBlock{}, }, @@ -1069,7 +1069,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-attribute-using-nested-invalid-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "single_nested_attribute": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ @@ -1089,7 +1089,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-block-using-nested-invalid-field-name": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_nested_block": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -1109,7 +1109,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-block-with-nested-block-using-invalid-field-names": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "$": schema.SingleNestedBlock{ Blocks: map[string]schema.Block{ @@ -1147,7 +1147,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "attribute-with-validate-attribute-implementation-error": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.ListAttribute{ Required: true, @@ -1165,7 +1165,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-attribute-with-validate-attribute-implementation-error": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Attributes: map[string]schema.Attribute{ "single_nested_attribute": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ @@ -1187,7 +1187,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-block-attribute-with-validate-attribute-implementation-error": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_nested_block": schema.SingleNestedBlock{ Attributes: map[string]schema.Attribute{ @@ -1209,7 +1209,7 @@ func TestSchemaValidateImplementation(t *testing.T) { }, }, "nested-nested-block-attribute-with-validate-attribute-implementation-error": { - schema: schema.UnlinkedSchema{ + schema: schema.Schema{ Blocks: map[string]schema.Block{ "single_nested_block": schema.SingleNestedBlock{ Blocks: map[string]schema.Block{ diff --git a/action/schema/schema_type.go b/action/schema/schema_type.go deleted file mode 100644 index 93bc8ddb5..000000000 --- a/action/schema/schema_type.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package schema - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" -) - -// SchemaType is the interface that an action schema type must implement. Action -// schema types are statically definined in the protocol, so all implementations -// are defined in this package. -// -// SchemaType implementations define how a practitioner can trigger an action, as well -// as what effect the action can have on the state. There is currently only one type of action: -// - [UnlinkedSchema] actions are actions that cannot cause changes to resource states. -type SchemaType interface { - fwschema.Schema - - // MAINTAINER NOTE: Action schemas are unique to other schema types in framework in that the - // exported methods all return a schema interface ([SchemaType]) rather than a schema struct, - // due to the multiple different types of action schema implementations. - // - // As a result, there are certain methods that all schema structs implement that aren't defined in - // the [fwschema.Schema] interface, such as the ValidateImplementation method. So we are adding that - // here to the action schema interface to avoid additional internal interfaces and unnecessary - // type assertions. - ValidateImplementation(context.Context) diag.Diagnostics - - // Action schema types are statically defined in the protocol, so this - // interface is not meant to be implemented outside of this package - isActionSchemaType() -} diff --git a/go.mod b/go.mod index 71c5bcd78..9bf4fd3ff 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.24.4 require ( github.com/google/go-cmp v0.7.0 - github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250904144425-4c19f069077d + github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250915194700-c3810b1245c0 github.com/hashicorp/terraform-plugin-log v0.9.0 ) @@ -14,7 +14,7 @@ require ( github.com/fatih/color v1.15.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect - github.com/hashicorp/go-plugin v1.6.3 // indirect + github.com/hashicorp/go-plugin v1.7.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/terraform-registry-address v0.4.0 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect @@ -23,13 +23,12 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/oklog/run v1.1.0 // indirect - github.com/stretchr/testify v1.10.0 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect golang.org/x/net v0.43.0 // indirect golang.org/x/sys v0.35.0 // indirect golang.org/x/text v0.28.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect - google.golang.org/grpc v1.75.0 // indirect - google.golang.org/protobuf v1.36.8 // indirect + google.golang.org/grpc v1.75.1 // indirect + google.golang.org/protobuf v1.36.9 // indirect ) diff --git a/go.sum b/go.sum index 03e435852..a82e671c1 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,9 @@ -github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= -github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= +github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= @@ -18,12 +19,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= -github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= +github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshfk+mA= +github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250904144425-4c19f069077d h1:sr9OmOzsMvVLJNS03rXBaKlnN04dIbv3GIysvb29lEA= -github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250904144425-4c19f069077d/go.mod h1:ALzufgzXQhdmGGUgpYRwUtBdMluh8cYn8vNnmQXxo5s= +github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250915194700-c3810b1245c0 h1:4dh8RXeFIH1v4mOgv70OvrbZWC5vDEWiEXIRFIA63S0= +github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1.0.20250915194700-c3810b1245c0/go.mod h1:vYZbIyvxyy0FWSmDHChCqKvI40cFTDGSb3D8D70i9GM= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/hashicorp/terraform-registry-address v0.4.0 h1:S1yCGomj30Sao4l5BMPjTGZmCNzuv7/GDTDX99E9gTk= @@ -32,8 +33,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= -github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= -github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94= +github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -47,8 +48,9 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= @@ -86,10 +88,10 @@ gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 h1:pFyd6EwwL2TqFf8emdthzeX+gZE1ElRq3iM8pui4KBY= google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= -google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4= -google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= -google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= -google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= +google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI= +google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= +google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= +google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/fromproto5/invokeaction.go b/internal/fromproto5/invokeaction.go index cfbf8b260..4672fc220 100644 --- a/internal/fromproto5/invokeaction.go +++ b/internal/fromproto5/invokeaction.go @@ -47,7 +47,5 @@ func InvokeActionRequest(ctx context.Context, proto5 *tfprotov5.InvokeActionRequ fw.Config = config - // TODO:Actions: Add linked resources when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto5/invokeaction_test.go b/internal/fromproto5/invokeaction_test.go index 6f74fcf83..49ce6de65 100644 --- a/internal/fromproto5/invokeaction_test.go +++ b/internal/fromproto5/invokeaction_test.go @@ -39,7 +39,7 @@ func TestInvokeActionRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err) } - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, @@ -91,13 +91,13 @@ func TestInvokeActionRequest(t *testing.T) { input: &tfprotov5.InvokeActionRequest{ Config: &testProto5DynamicValue, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.InvokeActionRequest{ Config: &tfsdk.Config{ Raw: testProto5Value, - Schema: testUnlinkedSchema, + Schema: testSchema, }, - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, }, }, } diff --git a/internal/fromproto5/planaction.go b/internal/fromproto5/planaction.go index ec1d32ae8..147906fd4 100644 --- a/internal/fromproto5/planaction.go +++ b/internal/fromproto5/planaction.go @@ -48,7 +48,5 @@ func PlanActionRequest(ctx context.Context, proto5 *tfprotov5.PlanActionRequest, fw.Config = config - // TODO:Actions: Add linked resources when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto5/planaction_test.go b/internal/fromproto5/planaction_test.go index 294792d58..3335605ae 100644 --- a/internal/fromproto5/planaction_test.go +++ b/internal/fromproto5/planaction_test.go @@ -39,7 +39,7 @@ func TestPlanActionRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err) } - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, @@ -91,13 +91,13 @@ func TestPlanActionRequest(t *testing.T) { input: &tfprotov5.PlanActionRequest{ Config: &testProto5DynamicValue, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ Config: &tfsdk.Config{ Raw: testProto5Value, - Schema: testUnlinkedSchema, + Schema: testSchema, }, - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, }, }, "client-capabilities": { @@ -106,9 +106,9 @@ func TestPlanActionRequest(t *testing.T) { DeferralAllowed: true, }, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, ClientCapabilities: action.ModifyPlanClientCapabilities{ DeferralAllowed: true, }, @@ -116,9 +116,9 @@ func TestPlanActionRequest(t *testing.T) { }, "client-capabilities-unset": { input: &tfprotov5.PlanActionRequest{}, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, ClientCapabilities: action.ModifyPlanClientCapabilities{ DeferralAllowed: false, }, diff --git a/internal/fromproto5/validateactionconfig.go b/internal/fromproto5/validateactionconfig.go index 397599ea3..569e6fe60 100644 --- a/internal/fromproto5/validateactionconfig.go +++ b/internal/fromproto5/validateactionconfig.go @@ -6,11 +6,12 @@ package fromproto5 import ( "context" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ValidateActionConfigRequest returns the *fwserver.ValidateActionConfigRequest @@ -27,7 +28,5 @@ func ValidateActionConfigRequest(ctx context.Context, proto5 *tfprotov5.Validate fw.Config = config fw.Action = reqAction - // TODO:Actions: Add linked resource configs when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto5/validateactionconfig_test.go b/internal/fromproto5/validateactionconfig_test.go index 4ecfeedc2..c129fe3b9 100644 --- a/internal/fromproto5/validateactionconfig_test.go +++ b/internal/fromproto5/validateactionconfig_test.go @@ -38,7 +38,7 @@ func TestValidateActionConfigRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err) } - testFwSchema := schema.UnlinkedSchema{ + testFwSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, diff --git a/internal/fromproto6/invokeaction.go b/internal/fromproto6/invokeaction.go index 6759531a7..bd344e3bd 100644 --- a/internal/fromproto6/invokeaction.go +++ b/internal/fromproto6/invokeaction.go @@ -47,7 +47,5 @@ func InvokeActionRequest(ctx context.Context, proto6 *tfprotov6.InvokeActionRequ fw.Config = config - // TODO:Actions: Add linked resources when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto6/invokeaction_test.go b/internal/fromproto6/invokeaction_test.go index 9772d420e..03513a3a4 100644 --- a/internal/fromproto6/invokeaction_test.go +++ b/internal/fromproto6/invokeaction_test.go @@ -39,7 +39,7 @@ func TestInvokeActionRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err) } - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, @@ -91,13 +91,13 @@ func TestInvokeActionRequest(t *testing.T) { input: &tfprotov6.InvokeActionRequest{ Config: &testProto6DynamicValue, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.InvokeActionRequest{ Config: &tfsdk.Config{ Raw: testProto6Value, - Schema: testUnlinkedSchema, + Schema: testSchema, }, - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, }, }, } diff --git a/internal/fromproto6/planaction.go b/internal/fromproto6/planaction.go index 0cb71e3dd..08c4072ba 100644 --- a/internal/fromproto6/planaction.go +++ b/internal/fromproto6/planaction.go @@ -48,7 +48,5 @@ func PlanActionRequest(ctx context.Context, proto6 *tfprotov6.PlanActionRequest, fw.Config = config - // TODO:Actions: Add linked resources when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto6/planaction_test.go b/internal/fromproto6/planaction_test.go index 6bc0fa7fe..c3bc40448 100644 --- a/internal/fromproto6/planaction_test.go +++ b/internal/fromproto6/planaction_test.go @@ -39,7 +39,7 @@ func TestPlanActionRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err) } - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, @@ -91,13 +91,13 @@ func TestPlanActionRequest(t *testing.T) { input: &tfprotov6.PlanActionRequest{ Config: &testProto6DynamicValue, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ Config: &tfsdk.Config{ Raw: testProto6Value, - Schema: testUnlinkedSchema, + Schema: testSchema, }, - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, }, }, "client-capabilities": { @@ -106,9 +106,9 @@ func TestPlanActionRequest(t *testing.T) { DeferralAllowed: true, }, }, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, ClientCapabilities: action.ModifyPlanClientCapabilities{ DeferralAllowed: true, }, @@ -116,9 +116,9 @@ func TestPlanActionRequest(t *testing.T) { }, "client-capabilities-unset": { input: &tfprotov6.PlanActionRequest{}, - actionSchema: testUnlinkedSchema, + actionSchema: testSchema, expected: &fwserver.PlanActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, ClientCapabilities: action.ModifyPlanClientCapabilities{ DeferralAllowed: false, }, diff --git a/internal/fromproto6/validateactionconfig.go b/internal/fromproto6/validateactionconfig.go index 9c1f36303..514f6f48b 100644 --- a/internal/fromproto6/validateactionconfig.go +++ b/internal/fromproto6/validateactionconfig.go @@ -6,11 +6,12 @@ package fromproto6 import ( "context" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ValidateActionConfigRequest returns the *fwserver.ValidateActionConfigRequest @@ -27,7 +28,5 @@ func ValidateActionConfigRequest(ctx context.Context, proto6 *tfprotov6.Validate fw.Config = config fw.Action = reqAction - // TODO:Actions: Add linked resource configs when new action schema types are introduced - return fw, diags } diff --git a/internal/fromproto6/validateactionconfig_test.go b/internal/fromproto6/validateactionconfig_test.go index c782c2e2f..3f40a5e1b 100644 --- a/internal/fromproto6/validateactionconfig_test.go +++ b/internal/fromproto6/validateactionconfig_test.go @@ -38,7 +38,7 @@ func TestValidateActionConfigRequest(t *testing.T) { t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err) } - testFwSchema := schema.UnlinkedSchema{ + testFwSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_attribute": schema.StringAttribute{ Required: true, diff --git a/internal/fwserver/server.go b/internal/fwserver/server.go index adac3cafe..b15a08328 100644 --- a/internal/fwserver/server.go +++ b/internal/fwserver/server.go @@ -55,7 +55,7 @@ type Server struct { // actionSchemas is the cached Action Schemas for RPCs that need to // convert configuration data from the protocol. If not found, it will be // fetched from the Action.Schema() method. - actionSchemas map[string]actionschema.SchemaType + actionSchemas map[string]actionschema.Schema // actionSchemasMutex is a mutex to protect concurrent actionSchemas // access from race conditions. diff --git a/internal/fwserver/server_actions.go b/internal/fwserver/server_actions.go index 4fd25ae87..66f10c21d 100644 --- a/internal/fwserver/server_actions.go +++ b/internal/fwserver/server_actions.go @@ -112,7 +112,7 @@ func (s *Server) ActionMetadatas(ctx context.Context) ([]ActionMetadata, diag.Di // ActionSchema returns the Action Schema for the given type name and // caches the result for later Action operations. -func (s *Server) ActionSchema(ctx context.Context, actionType string) (actionschema.SchemaType, diag.Diagnostics) { +func (s *Server) ActionSchema(ctx context.Context, actionType string) (actionschema.Schema, diag.Diagnostics) { s.actionSchemasMutex.RLock() actionSchema, ok := s.actionSchemas[actionType] s.actionSchemasMutex.RUnlock() @@ -128,7 +128,7 @@ func (s *Server) ActionSchema(ctx context.Context, actionType string) (actionsch diags.Append(actionDiags...) if diags.HasError() { - return nil, diags + return actionSchema, diags } schemaReq := action.SchemaRequest{} @@ -147,7 +147,7 @@ func (s *Server) ActionSchema(ctx context.Context, actionType string) (actionsch s.actionSchemasMutex.Lock() if s.actionSchemas == nil { - s.actionSchemas = make(map[string]actionschema.SchemaType) + s.actionSchemas = make(map[string]actionschema.Schema) } s.actionSchemas[actionType] = schemaResp.Schema @@ -161,8 +161,8 @@ func (s *Server) ActionSchema(ctx context.Context, actionType string) (actionsch // GetProviderSchema RPC without caching since not all schemas are guaranteed to // be necessary for later provider operations. The schema implementations are // also validated. -func (s *Server) ActionSchemas(ctx context.Context) (map[string]actionschema.SchemaType, diag.Diagnostics) { - actionSchemas := make(map[string]actionschema.SchemaType) +func (s *Server) ActionSchemas(ctx context.Context) (map[string]actionschema.Schema, diag.Diagnostics) { + actionSchemas := make(map[string]actionschema.Schema) actionFuncs, diags := s.ActionFuncs(ctx) diff --git a/internal/fwserver/server_getproviderschema.go b/internal/fwserver/server_getproviderschema.go index 74a25446e..d04a46965 100644 --- a/internal/fwserver/server_getproviderschema.go +++ b/internal/fwserver/server_getproviderschema.go @@ -22,7 +22,7 @@ type GetProviderSchemaResponse struct { ServerCapabilities *ServerCapabilities Provider fwschema.Schema ProviderMeta fwschema.Schema - ActionSchemas map[string]actionschema.SchemaType + ActionSchemas map[string]actionschema.Schema ResourceSchemas map[string]fwschema.Schema DataSourceSchemas map[string]fwschema.Schema EphemeralResourceSchemas map[string]fwschema.Schema diff --git a/internal/fwserver/server_getproviderschema_test.go b/internal/fwserver/server_getproviderschema_test.go index 014ce72f3..c55d5c757 100644 --- a/internal/fwserver/server_getproviderschema_test.go +++ b/internal/fwserver/server_getproviderschema_test.go @@ -42,7 +42,7 @@ func TestServerGetProviderSchema(t *testing.T) { Provider: &testprovider.Provider{}, }, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, @@ -64,7 +64,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test1": actionschema.StringAttribute{ Required: true, @@ -80,7 +80,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -99,15 +99,15 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "test_action1": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "test_action1": { Attributes: map[string]actionschema.Attribute{ "test1": actionschema.StringAttribute{ Required: true, }, }, }, - "test_action2": actionschema.UnlinkedSchema{ + "test_action2": { Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -138,7 +138,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "$": actionschema.StringAttribute{ Required: true, @@ -154,7 +154,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -204,7 +204,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test1": actionschema.StringAttribute{ Required: true, @@ -220,7 +220,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -313,7 +313,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test": actionschema.StringAttribute{ Required: true, @@ -332,8 +332,8 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "testprovidertype_action": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "testprovidertype_action": { Attributes: map[string]actionschema.Attribute{ "test": actionschema.StringAttribute{ Required: true, @@ -397,7 +397,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{ "test_data_source1": datasourceschema.Schema{ Attributes: map[string]datasourceschema.Attribute{ @@ -613,7 +613,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{ "testprovidertype_data_source": datasourceschema.Schema{ Attributes: map[string]datasourceschema.Attribute{ @@ -678,7 +678,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{ "test_ephemeral_resource1": ephemeralschema.Schema{ @@ -900,7 +900,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{ "testprovidertype_ephemeral_resource": ephemeralschema.Schema{ @@ -957,7 +957,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{ @@ -1169,7 +1169,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, @@ -1291,7 +1291,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, @@ -1360,7 +1360,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, @@ -1458,7 +1458,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, @@ -1673,7 +1673,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, request: &fwserver.GetProviderSchemaRequest{}, expectedResponse: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{}, + ActionSchemas: map[string]actionschema.Schema{}, DataSourceSchemas: map[string]fwschema.Schema{}, EphemeralResourceSchemas: map[string]fwschema.Schema{}, FunctionDefinitions: map[string]function.Definition{}, diff --git a/internal/fwserver/server_invokeaction_test.go b/internal/fwserver/server_invokeaction_test.go index ece66c657..0ccb44db5 100644 --- a/internal/fwserver/server_invokeaction_test.go +++ b/internal/fwserver/server_invokeaction_test.go @@ -9,6 +9,8 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -17,7 +19,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerInvokeAction(t *testing.T) { @@ -33,7 +34,7 @@ func TestServerInvokeAction(t *testing.T) { "test_required": tftypes.NewValue(tftypes.String, "test-config-value"), }) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -41,9 +42,9 @@ func TestServerInvokeAction(t *testing.T) { }, } - testUnlinkedConfig := &tfsdk.Config{ + testConfig := &tfsdk.Config{ Raw: testConfigValue, - Schema: testUnlinkedSchema, + Schema: testSchema, } testCases := map[string]struct { @@ -58,12 +59,12 @@ func TestServerInvokeAction(t *testing.T) { }, expectedResponse: &fwserver.InvokeActionResponse{}, }, - "unlinked-nil-config": { + "nil-config": { server: &fwserver.Server{ Provider: &testprovider.Provider{}, }, request: &fwserver.InvokeActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, Action: &testprovider.Action{ InvokeMethod: func(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) { if !req.Config.Raw.IsNull() { @@ -79,8 +80,8 @@ func TestServerInvokeAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.InvokeActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.Action{ InvokeMethod: func(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) { var config struct { @@ -103,8 +104,8 @@ func TestServerInvokeAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.InvokeActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithConfigure{ ConfigureMethod: func(ctx context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse) { providerData, ok := req.ProviderData.(string) @@ -141,8 +142,8 @@ func TestServerInvokeAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.InvokeActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.Action{ InvokeMethod: func(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") diff --git a/internal/fwserver/server_planaction.go b/internal/fwserver/server_planaction.go index 38ab5b9ee..94e9d3cf7 100644 --- a/internal/fwserver/server_planaction.go +++ b/internal/fwserver/server_planaction.go @@ -6,12 +6,13 @@ package fwserver import ( "context" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/tfsdk" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) // PlanActionRequest is the framework server request for the PlanAction RPC. @@ -34,9 +35,6 @@ func (s *Server) PlanAction(ctx context.Context, req *PlanActionRequest, resp *P return } - // TODO:Actions: When action schemas that use linked resources are introduced, pass-through proposed -> planned state similar to - // how normal resource planning works. - if s.deferred != nil { logging.FrameworkDebug(ctx, "Provider has deferred response configured, automatically returning deferred response.", map[string]interface{}{ diff --git a/internal/fwserver/server_planaction_test.go b/internal/fwserver/server_planaction_test.go index d922eb844..5a62b650d 100644 --- a/internal/fwserver/server_planaction_test.go +++ b/internal/fwserver/server_planaction_test.go @@ -9,6 +9,8 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -17,7 +19,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerPlanAction(t *testing.T) { @@ -33,7 +34,7 @@ func TestServerPlanAction(t *testing.T) { "test_required": tftypes.NewValue(tftypes.String, "test-config-value"), }) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -41,9 +42,9 @@ func TestServerPlanAction(t *testing.T) { }, } - testUnlinkedConfig := &tfsdk.Config{ + testConfig := &tfsdk.Config{ Raw: testConfigValue, - Schema: testUnlinkedSchema, + Schema: testSchema, } testDeferralAllowed := action.ModifyPlanClientCapabilities{ @@ -62,12 +63,12 @@ func TestServerPlanAction(t *testing.T) { }, expectedResponse: &fwserver.PlanActionResponse{}, }, - "unlinked-nil-config-no-modifyplan": { + "nil-config-no-modifyplan": { server: &fwserver.Server{ Provider: &testprovider.Provider{}, }, request: &fwserver.PlanActionRequest{ - ActionSchema: testUnlinkedSchema, + ActionSchema: testSchema, Action: &testprovider.Action{}, }, expectedResponse: &fwserver.PlanActionResponse{}, @@ -78,8 +79,8 @@ func TestServerPlanAction(t *testing.T) { }, request: &fwserver.PlanActionRequest{ ClientCapabilities: testDeferralAllowed, - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req action.ModifyPlanRequest, resp *action.ModifyPlanResponse) { if req.ClientCapabilities.DeferralAllowed != true { @@ -102,8 +103,8 @@ func TestServerPlanAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.PlanActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req action.ModifyPlanRequest, resp *action.ModifyPlanResponse) { var config struct { @@ -126,8 +127,8 @@ func TestServerPlanAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.PlanActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithConfigureAndModifyPlan{ ConfigureMethod: func(ctx context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse) { providerData, ok := req.ProviderData.(string) @@ -172,8 +173,8 @@ func TestServerPlanAction(t *testing.T) { }, }, request: &fwserver.PlanActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req action.ModifyPlanRequest, resp *action.ModifyPlanResponse) { resp.Diagnostics.AddError("Test assertion failed: ", "ModifyPlan shouldn't be called") @@ -190,8 +191,8 @@ func TestServerPlanAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.PlanActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req action.ModifyPlanRequest, resp *action.ModifyPlanResponse) { var config struct { @@ -218,8 +219,8 @@ func TestServerPlanAction(t *testing.T) { Provider: &testprovider.Provider{}, }, request: &fwserver.PlanActionRequest{ - Config: testUnlinkedConfig, - ActionSchema: testUnlinkedSchema, + Config: testConfig, + ActionSchema: testSchema, Action: &testprovider.ActionWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req action.ModifyPlanRequest, resp *action.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") diff --git a/internal/fwserver/server_validateactionconfig_test.go b/internal/fwserver/server_validateactionconfig_test.go index 0a9d30ce6..76636ebde 100644 --- a/internal/fwserver/server_validateactionconfig_test.go +++ b/internal/fwserver/server_validateactionconfig_test.go @@ -34,7 +34,7 @@ func TestServerValidateActionConfig(t *testing.T) { "test": tftypes.NewValue(tftypes.String, "test-value"), }) - testSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{ Required: true, @@ -47,7 +47,7 @@ func TestServerValidateActionConfig(t *testing.T) { Schema: testSchema, } - testSchemaAttributeValidator := schema.UnlinkedSchema{ + testSchemaAttributeValidator := schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{ Required: true, @@ -69,7 +69,7 @@ func TestServerValidateActionConfig(t *testing.T) { Schema: testSchemaAttributeValidator, } - testSchemaAttributeValidatorError := schema.UnlinkedSchema{ + testSchemaAttributeValidatorError := schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{ Required: true, diff --git a/internal/proto5server/server_getproviderschema_test.go b/internal/proto5server/server_getproviderschema_test.go index 409e06e9e..abec99b4f 100644 --- a/internal/proto5server/server_getproviderschema_test.go +++ b/internal/proto5server/server_getproviderschema_test.go @@ -9,6 +9,10 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-log/tfsdklogtest" + "github.com/hashicorp/terraform-plugin-framework/action" actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -26,9 +30,6 @@ import ( providerschema "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" resourceschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "github.com/hashicorp/terraform-plugin-log/tfsdklogtest" ) func TestServerGetProviderSchema(t *testing.T) { @@ -49,7 +50,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test1": actionschema.StringAttribute{ Required: true, @@ -65,7 +66,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -87,7 +88,6 @@ func TestServerGetProviderSchema(t *testing.T) { expectedResponse: &tfprotov5.GetProviderSchemaResponse{ ActionSchemas: map[string]*tfprotov5.ActionSchema{ "test_action1": { - Type: tfprotov5.UnlinkedActionSchemaType{}, Schema: &tfprotov5.Schema{ Block: &tfprotov5.SchemaBlock{ Attributes: []*tfprotov5.SchemaAttribute{ @@ -101,7 +101,6 @@ func TestServerGetProviderSchema(t *testing.T) { }, }, "test_action2": { - Type: tfprotov5.UnlinkedActionSchemaType{}, Schema: &tfprotov5.Schema{ Block: &tfprotov5.SchemaBlock{ Attributes: []*tfprotov5.SchemaAttribute{ diff --git a/internal/proto5server/server_invokeaction_test.go b/internal/proto5server/server_invokeaction_test.go index 6d08c770d..e5403dd9e 100644 --- a/internal/proto5server/server_invokeaction_test.go +++ b/internal/proto5server/server_invokeaction_test.go @@ -10,13 +10,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerInvokeAction(t *testing.T) { @@ -34,7 +35,7 @@ func TestServerInvokeAction(t *testing.T) { testEmptyDynamicValue := testNewDynamicValue(t, tftypes.Object{}, nil) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -57,7 +58,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = schema.UnlinkedSchema{} + resp.Schema = schema.Schema{} }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -88,7 +89,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -130,7 +131,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -181,7 +182,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -229,7 +230,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" diff --git a/internal/proto5server/server_planaction_test.go b/internal/proto5server/server_planaction_test.go index d3017e4a9..d054ce9fb 100644 --- a/internal/proto5server/server_planaction_test.go +++ b/internal/proto5server/server_planaction_test.go @@ -8,13 +8,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerPlanAction(t *testing.T) { @@ -32,7 +33,7 @@ func TestServerPlanAction(t *testing.T) { testEmptyDynamicValue := testNewDynamicValue(t, tftypes.Object{}, nil) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -55,7 +56,7 @@ func TestServerPlanAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = schema.UnlinkedSchema{} + resp.Schema = schema.Schema{} }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -83,7 +84,7 @@ func TestServerPlanAction(t *testing.T) { return &testprovider.ActionWithModifyPlan{ Action: &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -123,7 +124,7 @@ func TestServerPlanAction(t *testing.T) { return &testprovider.ActionWithModifyPlan{ Action: &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" diff --git a/internal/proto5server/server_validateactionconfig_test.go b/internal/proto5server/server_validateactionconfig_test.go index 77349fecf..4c5ea9659 100644 --- a/internal/proto5server/server_validateactionconfig_test.go +++ b/internal/proto5server/server_validateactionconfig_test.go @@ -35,7 +35,7 @@ func TestServerValidateActionConfig(t *testing.T) { t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err) } - testSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{ Required: true, diff --git a/internal/proto6server/server_getproviderschema_test.go b/internal/proto6server/server_getproviderschema_test.go index e93e75b70..aea2c6061 100644 --- a/internal/proto6server/server_getproviderschema_test.go +++ b/internal/proto6server/server_getproviderschema_test.go @@ -9,6 +9,10 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-log/tfsdklogtest" + "github.com/hashicorp/terraform-plugin-framework/action" actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -26,9 +30,6 @@ import ( providerschema "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" resourceschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "github.com/hashicorp/terraform-plugin-log/tfsdklogtest" ) func TestServerGetProviderSchema(t *testing.T) { @@ -49,7 +50,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test1": actionschema.StringAttribute{ Required: true, @@ -65,7 +66,7 @@ func TestServerGetProviderSchema(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = actionschema.UnlinkedSchema{ + resp.Schema = actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "test2": actionschema.StringAttribute{ Required: true, @@ -87,7 +88,6 @@ func TestServerGetProviderSchema(t *testing.T) { expectedResponse: &tfprotov6.GetProviderSchemaResponse{ ActionSchemas: map[string]*tfprotov6.ActionSchema{ "test_action1": { - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ @@ -101,7 +101,6 @@ func TestServerGetProviderSchema(t *testing.T) { }, }, "test_action2": { - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ diff --git a/internal/proto6server/server_invokeaction_test.go b/internal/proto6server/server_invokeaction_test.go index 0c36bf980..8c2e4da37 100644 --- a/internal/proto6server/server_invokeaction_test.go +++ b/internal/proto6server/server_invokeaction_test.go @@ -10,13 +10,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerInvokeAction(t *testing.T) { @@ -34,7 +35,7 @@ func TestServerInvokeAction(t *testing.T) { testEmptyDynamicValue := testNewDynamicValue(t, tftypes.Object{}, nil) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -57,7 +58,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = schema.UnlinkedSchema{} + resp.Schema = schema.Schema{} }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -88,7 +89,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -130,7 +131,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -181,7 +182,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -229,7 +230,7 @@ func TestServerInvokeAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" diff --git a/internal/proto6server/server_planaction_test.go b/internal/proto6server/server_planaction_test.go index 8d4093e2f..844ee2443 100644 --- a/internal/proto6server/server_planaction_test.go +++ b/internal/proto6server/server_planaction_test.go @@ -8,13 +8,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-framework/action" "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestServerPlanAction(t *testing.T) { @@ -32,7 +33,7 @@ func TestServerPlanAction(t *testing.T) { testEmptyDynamicValue := testNewDynamicValue(t, tftypes.Object{}, nil) - testUnlinkedSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test_required": schema.StringAttribute{ Required: true, @@ -55,7 +56,7 @@ func TestServerPlanAction(t *testing.T) { func() action.Action { return &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = schema.UnlinkedSchema{} + resp.Schema = schema.Schema{} }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -83,7 +84,7 @@ func TestServerPlanAction(t *testing.T) { return &testprovider.ActionWithModifyPlan{ Action: &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" @@ -123,7 +124,7 @@ func TestServerPlanAction(t *testing.T) { return &testprovider.ActionWithModifyPlan{ Action: &testprovider.Action{ SchemaMethod: func(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) { - resp.Schema = testUnlinkedSchema + resp.Schema = testSchema }, MetadataMethod: func(_ context.Context, _ action.MetadataRequest, resp *action.MetadataResponse) { resp.TypeName = "test_action" diff --git a/internal/proto6server/server_validateactionconfig_test.go b/internal/proto6server/server_validateactionconfig_test.go index 4fd7ce2d5..c6d01a839 100644 --- a/internal/proto6server/server_validateactionconfig_test.go +++ b/internal/proto6server/server_validateactionconfig_test.go @@ -35,7 +35,7 @@ func TestServerValidateActionConfig(t *testing.T) { t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err) } - testSchema := schema.UnlinkedSchema{ + testSchema := schema.Schema{ Attributes: map[string]schema.Attribute{ "test": schema.StringAttribute{ Required: true, diff --git a/internal/toproto5/action_schema.go b/internal/toproto5/action_schema.go index 2b2139bfa..ee4566235 100644 --- a/internal/toproto5/action_schema.go +++ b/internal/toproto5/action_schema.go @@ -5,18 +5,14 @@ package toproto5 import ( "context" - "fmt" - actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + + actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" ) // ActionSchema returns the *tfprotov5.ActionSchema equivalent of a ActionSchema. -func ActionSchema(ctx context.Context, s actionschema.SchemaType) (*tfprotov5.ActionSchema, error) { - if s == nil { - return nil, nil - } - +func ActionSchema(ctx context.Context, s actionschema.Schema) (*tfprotov5.ActionSchema, error) { configSchema, err := Schema(ctx, s) if err != nil { return nil, err @@ -26,17 +22,5 @@ func ActionSchema(ctx context.Context, s actionschema.SchemaType) (*tfprotov5.Ac Schema: configSchema, } - // TODO:Actions: Implement action schema types that can modify state - switch s.(type) { - case actionschema.UnlinkedSchema: - result.Type = tfprotov5.UnlinkedActionSchemaType{} - default: - // It is not currently possible to create [actionschema.SchemaType] - // implementations outside the "action/schema" package. If this error was reached, - // it implies that a new event type was introduced and needs to be implemented - // as a new case above. - return nil, fmt.Errorf("unimplemented schema.SchemaType type: %T", s) - } - return result, nil } diff --git a/internal/toproto5/action_schema_test.go b/internal/toproto5/action_schema_test.go index 39b7e7c7f..5dfbbe3de 100644 --- a/internal/toproto5/action_schema_test.go +++ b/internal/toproto5/action_schema_test.go @@ -8,28 +8,31 @@ import ( "testing" "github.com/google/go-cmp/cmp" - actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" - "github.com/hashicorp/terraform-plugin-framework/internal/toproto5" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tftypes" + + actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" + "github.com/hashicorp/terraform-plugin-framework/internal/toproto5" ) func TestActionSchema(t *testing.T) { t.Parallel() type testCase struct { - input actionschema.SchemaType + input actionschema.Schema expected *tfprotov5.ActionSchema expectedErr string } tests := map[string]testCase{ - "nil": { - input: nil, - expected: nil, + "empty": { + input: actionschema.Schema{}, + expected: &tfprotov5.ActionSchema{ + Schema: &tfprotov5.Schema{Block: &tfprotov5.SchemaBlock{}}, + }, }, - "unlinked": { - input: actionschema.UnlinkedSchema{ + "valid": { + input: actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "bool": actionschema.BoolAttribute{ Optional: true, @@ -52,7 +55,6 @@ func TestActionSchema(t *testing.T) { }, }, expected: &tfprotov5.ActionSchema{ - Type: tfprotov5.UnlinkedActionSchemaType{}, Schema: &tfprotov5.Schema{ Version: 0, Block: &tfprotov5.SchemaBlock{ diff --git a/internal/toproto5/getproviderschema_test.go b/internal/toproto5/getproviderschema_test.go index 807850a07..91cd0428a 100644 --- a/internal/toproto5/getproviderschema_test.go +++ b/internal/toproto5/getproviderschema_test.go @@ -41,15 +41,15 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, "action-multiple-actions": { input: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "test_action_1": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "test_action_1": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.StringAttribute{ Required: true, }, }, }, - "test_action_2": actionschema.UnlinkedSchema{ + "test_action_2": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.StringAttribute{ Optional: true, @@ -62,7 +62,6 @@ func TestGetProviderSchemaResponse(t *testing.T) { expected: &tfprotov5.GetProviderSchemaResponse{ ActionSchemas: map[string]*tfprotov5.ActionSchema{ "test_action_1": { - Type: tfprotov5.UnlinkedActionSchemaType{}, Schema: &tfprotov5.Schema{ Version: 0, Block: &tfprotov5.SchemaBlock{ @@ -77,7 +76,6 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, }, "test_action_2": { - Type: tfprotov5.UnlinkedActionSchemaType{}, Schema: &tfprotov5.Schema{ Version: 0, Block: &tfprotov5.SchemaBlock{ @@ -102,8 +100,8 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, "action-type-invalid-proto-6-nested-attributes": { input: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "test_action": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "test_action": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.SingleNestedAttribute{ Attributes: map[string]actionschema.Attribute{ diff --git a/internal/toproto5/invoke_action_event.go b/internal/toproto5/invoke_action_event.go index f858635a2..c445c21be 100644 --- a/internal/toproto5/invoke_action_event.go +++ b/internal/toproto5/invoke_action_event.go @@ -6,8 +6,9 @@ package toproto5 import ( "context" - "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + + "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" ) func ProgressInvokeActionEventType(ctx context.Context, event fwserver.InvokeProgressEvent) tfprotov5.InvokeActionEvent { @@ -21,7 +22,6 @@ func ProgressInvokeActionEventType(ctx context.Context, event fwserver.InvokePro func CompletedInvokeActionEventType(ctx context.Context, event *fwserver.InvokeActionResponse) tfprotov5.InvokeActionEvent { return tfprotov5.InvokeActionEvent{ Type: tfprotov5.CompletedInvokeActionEventType{ - // TODO:Actions: Add linked resources when new action schema types are introduced Diagnostics: Diagnostics(ctx, event.Diagnostics), }, } diff --git a/internal/toproto5/planaction.go b/internal/toproto5/planaction.go index 2a50c500e..ff187e497 100644 --- a/internal/toproto5/planaction.go +++ b/internal/toproto5/planaction.go @@ -22,7 +22,5 @@ func PlanActionResponse(ctx context.Context, fw *fwserver.PlanActionResponse) *t Deferred: ActionDeferred(fw.Deferred), } - // TODO:Actions: Add linked resources when new action schema types are introduced - return proto5 } diff --git a/internal/toproto6/action_schema.go b/internal/toproto6/action_schema.go index ce6e1be45..cae8ab128 100644 --- a/internal/toproto6/action_schema.go +++ b/internal/toproto6/action_schema.go @@ -5,18 +5,14 @@ package toproto6 import ( "context" - "fmt" - actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + + actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" ) // ActionSchema returns the *tfprotov6.ActionSchema equivalent of a ActionSchema. -func ActionSchema(ctx context.Context, s actionschema.SchemaType) (*tfprotov6.ActionSchema, error) { - if s == nil { - return nil, nil - } - +func ActionSchema(ctx context.Context, s actionschema.Schema) (*tfprotov6.ActionSchema, error) { configSchema, err := Schema(ctx, s) if err != nil { return nil, err @@ -26,17 +22,5 @@ func ActionSchema(ctx context.Context, s actionschema.SchemaType) (*tfprotov6.Ac Schema: configSchema, } - // TODO:Actions: Implement action schema types that can modify state - switch s.(type) { - case actionschema.UnlinkedSchema: - result.Type = tfprotov6.UnlinkedActionSchemaType{} - default: - // It is not currently possible to create [actionschema.SchemaType] - // implementations outside the "action/schema" package. If this error was reached, - // it implies that a new event type was introduced and needs to be implemented - // as a new case above. - return nil, fmt.Errorf("unimplemented schema.SchemaType type: %T", s) - } - return result, nil } diff --git a/internal/toproto6/action_schema_test.go b/internal/toproto6/action_schema_test.go index ab145a2d7..dbd8603d2 100644 --- a/internal/toproto6/action_schema_test.go +++ b/internal/toproto6/action_schema_test.go @@ -8,28 +8,31 @@ import ( "testing" "github.com/google/go-cmp/cmp" - actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" - "github.com/hashicorp/terraform-plugin-framework/internal/toproto6" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + + actionschema "github.com/hashicorp/terraform-plugin-framework/action/schema" + "github.com/hashicorp/terraform-plugin-framework/internal/toproto6" ) func TestActionSchema(t *testing.T) { t.Parallel() type testCase struct { - input actionschema.SchemaType + input actionschema.Schema expected *tfprotov6.ActionSchema expectedErr string } tests := map[string]testCase{ - "nil": { - input: nil, - expected: nil, + "empty": { + input: actionschema.Schema{}, + expected: &tfprotov6.ActionSchema{ + Schema: &tfprotov6.Schema{Block: &tfprotov6.SchemaBlock{}}, + }, }, - "unlinked": { - input: actionschema.UnlinkedSchema{ + "valid": { + input: actionschema.Schema{ Attributes: map[string]actionschema.Attribute{ "bool": actionschema.BoolAttribute{ Optional: true, @@ -52,7 +55,6 @@ func TestActionSchema(t *testing.T) { }, }, expected: &tfprotov6.ActionSchema{ - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Version: 0, Block: &tfprotov6.SchemaBlock{ diff --git a/internal/toproto6/getproviderschema_test.go b/internal/toproto6/getproviderschema_test.go index 5c0037b82..54b8b3a86 100644 --- a/internal/toproto6/getproviderschema_test.go +++ b/internal/toproto6/getproviderschema_test.go @@ -41,15 +41,15 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, "action-multiple-actions": { input: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "test_action_1": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "test_action_1": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.StringAttribute{ Required: true, }, }, }, - "test_action_2": actionschema.UnlinkedSchema{ + "test_action_2": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.StringAttribute{ Optional: true, @@ -62,7 +62,6 @@ func TestGetProviderSchemaResponse(t *testing.T) { expected: &tfprotov6.GetProviderSchemaResponse{ ActionSchemas: map[string]*tfprotov6.ActionSchema{ "test_action_1": { - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Version: 0, Block: &tfprotov6.SchemaBlock{ @@ -77,7 +76,6 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, }, "test_action_2": { - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Version: 0, Block: &tfprotov6.SchemaBlock{ @@ -102,8 +100,8 @@ func TestGetProviderSchemaResponse(t *testing.T) { }, "action-type-nested-attributes": { input: &fwserver.GetProviderSchemaResponse{ - ActionSchemas: map[string]actionschema.SchemaType{ - "test_action": actionschema.UnlinkedSchema{ + ActionSchemas: map[string]actionschema.Schema{ + "test_action": { Attributes: map[string]actionschema.Attribute{ "test_attribute": actionschema.SingleNestedAttribute{ Attributes: map[string]actionschema.Attribute{ @@ -120,7 +118,6 @@ func TestGetProviderSchemaResponse(t *testing.T) { expected: &tfprotov6.GetProviderSchemaResponse{ ActionSchemas: map[string]*tfprotov6.ActionSchema{ "test_action": { - Type: tfprotov6.UnlinkedActionSchemaType{}, Schema: &tfprotov6.Schema{ Version: 0, Block: &tfprotov6.SchemaBlock{ diff --git a/internal/toproto6/invoke_action_event.go b/internal/toproto6/invoke_action_event.go index 921d46464..161246cf6 100644 --- a/internal/toproto6/invoke_action_event.go +++ b/internal/toproto6/invoke_action_event.go @@ -6,8 +6,9 @@ package toproto6 import ( "context" - "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + + "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" ) func ProgressInvokeActionEventType(ctx context.Context, event fwserver.InvokeProgressEvent) tfprotov6.InvokeActionEvent { @@ -21,7 +22,6 @@ func ProgressInvokeActionEventType(ctx context.Context, event fwserver.InvokePro func CompletedInvokeActionEventType(ctx context.Context, event *fwserver.InvokeActionResponse) tfprotov6.InvokeActionEvent { return tfprotov6.InvokeActionEvent{ Type: tfprotov6.CompletedInvokeActionEventType{ - // TODO:Actions: Add linked resources when new action schema types are introduced Diagnostics: Diagnostics(ctx, event.Diagnostics), }, } diff --git a/internal/toproto6/planaction.go b/internal/toproto6/planaction.go index 8dd6503c6..60397c126 100644 --- a/internal/toproto6/planaction.go +++ b/internal/toproto6/planaction.go @@ -22,7 +22,5 @@ func PlanActionResponse(ctx context.Context, fw *fwserver.PlanActionResponse) *t Deferred: ActionDeferred(fw.Deferred), } - // TODO:Actions: Add linked resources when new action schema types are introduced - return proto6 }