From a278d0acf694b7973dc3cfdeeeedfac70db90e94 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 28 Jul 2022 22:51:11 -0400 Subject: [PATCH 1/3] tfsdk: Migrate data source, provider, and resource types into new Go packages Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/132 Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/365 Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/366 Since the framework's initial release, the `tfsdk` Go package has been a monolithic collection of various provider concepts, including but not limited to handling of data sources, providers, resources, schemas, schema data (such as `Config`, `Plan`, and `State`), and various other helpers. For framework maintainers, this monolithic package has made implementations difficult for certain enhancements, such as import cycles. For provider developers, this monolithic package has been difficult to navigate in the Go documentation. This change represents the first major provider coding paradigm shift to colocate related concepts into their own Go packages, starting with new top-level `datasource`, `provider`, and `resource` packages. This particular change and method (no deprecation period) was not desired, but it was unavoidable due to the interconnectedness of the `tfsdk` package and due to the amount of effort it would require to attempt to support both the old and new types. This change is necessary to complete before there are additional code compatibility promises added to this Go module, such as a version 1.0.0 release or release candidate. This type of change is not taken lightly, as it is quite disruptive for existing provider codebases. On the surface, this change may look fairly unbeneficial for provider developers other than the easier discoverability and reduced wordiness, however it is required to unblock other future refactoring and enhancement efforts in the framework. It is unclear at the time of writing whether splitting out the other concepts from the `tfsdk` package, such as schemas, will present the same issues. Regardless, any other major changes will be spread across releases. Provider developers should be able to update their code using find and replace operations using the tables below. To reduce framework maintainer review burden, all code migrations were lift and shift operations while most code and documentation updates were find and replace operations. | Prior tfsdk Package Type | New provider Package Type | | --- | --- | | `tfsdk.ConfigureProviderRequest` | `provider.ConfigureRequest` | | `tfsdk.ConfigureProviderResponse` | `provider.ConfigureResponse` | | `tfsdk.Provider` | `provider.Provider` | | `tfsdk.ProviderConfigValidator` | `provider.ConfigValidator` | | `tfsdk.ProviderWithConfigValidators` | `provider.ProviderWithConfigValidators` | | `tfsdk.ProviderWithProviderMeta` | `provider.ProviderWithMetaSchema` (note naming realignment) | | `tfsdk.ProviderWithValidateConfig` | `provider.ProviderWithValidateConfig` | | `tfsdk.ValidateProviderConfigRequest` | `provider.ValidateConfigRequest` | | `tfsdk.ValidateProviderConfigResponse` | `provider.ValidateConfigResponse` | The `DataSourceType` abstraction migrates to the `provider` package since it relates to data that must be populated before the provider is configured as well as being passed the `Provider` interface, which can be converted into a concrete Go type when creating a `DataSource`. Other data source concept types are migrated to a new `datasource` package. | Prior tfsdk Package Type | New provider Package Type | | --- | --- | | `tfsdk.DataSourceType` | `provider.DataSourceType` | | Prior tfsdk Package Type | New datasource Package Type | | --- | --- | | `tfsdk.DataSource` | `datasource.DataSource` | | `tfsdk.DataSourceConfigValidator` | `datasource.ConfigValidator` | | `tfsdk.DataSourceWithConfigValidators` | `datasource.DataSourceWithConfigValidators` | | `tfsdk.DataSourceWithValidateConfig` | `datasource.DataSourceWithValidateConfig` | | `tfsdk.ReadDataSourceRequest` | `datasource.ReadRequest` | | `tfsdk.ReadDataSourceResponse` | `datasource.ReadResponse` | | `tfsdk.ValidateDataSourceConfigRequest` | `datasource.ValidateConfigRequest` | | `tfsdk.ValidateDataSourceConfigResponse` | `datasource.ValidateConfigResponse` | The `ResourceType` abstraction migrates to the `provider` package since it relates to data that must be populated before the provider is configured as well as being passed the `Provider` interface, which can be converted into a concrete Go type when creating a `Resource`. Other resource concept types are migrated to a new `resource` package. Additionally, the `tfsdk.ResourceImportStatePassthroughID()` function has been migrated to `resource.ImportStatePassthroughID()`. | Prior tfsdk Package Type | New provider Package Type | | --- | --- | | `tfsdk.ResourceType` | `provider.ResourceType` | | Prior tfsdk Package Type | New resource Package Type | | --- | --- | | `tfsdk.CreateResourceRequest` | `resource.CreateRequest` | | `tfsdk.CreateResourceResponse` | `resource.CreateResponse` | | `tfsdk.DeleteResourceRequest` | `resource.DeleteRequest` | | `tfsdk.DeleteResourceResponse` | `resource.DeleteResponse` | | `tfsdk.ImportResourceStateRequest` | `resource.ImportStateRequest` | | `tfsdk.ImportResourceStateResponse` | `resource.ImportStateResponse` | | `tfsdk.ModifyResourcePlanRequest` | `resource.ModifyPlanRequest` | | `tfsdk.ModifyResourcePlanResponse` | `resource.ModifyPlanResponse` | | `tfsdk.ReadResourceRequest` | `resource.ReadRequest` | | `tfsdk.ReadResourceResponse` | `resource.ReadResponse` | | `tfsdk.Resource` | `resource.Resource` | | `tfsdk.ResourceConfigValidator` | `resource.ConfigValidator` | | `tfsdk.ResourceWithConfigValidators` | `resource.ResourceWithConfigValidators` | | `tfsdk.ResourceWithImportState` | `resource.ResourceWithImportState` | | `tfsdk.ResourceWithModifyPlan` | `resource.ResourceWithModifyPlan` | | `tfsdk.ResourceWithUpgradeState` | `resource.ResourceWithUpgradeState` | | `tfsdk.ResourceWithValidateConfig` | `resource.ResourceWithValidateConfig` | | `tfsdk.UpdateResourceRequest` | `resource.UpdateRequest` | | `tfsdk.UpdateResourceResponse` | `resource.UpdateResponse` | | `tfsdk.UpgradeResourceStateRequest` | `resource.UpgradeStateRequest` | | `tfsdk.UpgradeResourceStateResponse` | `resource.UpgradeStateResponse` | | `tfsdk.ValidateResourceConfigRequest` | `resource.ValidateConfigRequest` | | `tfsdk.ValidateResourceConfigResponse` | `resource.ValidateConfigResponse` | --- .changelog/pending.txt | 27 +++ README.md | 2 +- datasource/config_validator.go | 25 +++ datasource/data_source.go | 43 ++++ datasource/doc.go | 3 + datasource/read.go | 37 +++ datasource/validate_config.go | 30 +++ internal/fromproto5/applyresourcechange.go | 3 +- .../fromproto5/applyresourcechange_test.go | 3 +- internal/fromproto5/configureprovider.go | 5 +- internal/fromproto5/configureprovider_test.go | 11 +- internal/fromproto5/importresourcestate.go | 3 +- .../fromproto5/importresourcestate_test.go | 3 +- internal/fromproto5/planresourcechange.go | 3 +- .../fromproto5/planresourcechange_test.go | 3 +- internal/fromproto5/readdatasource.go | 3 +- internal/fromproto5/readdatasource_test.go | 3 +- internal/fromproto5/readresource.go | 3 +- internal/fromproto5/readresource_test.go | 3 +- internal/fromproto5/upgraderesourcestate.go | 3 +- .../fromproto5/upgraderesourcestate_test.go | 3 +- .../fromproto5/validatedatasourceconfig.go | 3 +- .../validatedatasourceconfig_test.go | 3 +- .../fromproto5/validateresourcetypeconfig.go | 3 +- .../validateresourcetypeconfig_test.go | 3 +- internal/fromproto6/applyresourcechange.go | 3 +- .../fromproto6/applyresourcechange_test.go | 3 +- internal/fromproto6/configureprovider.go | 5 +- internal/fromproto6/configureprovider_test.go | 11 +- internal/fromproto6/importresourcestate.go | 3 +- .../fromproto6/importresourcestate_test.go | 3 +- internal/fromproto6/planresourcechange.go | 3 +- .../fromproto6/planresourcechange_test.go | 3 +- internal/fromproto6/readdatasource.go | 3 +- internal/fromproto6/readdatasource_test.go | 3 +- internal/fromproto6/readresource.go | 3 +- internal/fromproto6/readresource_test.go | 3 +- internal/fromproto6/upgraderesourcestate.go | 3 +- .../fromproto6/upgraderesourcestate_test.go | 3 +- .../fromproto6/validatedatasourceconfig.go | 3 +- .../validatedatasourceconfig_test.go | 3 +- internal/fromproto6/validateresourceconfig.go | 3 +- .../fromproto6/validateresourceconfig_test.go | 3 +- internal/fwserver/server.go | 21 +- .../fwserver/server_applyresourcechange.go | 3 +- .../server_applyresourcechange_test.go | 138 ++++++------ internal/fwserver/server_configureprovider.go | 6 +- .../fwserver/server_configureprovider_test.go | 27 +-- internal/fwserver/server_createresource.go | 14 +- .../fwserver/server_createresource_test.go | 26 ++- internal/fwserver/server_deleteresource.go | 12 +- .../fwserver/server_deleteresource_test.go | 18 +- .../fwserver/server_getproviderschema_test.go | 11 +- .../fwserver/server_importresourcestate.go | 12 +- .../server_importresourcestate_test.go | 24 +- .../fwserver/server_planresourcechange.go | 14 +- .../server_planresourcechange_test.go | 90 ++++---- internal/fwserver/server_readdatasource.go | 8 +- .../fwserver/server_readdatasource_test.go | 18 +- internal/fwserver/server_readresource.go | 12 +- internal/fwserver/server_readresource_test.go | 22 +- internal/fwserver/server_updateresource.go | 12 +- .../fwserver/server_updateresource_test.go | 30 +-- .../fwserver/server_upgraderesourcestate.go | 14 +- .../server_upgraderesourcestate_test.go | 74 +++--- .../server_validatedatasourceconfig.go | 18 +- .../server_validatedatasourceconfig_test.go | 26 ++- .../fwserver/server_validateproviderconfig.go | 19 +- .../server_validateproviderconfig_test.go | 17 +- .../fwserver/server_validateresourceconfig.go | 20 +- .../server_validateresourceconfig_test.go | 26 ++- .../server_applyresourcechange_test.go | 212 +++++++++--------- .../proto5server/server_configureprovider.go | 4 +- .../server_configureprovider_test.go | 9 +- .../server_getproviderschema_test.go | 11 +- .../server_importresourcestate_test.go | 30 +-- .../server_planresourcechange_test.go | 152 ++++++------- .../server_prepareproviderconfig_test.go | 3 +- .../server_readdatasource_test.go | 42 ++-- .../proto5server/server_readresource_test.go | 50 +++-- .../server_upgraderesourcestate_test.go | 38 ++-- .../server_validatedatasourceconfig_test.go | 22 +- .../server_validateresourcetypeconfig_test.go | 22 +- .../server_applyresourcechange_test.go | 212 +++++++++--------- .../proto6server/server_configureprovider.go | 4 +- .../server_configureprovider_test.go | 9 +- .../server_getproviderschema_test.go | 11 +- .../server_importresourcestate_test.go | 30 +-- .../server_planresourcechange_test.go | 152 ++++++------- .../server_readdatasource_test.go | 42 ++-- .../proto6server/server_readresource_test.go | 50 +++-- .../server_upgraderesourcestate_test.go | 38 ++-- .../server_validatedataresourceconfig_test.go | 22 +- .../server_validateproviderconfig_test.go | 3 +- .../server_validateresourceconfig_test.go | 22 +- internal/testing/testprovider/datasource.go | 12 +- .../testprovider/datasourceconfigvalidator.go | 16 +- .../testing/testprovider/datasourcetype.go | 14 +- .../datasourcewithconfigvalidators.go | 14 +- .../datasourcewithvalidateconfig.go | 14 +- internal/testing/testprovider/provider.go | 29 +-- .../testprovider/providerconfigvalidator.go | 18 +- .../providerwithconfigvalidators.go | 14 +- .../testing/testprovider/providerwithmeta.go | 15 +- .../providerwithvalidateconfig.go | 14 +- internal/testing/testprovider/resource.go | 30 +-- .../testprovider/resourceconfigvalidator.go | 16 +- internal/testing/testprovider/resourcetype.go | 14 +- .../resourcewithconfigvalidators.go | 14 +- .../testprovider/resourcewithimportstate.go | 14 +- .../testprovider/resourcewithmodifyplan.go | 14 +- .../testprovider/resourcewithupgradestate.go | 14 +- .../resourcewithvalidateconfig.go | 14 +- internal/toproto5/configureprovider.go | 4 +- internal/toproto5/configureprovider_test.go | 8 +- internal/toproto6/configureprovider.go | 4 +- internal/toproto6/configureprovider_test.go | 8 +- provider/config_validator.go | 25 +++ provider/configure.go | 35 +++ provider/data_source_type.go | 20 ++ provider/doc.go | 3 + {tfsdk => provider}/provider.go | 44 +++- provider/resource_type.go | 20 ++ provider/validate_config.go | 30 +++ providerserver/providerserver.go | 12 +- resource/config_validator.go | 25 +++ resource/create.go | 40 ++++ resource/delete.go | 34 +++ resource/doc.go | 3 + resource/import_state.go | 53 +++++ resource/modify_plan.go | 48 ++++ resource/read.go | 35 +++ resource/resource.go | 134 +++++++++++ resource/state_upgrader.go | 37 +++ resource/update.go | 44 ++++ resource/upgrade_state.go | 71 ++++++ resource/validate_config.go | 30 +++ tfsdk/data_source.go | 28 --- tfsdk/data_source_validation.go | 58 ----- tfsdk/doc.go | 3 +- tfsdk/provider_validation.go | 57 ----- tfsdk/request.go | 122 ---------- tfsdk/request_import.go | 14 -- tfsdk/request_validation.go | 40 ---- tfsdk/resource.go | 78 ------- tfsdk/resource_import.go | 38 ---- tfsdk/resource_upgrade_state.go | 130 ----------- tfsdk/resource_validation.go | 57 ----- tfsdk/response.go | 117 ---------- tfsdk/response_import.go | 21 -- tfsdk/response_validation.go | 38 ---- .../plugin/framework/accessing-values.mdx | 13 +- website/docs/plugin/framework/acctests.mdx | 6 +- .../docs/plugin/framework/data-sources.mdx | 20 +- website/docs/plugin/framework/diagnostics.mdx | 8 +- website/docs/plugin/framework/providers.mdx | 32 +-- .../plugin/framework/resources/import.mdx | 20 +- .../docs/plugin/framework/resources/index.mdx | 28 +-- .../framework/resources/plan-modification.mdx | 8 +- .../framework/resources/state-upgrade.mdx | 54 ++--- website/docs/plugin/framework/validation.mdx | 42 ++-- .../docs/plugin/framework/writing-state.mdx | 17 +- 162 files changed, 2263 insertions(+), 2060 deletions(-) create mode 100644 .changelog/pending.txt create mode 100644 datasource/config_validator.go create mode 100644 datasource/data_source.go create mode 100644 datasource/doc.go create mode 100644 datasource/read.go create mode 100644 datasource/validate_config.go create mode 100644 provider/config_validator.go create mode 100644 provider/configure.go create mode 100644 provider/data_source_type.go create mode 100644 provider/doc.go rename {tfsdk => provider}/provider.go (52%) create mode 100644 provider/resource_type.go create mode 100644 provider/validate_config.go create mode 100644 resource/config_validator.go create mode 100644 resource/create.go create mode 100644 resource/delete.go create mode 100644 resource/doc.go create mode 100644 resource/import_state.go create mode 100644 resource/modify_plan.go create mode 100644 resource/read.go create mode 100644 resource/resource.go create mode 100644 resource/state_upgrader.go create mode 100644 resource/update.go create mode 100644 resource/upgrade_state.go create mode 100644 resource/validate_config.go delete mode 100644 tfsdk/data_source.go delete mode 100644 tfsdk/data_source_validation.go delete mode 100644 tfsdk/provider_validation.go delete mode 100644 tfsdk/request.go delete mode 100644 tfsdk/request_import.go delete mode 100644 tfsdk/request_validation.go delete mode 100644 tfsdk/resource.go delete mode 100644 tfsdk/resource_import.go delete mode 100644 tfsdk/resource_upgrade_state.go delete mode 100644 tfsdk/resource_validation.go delete mode 100644 tfsdk/response.go delete mode 100644 tfsdk/response_import.go delete mode 100644 tfsdk/response_validation.go diff --git a/.changelog/pending.txt b/.changelog/pending.txt new file mode 100644 index 000000000..e9bb08174 --- /dev/null +++ b/.changelog/pending.txt @@ -0,0 +1,27 @@ +```release-note:feature +datasource: New package, which colocates all data source implementation types from the `tfsdk` package +``` + +```release-note:feature +provider: New package, which colocates all provider implementation types from the `tfsdk` package +``` + +```release-note:feature +resource: New package, which colocates all resource implementation types from the `tfsdk` package +``` + +```release-note:breaking-change +tfsdk: Go types relating to data source handling have been migrated to the new `datasource` package. Consult the pull request description for a full listing of find-and-replace information. +``` + +```release-note:breaking-change +tfsdk: Go types relating to provider handling have been migrated to the new `provider` package. Consult the pull request description for a full listing of find-and-replace information. +``` + +```release-note:breaking-change +tfsdk: Go types relating to resource handling have been migrated to the new `resource` package. Consult the pull request description for a full listing of find-and-replace information. +``` + +```release-note:breaking-change +tfsdk: The `ResourceImportStatePassthroughID()` function has been moved to `resource.ImportStatePassthroughID()`. +``` diff --git a/README.md b/README.md index 22812971a..1ccac30e6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Currently, that means Go **1.17** or later must be used when including this proj Documentation for terraform-plugin-framework is still in development. In the meantime, the [GoDoc](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework) is the best source of documentation. -The [`tfsdk.Provider`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Provider) type is the root of your provider implementation. From there, [`tfsdk.ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceType) and [`tfsdk.DataSourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceType) implementations define the [schema](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/schema#Schema) of your resources and data sources, and how to create [`tfsdk.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Resource) and [`tfsdk.DataSource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSource) implementations that talk to the API. +The [`provider.Provider`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#Provider) type is the root of your provider implementation. From there, [`provider.ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ResourceType) and [`provider.DataSourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#DataSourceType) implementations define the [schema](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Schema) of your resources and data sources, and how to create [`resource.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#Resource) and [`datasource.DataSource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#DataSource) implementations that talk to the API. ## Contributing diff --git a/datasource/config_validator.go b/datasource/config_validator.go new file mode 100644 index 000000000..33918cbf9 --- /dev/null +++ b/datasource/config_validator.go @@ -0,0 +1,25 @@ +package datasource + +import "context" + +// ConfigValidator describes reusable data source configuration validation functionality. +type ConfigValidator interface { + // Description describes the validation in plain text formatting. + // + // This information may be automatically added to data source plain text + // descriptions by external tooling. + Description(context.Context) string + + // MarkdownDescription describes the validation in Markdown formatting. + // + // This information may be automatically added to data source Markdown + // descriptions by external tooling. + MarkdownDescription(context.Context) string + + // ValidateDataSource performs the validation. + // + // This method name is separate from the provider.ConfigValidator + // interface ValidateProvider method name and resource.ConfigValidator + // interface ValidateResource method name to allow generic validators. + ValidateDataSource(context.Context, ValidateConfigRequest, *ValidateConfigResponse) +} diff --git a/datasource/data_source.go b/datasource/data_source.go new file mode 100644 index 000000000..7101957bc --- /dev/null +++ b/datasource/data_source.go @@ -0,0 +1,43 @@ +package datasource + +import "context" + +// DataSource represents a data source instance. This is the core interface that +// all data sources must implement. +type DataSource interface { + // Read is called when the provider must read data source values in + // order to update state. Config values should be read from the + // ReadRequest and new state values set on the ReadResponse. + Read(context.Context, ReadRequest, *ReadResponse) +} + +// DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations. +// +// Declaring validation using this methodology simplifies implmentation of +// reusable functionality. These also include descriptions, which can be used +// for automating documentation. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type DataSourceWithConfigValidators interface { + DataSource + + // ConfigValidators returns a list of ConfigValidators. Each ConfigValidator's Validate method will be called when validating the data source. + ConfigValidators(context.Context) []ConfigValidator +} + +// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation. +// +// Declaring validation using this methodology simplifies one-off +// functionality that typically applies to a single data source. Any +// documentation of this functionality must be manually added into schema +// descriptions. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type DataSourceWithValidateConfig interface { + DataSource + + // ValidateConfig performs the validation. + ValidateConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse) +} diff --git a/datasource/doc.go b/datasource/doc.go new file mode 100644 index 000000000..9276adf4e --- /dev/null +++ b/datasource/doc.go @@ -0,0 +1,3 @@ +// Package datasource contains all interfaces, request types, and response +// types for a data source implementation. +package datasource diff --git a/datasource/read.go b/datasource/read.go new file mode 100644 index 000000000..30b67ce3e --- /dev/null +++ b/datasource/read.go @@ -0,0 +1,37 @@ +package datasource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ReadRequest represents a request for the provider to read a data +// source, i.e., update values in state according to the real state of the +// data source. An instance of this request struct is supplied as an argument +// to the data source's Read function. +type ReadRequest struct { + // Config is the configuration the user supplied for the data source. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// ReadResponse represents a response to a ReadRequest. An +// instance of this response struct is supplied as an argument to the data +// source's Read function, in which the provider should set values on the +// ReadResponse as appropriate. +type ReadResponse struct { + // State is the state of the data source following the Read operation. + // This field should be set during the resource's Read operation. + State tfsdk.State + + // Diagnostics report errors or warnings related to reading the data + // source. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/datasource/validate_config.go b/datasource/validate_config.go new file mode 100644 index 000000000..d01936ad4 --- /dev/null +++ b/datasource/validate_config.go @@ -0,0 +1,30 @@ +package datasource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ValidateConfigRequest represents a request to validate the +// configuration of a data source. An instance of this request struct is +// supplied as an argument to the DataSource ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigRequest struct { + // Config is the configuration the user supplied for the data source. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config +} + +// ValidateConfigResponse represents a response to a +// ValidateConfigRequest. An instance of this response struct is +// supplied as an argument to the DataSource ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigResponse struct { + // Diagnostics report errors or warnings related to validating the data + // source configuration. An empty slice indicates success, with no warnings + // or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/internal/fromproto5/applyresourcechange.go b/internal/fromproto5/applyresourcechange.go index d6c2d188a..cdbc7f82a 100644 --- a/internal/fromproto5/applyresourcechange.go +++ b/internal/fromproto5/applyresourcechange.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ApplyResourceChangeRequest returns the *fwserver.ApplyResourceChangeRequest // equivalent of a *tfprotov5.ApplyResourceChangeRequest. -func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyResourceChangeRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) { +func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyResourceChangeRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/applyresourcechange_test.go b/internal/fromproto5/applyresourcechange_test.go index 049aa3196..1bf7e4aa2 100644 --- a/internal/fromproto5/applyresourcechange_test.go +++ b/internal/fromproto5/applyresourcechange_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestApplyResourceChangeRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ApplyResourceChangeRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ApplyResourceChangeRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto5/configureprovider.go b/internal/fromproto5/configureprovider.go index 8771a4f3e..5e4f021a4 100644 --- a/internal/fromproto5/configureprovider.go +++ b/internal/fromproto5/configureprovider.go @@ -4,18 +4,19 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ConfigureProviderRequest returns the *fwserver.ConfigureProviderRequest // equivalent of a *tfprotov5.ConfigureProviderRequest. -func ConfigureProviderRequest(ctx context.Context, proto5 *tfprotov5.ConfigureProviderRequest, providerSchema *tfsdk.Schema) (*tfsdk.ConfigureProviderRequest, diag.Diagnostics) { +func ConfigureProviderRequest(ctx context.Context, proto5 *tfprotov5.ConfigureProviderRequest, providerSchema *tfsdk.Schema) (*provider.ConfigureRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } - fw := &tfsdk.ConfigureProviderRequest{ + fw := &provider.ConfigureRequest{ TerraformVersion: proto5.TerraformVersion, } diff --git a/internal/fromproto5/configureprovider_test.go b/internal/fromproto5/configureprovider_test.go index 50f091429..a7d640cc5 100644 --- a/internal/fromproto5/configureprovider_test.go +++ b/internal/fromproto5/configureprovider_test.go @@ -7,6 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" + "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/tfprotov5" @@ -44,7 +45,7 @@ func TestConfigureProviderRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ConfigureProviderRequest providerSchema *tfsdk.Schema - expected *tfsdk.ConfigureProviderRequest + expected *provider.ConfigureRequest expectedDiagnostics diag.Diagnostics }{ "nil": { @@ -53,13 +54,13 @@ func TestConfigureProviderRequest(t *testing.T) { }, "empty": { input: &tfprotov5.ConfigureProviderRequest{}, - expected: &tfsdk.ConfigureProviderRequest{}, + expected: &provider.ConfigureRequest{}, }, "config-missing-schema": { input: &tfprotov5.ConfigureProviderRequest{ Config: &testProto5DynamicValue, }, - expected: &tfsdk.ConfigureProviderRequest{}, + expected: &provider.ConfigureRequest{}, expectedDiagnostics: diag.Diagnostics{ diag.NewErrorDiagnostic( "Unable to Convert Configuration", @@ -75,7 +76,7 @@ func TestConfigureProviderRequest(t *testing.T) { Config: &testProto5DynamicValue, }, providerSchema: testFwSchema, - expected: &tfsdk.ConfigureProviderRequest{ + expected: &provider.ConfigureRequest{ Config: tfsdk.Config{ Raw: testProto5Value, Schema: *testFwSchema, @@ -86,7 +87,7 @@ func TestConfigureProviderRequest(t *testing.T) { input: &tfprotov5.ConfigureProviderRequest{ TerraformVersion: "99.99.99", }, - expected: &tfsdk.ConfigureProviderRequest{ + expected: &provider.ConfigureRequest{ TerraformVersion: "99.99.99", }, }, diff --git a/internal/fromproto5/importresourcestate.go b/internal/fromproto5/importresourcestate.go index 4f6813cc0..6ce49a7bc 100644 --- a/internal/fromproto5/importresourcestate.go +++ b/internal/fromproto5/importresourcestate.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -12,7 +13,7 @@ import ( // ImportResourceStateRequest returns the *fwserver.ImportResourceStateRequest // equivalent of a *tfprotov5.ImportResourceStateRequest. -func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportResourceStateRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) { +func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportResourceStateRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/importresourcestate_test.go b/internal/fromproto5/importresourcestate_test.go index 56c234cc8..588fc1a7a 100644 --- a/internal/fromproto5/importresourcestate_test.go +++ b/internal/fromproto5/importresourcestate_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -34,7 +35,7 @@ func TestImportResourceStateRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ImportResourceStateRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.ImportResourceStateRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto5/planresourcechange.go b/internal/fromproto5/planresourcechange.go index 59e075688..430f73b56 100644 --- a/internal/fromproto5/planresourcechange.go +++ b/internal/fromproto5/planresourcechange.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // PlanResourceChangeRequest returns the *fwserver.PlanResourceChangeRequest // equivalent of a *tfprotov5.PlanResourceChangeRequest. -func PlanResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.PlanResourceChangeRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) { +func PlanResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.PlanResourceChangeRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/planresourcechange_test.go b/internal/fromproto5/planresourcechange_test.go index 842ac4def..fcc4878f5 100644 --- a/internal/fromproto5/planresourcechange_test.go +++ b/internal/fromproto5/planresourcechange_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestPlanResourceChangeRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.PlanResourceChangeRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.PlanResourceChangeRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto5/readdatasource.go b/internal/fromproto5/readdatasource.go index c66cc8991..6ce9df076 100644 --- a/internal/fromproto5/readdatasource.go +++ b/internal/fromproto5/readdatasource.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ReadDataSourceRequest returns the *fwserver.ReadDataSourceRequest // equivalent of a *tfprotov5.ReadDataSourceRequest. -func ReadDataSourceRequest(ctx context.Context, proto5 *tfprotov5.ReadDataSourceRequest, dataSourceType tfsdk.DataSourceType, dataSourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) { +func ReadDataSourceRequest(ctx context.Context, proto5 *tfprotov5.ReadDataSourceRequest, dataSourceType provider.DataSourceType, dataSourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/readdatasource_test.go b/internal/fromproto5/readdatasource_test.go index 31351e9fc..9fbd51571 100644 --- a/internal/fromproto5/readdatasource_test.go +++ b/internal/fromproto5/readdatasource_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestReadDataSourceRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ReadDataSourceRequest dataSourceSchema *tfsdk.Schema - dataSourceType tfsdk.DataSourceType + dataSourceType provider.DataSourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ReadDataSourceRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto5/readresource.go b/internal/fromproto5/readresource.go index c9f565b09..44740871b 100644 --- a/internal/fromproto5/readresource.go +++ b/internal/fromproto5/readresource.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ReadResourceRequest returns the *fwserver.ReadResourceRequest // equivalent of a *tfprotov5.ReadResourceRequest. -func ReadResourceRequest(ctx context.Context, proto5 *tfprotov5.ReadResourceRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadResourceRequest, diag.Diagnostics) { +func ReadResourceRequest(ctx context.Context, proto5 *tfprotov5.ReadResourceRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadResourceRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/readresource_test.go b/internal/fromproto5/readresource_test.go index 922c27664..623795493 100644 --- a/internal/fromproto5/readresource_test.go +++ b/internal/fromproto5/readresource_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestReadResourceRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ReadResourceRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ReadResourceRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto5/upgraderesourcestate.go b/internal/fromproto5/upgraderesourcestate.go index ff8b23b7b..36283c876 100644 --- a/internal/fromproto5/upgraderesourcestate.go +++ b/internal/fromproto5/upgraderesourcestate.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -12,7 +13,7 @@ import ( // UpgradeResourceStateRequest returns the *fwserver.UpgradeResourceStateRequest // equivalent of a *tfprotov5.UpgradeResourceStateRequest. -func UpgradeResourceStateRequest(ctx context.Context, proto5 *tfprotov5.UpgradeResourceStateRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.UpgradeResourceStateRequest, diag.Diagnostics) { +func UpgradeResourceStateRequest(ctx context.Context, proto5 *tfprotov5.UpgradeResourceStateRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.UpgradeResourceStateRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/upgraderesourcestate_test.go b/internal/fromproto5/upgraderesourcestate_test.go index f3c163732..ccc4d8b26 100644 --- a/internal/fromproto5/upgraderesourcestate_test.go +++ b/internal/fromproto5/upgraderesourcestate_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -28,7 +29,7 @@ func TestUpgradeResourceStateRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.UpgradeResourceStateRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.UpgradeResourceStateRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto5/validatedatasourceconfig.go b/internal/fromproto5/validatedatasourceconfig.go index 8a3b13e83..746b84b31 100644 --- a/internal/fromproto5/validatedatasourceconfig.go +++ b/internal/fromproto5/validatedatasourceconfig.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ValidateDataSourceConfigRequest returns the *fwserver.ValidateDataSourceConfigRequest // equivalent of a *tfprotov5.ValidateDataSourceConfigRequest. -func ValidateDataSourceConfigRequest(ctx context.Context, proto5 *tfprotov5.ValidateDataSourceConfigRequest, dataSourceType tfsdk.DataSourceType, dataSourceSchema *tfsdk.Schema) (*fwserver.ValidateDataSourceConfigRequest, diag.Diagnostics) { +func ValidateDataSourceConfigRequest(ctx context.Context, proto5 *tfprotov5.ValidateDataSourceConfigRequest, dataSourceType provider.DataSourceType, dataSourceSchema *tfsdk.Schema) (*fwserver.ValidateDataSourceConfigRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/validatedatasourceconfig_test.go b/internal/fromproto5/validatedatasourceconfig_test.go index b5d3df9ca..72b3e29a5 100644 --- a/internal/fromproto5/validatedatasourceconfig_test.go +++ b/internal/fromproto5/validatedatasourceconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestValidateDataSourceConfigRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ValidateDataSourceConfigRequest dataSourceSchema *tfsdk.Schema - dataSourceType tfsdk.DataSourceType + dataSourceType provider.DataSourceType expected *fwserver.ValidateDataSourceConfigRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto5/validateresourcetypeconfig.go b/internal/fromproto5/validateresourcetypeconfig.go index cb20d2ab0..0d0a276f9 100644 --- a/internal/fromproto5/validateresourcetypeconfig.go +++ b/internal/fromproto5/validateresourcetypeconfig.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ValidateResourceTypeConfigRequest returns the *fwserver.ValidateResourceConfigRequest // equivalent of a *tfprotov5.ValidateResourceTypeConfigRequest. -func ValidateResourceTypeConfigRequest(ctx context.Context, proto5 *tfprotov5.ValidateResourceTypeConfigRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ValidateResourceConfigRequest, diag.Diagnostics) { +func ValidateResourceTypeConfigRequest(ctx context.Context, proto5 *tfprotov5.ValidateResourceTypeConfigRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ValidateResourceConfigRequest, diag.Diagnostics) { if proto5 == nil { return nil, nil } diff --git a/internal/fromproto5/validateresourcetypeconfig_test.go b/internal/fromproto5/validateresourcetypeconfig_test.go index f48865cec..8ff9c134f 100644 --- a/internal/fromproto5/validateresourcetypeconfig_test.go +++ b/internal/fromproto5/validateresourcetypeconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov5" @@ -45,7 +46,7 @@ func TestValidateResourceTypeConfigRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov5.ValidateResourceTypeConfigRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.ValidateResourceConfigRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto6/applyresourcechange.go b/internal/fromproto6/applyresourcechange.go index 609369210..678ce7bcf 100644 --- a/internal/fromproto6/applyresourcechange.go +++ b/internal/fromproto6/applyresourcechange.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ApplyResourceChangeRequest returns the *fwserver.ApplyResourceChangeRequest // equivalent of a *tfprotov6.ApplyResourceChangeRequest. -func ApplyResourceChangeRequest(ctx context.Context, proto6 *tfprotov6.ApplyResourceChangeRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) { +func ApplyResourceChangeRequest(ctx context.Context, proto6 *tfprotov6.ApplyResourceChangeRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/applyresourcechange_test.go b/internal/fromproto6/applyresourcechange_test.go index 93bbb4c47..fd65f10f5 100644 --- a/internal/fromproto6/applyresourcechange_test.go +++ b/internal/fromproto6/applyresourcechange_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestApplyResourceChangeRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ApplyResourceChangeRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ApplyResourceChangeRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto6/configureprovider.go b/internal/fromproto6/configureprovider.go index da579c018..032ec668f 100644 --- a/internal/fromproto6/configureprovider.go +++ b/internal/fromproto6/configureprovider.go @@ -4,18 +4,19 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ConfigureProviderRequest returns the *fwserver.ConfigureProviderRequest // equivalent of a *tfprotov6.ConfigureProviderRequest. -func ConfigureProviderRequest(ctx context.Context, proto6 *tfprotov6.ConfigureProviderRequest, providerSchema *tfsdk.Schema) (*tfsdk.ConfigureProviderRequest, diag.Diagnostics) { +func ConfigureProviderRequest(ctx context.Context, proto6 *tfprotov6.ConfigureProviderRequest, providerSchema *tfsdk.Schema) (*provider.ConfigureRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } - fw := &tfsdk.ConfigureProviderRequest{ + fw := &provider.ConfigureRequest{ TerraformVersion: proto6.TerraformVersion, } diff --git a/internal/fromproto6/configureprovider_test.go b/internal/fromproto6/configureprovider_test.go index 20d9466dc..5d58070d5 100644 --- a/internal/fromproto6/configureprovider_test.go +++ b/internal/fromproto6/configureprovider_test.go @@ -7,6 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" + "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/tfprotov6" @@ -44,7 +45,7 @@ func TestConfigureProviderRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ConfigureProviderRequest providerSchema *tfsdk.Schema - expected *tfsdk.ConfigureProviderRequest + expected *provider.ConfigureRequest expectedDiagnostics diag.Diagnostics }{ "nil": { @@ -53,13 +54,13 @@ func TestConfigureProviderRequest(t *testing.T) { }, "empty": { input: &tfprotov6.ConfigureProviderRequest{}, - expected: &tfsdk.ConfigureProviderRequest{}, + expected: &provider.ConfigureRequest{}, }, "config-missing-schema": { input: &tfprotov6.ConfigureProviderRequest{ Config: &testProto6DynamicValue, }, - expected: &tfsdk.ConfigureProviderRequest{}, + expected: &provider.ConfigureRequest{}, expectedDiagnostics: diag.Diagnostics{ diag.NewErrorDiagnostic( "Unable to Convert Configuration", @@ -75,7 +76,7 @@ func TestConfigureProviderRequest(t *testing.T) { Config: &testProto6DynamicValue, }, providerSchema: testFwSchema, - expected: &tfsdk.ConfigureProviderRequest{ + expected: &provider.ConfigureRequest{ Config: tfsdk.Config{ Raw: testProto6Value, Schema: *testFwSchema, @@ -86,7 +87,7 @@ func TestConfigureProviderRequest(t *testing.T) { input: &tfprotov6.ConfigureProviderRequest{ TerraformVersion: "99.99.99", }, - expected: &tfsdk.ConfigureProviderRequest{ + expected: &provider.ConfigureRequest{ TerraformVersion: "99.99.99", }, }, diff --git a/internal/fromproto6/importresourcestate.go b/internal/fromproto6/importresourcestate.go index 828b2dfb4..3d05bac58 100644 --- a/internal/fromproto6/importresourcestate.go +++ b/internal/fromproto6/importresourcestate.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -12,7 +13,7 @@ import ( // ImportResourceStateRequest returns the *fwserver.ImportResourceStateRequest // equivalent of a *tfprotov6.ImportResourceStateRequest. -func ImportResourceStateRequest(ctx context.Context, proto6 *tfprotov6.ImportResourceStateRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) { +func ImportResourceStateRequest(ctx context.Context, proto6 *tfprotov6.ImportResourceStateRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/importresourcestate_test.go b/internal/fromproto6/importresourcestate_test.go index b5dc4c791..75f9a9a7a 100644 --- a/internal/fromproto6/importresourcestate_test.go +++ b/internal/fromproto6/importresourcestate_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -34,7 +35,7 @@ func TestImportResourceStateRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ImportResourceStateRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.ImportResourceStateRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto6/planresourcechange.go b/internal/fromproto6/planresourcechange.go index 817b689cc..921e0f0c3 100644 --- a/internal/fromproto6/planresourcechange.go +++ b/internal/fromproto6/planresourcechange.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // PlanResourceChangeRequest returns the *fwserver.PlanResourceChangeRequest // equivalent of a *tfprotov6.PlanResourceChangeRequest. -func PlanResourceChangeRequest(ctx context.Context, proto6 *tfprotov6.PlanResourceChangeRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) { +func PlanResourceChangeRequest(ctx context.Context, proto6 *tfprotov6.PlanResourceChangeRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/planresourcechange_test.go b/internal/fromproto6/planresourcechange_test.go index c82514155..b0dad0982 100644 --- a/internal/fromproto6/planresourcechange_test.go +++ b/internal/fromproto6/planresourcechange_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestPlanResourceChangeRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.PlanResourceChangeRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.PlanResourceChangeRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto6/readdatasource.go b/internal/fromproto6/readdatasource.go index 4335d11d1..206ca759b 100644 --- a/internal/fromproto6/readdatasource.go +++ b/internal/fromproto6/readdatasource.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ReadDataSourceRequest returns the *fwserver.ReadDataSourceRequest // equivalent of a *tfprotov6.ReadDataSourceRequest. -func ReadDataSourceRequest(ctx context.Context, proto6 *tfprotov6.ReadDataSourceRequest, dataSourceType tfsdk.DataSourceType, dataSourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) { +func ReadDataSourceRequest(ctx context.Context, proto6 *tfprotov6.ReadDataSourceRequest, dataSourceType provider.DataSourceType, dataSourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/readdatasource_test.go b/internal/fromproto6/readdatasource_test.go index dae500ff9..b18a022b0 100644 --- a/internal/fromproto6/readdatasource_test.go +++ b/internal/fromproto6/readdatasource_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestReadDataSourceRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ReadDataSourceRequest dataSourceSchema *tfsdk.Schema - dataSourceType tfsdk.DataSourceType + dataSourceType provider.DataSourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ReadDataSourceRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto6/readresource.go b/internal/fromproto6/readresource.go index 63c6e8c16..1a81f6272 100644 --- a/internal/fromproto6/readresource.go +++ b/internal/fromproto6/readresource.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ReadResourceRequest returns the *fwserver.ReadResourceRequest // equivalent of a *tfprotov6.ReadResourceRequest. -func ReadResourceRequest(ctx context.Context, proto6 *tfprotov6.ReadResourceRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadResourceRequest, diag.Diagnostics) { +func ReadResourceRequest(ctx context.Context, proto6 *tfprotov6.ReadResourceRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadResourceRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/readresource_test.go b/internal/fromproto6/readresource_test.go index 2f77566dc..7bc9ddf7d 100644 --- a/internal/fromproto6/readresource_test.go +++ b/internal/fromproto6/readresource_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestReadResourceRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ReadResourceRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType providerMetaSchema *tfsdk.Schema expected *fwserver.ReadResourceRequest expectedDiagnostics diag.Diagnostics diff --git a/internal/fromproto6/upgraderesourcestate.go b/internal/fromproto6/upgraderesourcestate.go index e37cdbfb6..22d328fb3 100644 --- a/internal/fromproto6/upgraderesourcestate.go +++ b/internal/fromproto6/upgraderesourcestate.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // UpgradeResourceStateRequest returns the *fwserver.UpgradeResourceStateRequest // equivalent of a *tfprotov6.UpgradeResourceStateRequest. -func UpgradeResourceStateRequest(ctx context.Context, proto6 *tfprotov6.UpgradeResourceStateRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.UpgradeResourceStateRequest, diag.Diagnostics) { +func UpgradeResourceStateRequest(ctx context.Context, proto6 *tfprotov6.UpgradeResourceStateRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.UpgradeResourceStateRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/upgraderesourcestate_test.go b/internal/fromproto6/upgraderesourcestate_test.go index 9c54a1194..ea880987a 100644 --- a/internal/fromproto6/upgraderesourcestate_test.go +++ b/internal/fromproto6/upgraderesourcestate_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -28,7 +29,7 @@ func TestUpgradeResourceStateRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.UpgradeResourceStateRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.UpgradeResourceStateRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto6/validatedatasourceconfig.go b/internal/fromproto6/validatedatasourceconfig.go index ae8503b67..6b2edbaa6 100644 --- a/internal/fromproto6/validatedatasourceconfig.go +++ b/internal/fromproto6/validatedatasourceconfig.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ValidateDataSourceConfigRequest returns the *fwserver.ValidateDataSourceConfigRequest // equivalent of a *tfprotov6.ValidateDataSourceConfigRequest. -func ValidateDataSourceConfigRequest(ctx context.Context, proto6 *tfprotov6.ValidateDataResourceConfigRequest, dataSourceType tfsdk.DataSourceType, dataSourceSchema *tfsdk.Schema) (*fwserver.ValidateDataSourceConfigRequest, diag.Diagnostics) { +func ValidateDataSourceConfigRequest(ctx context.Context, proto6 *tfprotov6.ValidateDataResourceConfigRequest, dataSourceType provider.DataSourceType, dataSourceSchema *tfsdk.Schema) (*fwserver.ValidateDataSourceConfigRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/validatedatasourceconfig_test.go b/internal/fromproto6/validatedatasourceconfig_test.go index e70742c92..6c514ccba 100644 --- a/internal/fromproto6/validatedatasourceconfig_test.go +++ b/internal/fromproto6/validatedatasourceconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestValidateDataSourceConfigRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ValidateDataResourceConfigRequest dataSourceSchema *tfsdk.Schema - dataSourceType tfsdk.DataSourceType + dataSourceType provider.DataSourceType expected *fwserver.ValidateDataSourceConfigRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fromproto6/validateresourceconfig.go b/internal/fromproto6/validateresourceconfig.go index a7dab2ac6..a3bc39b32 100644 --- a/internal/fromproto6/validateresourceconfig.go +++ b/internal/fromproto6/validateresourceconfig.go @@ -5,13 +5,14 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ValidateResourceConfigRequest returns the *fwserver.ValidateResourceConfigRequest // equivalent of a *tfprotov6.ValidateResourceConfigRequest. -func ValidateResourceConfigRequest(ctx context.Context, proto6 *tfprotov6.ValidateResourceConfigRequest, resourceType tfsdk.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ValidateResourceConfigRequest, diag.Diagnostics) { +func ValidateResourceConfigRequest(ctx context.Context, proto6 *tfprotov6.ValidateResourceConfigRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema) (*fwserver.ValidateResourceConfigRequest, diag.Diagnostics) { if proto6 == nil { return nil, nil } diff --git a/internal/fromproto6/validateresourceconfig_test.go b/internal/fromproto6/validateresourceconfig_test.go index 1ac6816da..befeed53c 100644 --- a/internal/fromproto6/validateresourceconfig_test.go +++ b/internal/fromproto6/validateresourceconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" + "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/tfprotov6" @@ -45,7 +46,7 @@ func TestValidateResourceConfigRequest(t *testing.T) { testCases := map[string]struct { input *tfprotov6.ValidateResourceConfigRequest resourceSchema *tfsdk.Schema - resourceType tfsdk.ResourceType + resourceType provider.ResourceType expected *fwserver.ValidateResourceConfigRequest expectedDiagnostics diag.Diagnostics }{ diff --git a/internal/fwserver/server.go b/internal/fwserver/server.go index dca718a16..03ea0c99f 100644 --- a/internal/fwserver/server.go +++ b/internal/fwserver/server.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -14,7 +15,7 @@ import ( // implementations wrap this handling along with calling all request and // response type conversions. type Server struct { - Provider tfsdk.Provider + Provider provider.Provider // dataSourceSchemas is the cached DataSource Schemas for RPCs that need to // convert configuration data from the protocol. If not found, it will be @@ -33,7 +34,7 @@ type Server struct { // dataSourceTypes is the cached DataSourceTypes for RPCs that need to // access data sources. If not found, it will be fetched from the // Provider.GetDataSources() method. - dataSourceTypes map[string]tfsdk.DataSourceType + dataSourceTypes map[string]provider.DataSourceType // dataSourceTypesDiags is the cached Diagnostics obtained while populating // dataSourceTypes. This is to ensure any warnings or errors are also @@ -89,7 +90,7 @@ type Server struct { // resourceTypes is the cached ResourceTypes for RPCs that need to // access resources. If not found, it will be fetched from the // Provider.GetResources() method. - resourceTypes map[string]tfsdk.ResourceType + resourceTypes map[string]provider.ResourceType // resourceTypesDiags is the cached Diagnostics obtained while populating // resourceTypes. This is to ensure any warnings or errors are also @@ -161,7 +162,7 @@ func (s *Server) DataSourceSchemas(ctx context.Context) (map[string]*tfsdk.Schem } // DataSourceType returns the DataSourceType for a given type name. -func (s *Server) DataSourceType(ctx context.Context, typeName string) (tfsdk.DataSourceType, diag.Diagnostics) { +func (s *Server) DataSourceType(ctx context.Context, typeName string) (provider.DataSourceType, diag.Diagnostics) { dataSourceTypes, diags := s.DataSourceTypes(ctx) dataSourceType, ok := dataSourceTypes[typeName] @@ -180,7 +181,7 @@ func (s *Server) DataSourceType(ctx context.Context, typeName string) (tfsdk.Dat // DataSourceTypes returns the map of DataSourceTypes. The results are cached // on first use. -func (s *Server) DataSourceTypes(ctx context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { +func (s *Server) DataSourceTypes(ctx context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { logging.FrameworkTrace(ctx, "Checking DataSourceTypes lock") s.dataSourceTypesMutex.Lock() defer s.dataSourceTypesMutex.Unlock() @@ -218,16 +219,16 @@ func (s *Server) ProviderSchema(ctx context.Context) (*tfsdk.Schema, diag.Diagno } // ProviderMetaSchema returns the Meta Schema associated with the Provider, if -// it implements the ProviderWithProviderMeta interface. The Schema and +// it implements the ProviderWithMetaSchema interface. The Schema and // Diagnostics are cached on first use. func (s *Server) ProviderMetaSchema(ctx context.Context) (*tfsdk.Schema, diag.Diagnostics) { - providerWithProviderMeta, ok := s.Provider.(tfsdk.ProviderWithProviderMeta) + providerWithProviderMeta, ok := s.Provider.(provider.ProviderWithMetaSchema) if !ok { return nil, nil } - logging.FrameworkTrace(ctx, "Provider implements ProviderWithProviderMeta") + logging.FrameworkTrace(ctx, "Provider implements ProviderWithMetaSchema") logging.FrameworkTrace(ctx, "Checking ProviderMetaSchema lock") s.providerMetaSchemaMutex.Lock() defer s.providerMetaSchemaMutex.Unlock() @@ -306,7 +307,7 @@ func (s *Server) ResourceSchemas(ctx context.Context) (map[string]*tfsdk.Schema, } // ResourceType returns the ResourceType for a given type name. -func (s *Server) ResourceType(ctx context.Context, typeName string) (tfsdk.ResourceType, diag.Diagnostics) { +func (s *Server) ResourceType(ctx context.Context, typeName string) (provider.ResourceType, diag.Diagnostics) { resourceTypes, diags := s.ResourceTypes(ctx) resourceType, ok := resourceTypes[typeName] @@ -325,7 +326,7 @@ func (s *Server) ResourceType(ctx context.Context, typeName string) (tfsdk.Resou // ResourceTypes returns the map of ResourceTypes. The results are cached // on first use. -func (s *Server) ResourceTypes(ctx context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { +func (s *Server) ResourceTypes(ctx context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { logging.FrameworkTrace(ctx, "Checking ResourceTypes lock") s.resourceTypesMutex.Lock() defer s.resourceTypesMutex.Unlock() diff --git a/internal/fwserver/server_applyresourcechange.go b/internal/fwserver/server_applyresourcechange.go index ed6cb5659..23e8dda3d 100644 --- a/internal/fwserver/server_applyresourcechange.go +++ b/internal/fwserver/server_applyresourcechange.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -17,7 +18,7 @@ type ApplyResourceChangeRequest struct { PriorState *tfsdk.State ProviderMeta *tfsdk.Config ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // ApplyResourceChangeResponse is the framework server response for the diff --git a/internal/fwserver/server_applyresourcechange_test.go b/internal/fwserver/server_applyresourcechange_test.go index c5bfe4e58..1f3e5a02f 100644 --- a/internal/fwserver/server_applyresourcechange_test.go +++ b/internal/fwserver/server_applyresourcechange_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -102,9 +104,9 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -116,10 +118,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -154,9 +156,9 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -168,10 +170,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -206,9 +208,9 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var metadata testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metadata)...) @@ -223,10 +225,10 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -255,16 +257,16 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -311,18 +313,18 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -364,15 +366,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Intentionally missing resp.State.Set() }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -410,12 +412,12 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -424,7 +426,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("unexpected req.State value: %s", data.TestRequired.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -453,12 +455,12 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -467,7 +469,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("unexpected req.ProviderMeta value: %s", data.TestProviderMetaAttribute.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -497,16 +499,16 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -551,15 +553,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // Intentionally empty, should call resp.State.RemoveResource() automatically. }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -601,15 +603,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -664,15 +666,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -727,15 +729,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -791,15 +793,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -854,15 +856,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -921,15 +923,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -980,15 +982,15 @@ func TestServerApplyResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/fwserver/server_configureprovider.go b/internal/fwserver/server_configureprovider.go index 6cadc486b..07d526561 100644 --- a/internal/fwserver/server_configureprovider.go +++ b/internal/fwserver/server_configureprovider.go @@ -4,17 +4,17 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/internal/logging" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" ) // ConfigureProvider implements the framework server ConfigureProvider RPC. -func (s *Server) ConfigureProvider(ctx context.Context, req *tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { +func (s *Server) ConfigureProvider(ctx context.Context, req *provider.ConfigureRequest, resp *provider.ConfigureResponse) { logging.FrameworkDebug(ctx, "Calling provider defined Provider Configure") if req != nil { s.Provider.Configure(ctx, *req, resp) } else { - s.Provider.Configure(ctx, tfsdk.ConfigureProviderRequest{}, resp) + s.Provider.Configure(ctx, provider.ConfigureRequest{}, resp) } logging.FrameworkDebug(ctx, "Called provider defined Provider Configure") diff --git a/internal/fwserver/server_configureprovider_test.go b/internal/fwserver/server_configureprovider_test.go index 4d3c2ea44..445e3c528 100644 --- a/internal/fwserver/server_configureprovider_test.go +++ b/internal/fwserver/server_configureprovider_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "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" @@ -43,14 +44,14 @@ func TestServerConfigureProvider(t *testing.T) { testCases := map[string]struct { server *fwserver.Server - request *tfsdk.ConfigureProviderRequest - expectedResponse *tfsdk.ConfigureProviderResponse + request *provider.ConfigureRequest + expectedResponse *provider.ConfigureResponse }{ "empty-provider": { server: &fwserver.Server{ Provider: &testprovider.Provider{}, }, - expectedResponse: &tfsdk.ConfigureProviderResponse{}, + expectedResponse: &provider.ConfigureResponse{}, }, "request-config": { server: &fwserver.Server{ @@ -58,7 +59,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -73,10 +74,10 @@ func TestServerConfigureProvider(t *testing.T) { }, }, }, - request: &tfsdk.ConfigureProviderRequest{ + request: &provider.ConfigureRequest{ Config: testConfig, }, - expectedResponse: &tfsdk.ConfigureProviderResponse{}, + expectedResponse: &provider.ConfigureResponse{}, }, "request-terraformversion": { server: &fwserver.Server{ @@ -84,17 +85,17 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { if req.TerraformVersion != "1.0.0" { resp.Diagnostics.AddError("Incorrect req.TerraformVersion", "expected 1.0.0, got "+req.TerraformVersion) } }, }, }, - request: &tfsdk.ConfigureProviderRequest{ + request: &provider.ConfigureRequest{ TerraformVersion: "1.0.0", }, - expectedResponse: &tfsdk.ConfigureProviderResponse{}, + expectedResponse: &provider.ConfigureResponse{}, }, "response-diagnostics": { server: &fwserver.Server{ @@ -102,14 +103,14 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, }, }, - request: &tfsdk.ConfigureProviderRequest{}, - expectedResponse: &tfsdk.ConfigureProviderResponse{ + request: &provider.ConfigureRequest{}, + expectedResponse: &provider.ConfigureResponse{ Diagnostics: diag.Diagnostics{ diag.NewWarningDiagnostic( "warning summary", @@ -130,7 +131,7 @@ func TestServerConfigureProvider(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - response := &tfsdk.ConfigureProviderResponse{} + response := &provider.ConfigureResponse{} testCase.server.ConfigureProvider(context.Background(), testCase.request, response) if diff := cmp.Diff(response, testCase.expectedResponse); diff != "" { diff --git a/internal/fwserver/server_createresource.go b/internal/fwserver/server_createresource.go index b1873748a..0eafe4521 100644 --- a/internal/fwserver/server_createresource.go +++ b/internal/fwserver/server_createresource.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" ) @@ -17,7 +19,7 @@ type CreateResourceRequest struct { PlannedState *tfsdk.Plan ProviderMeta *tfsdk.Config ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // CreateResourceResponse is the framework server response for a create request @@ -37,7 +39,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest, // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -48,7 +50,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest, nullSchemaData := tftypes.NewValue(req.ResourceSchema.TerraformType(ctx), nil) - createReq := tfsdk.CreateResourceRequest{ + createReq := resource.CreateRequest{ Config: tfsdk.Config{ Schema: req.ResourceSchema, Raw: nullSchemaData, @@ -58,7 +60,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest, Raw: nullSchemaData, }, } - createResp := tfsdk.CreateResourceResponse{ + createResp := resource.CreateResponse{ State: tfsdk.State{ Schema: req.ResourceSchema, Raw: nullSchemaData, @@ -78,7 +80,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest, } logging.FrameworkDebug(ctx, "Calling provider defined Resource Create") - resource.Create(ctx, createReq, &createResp) + resourceImpl.Create(ctx, createReq, &createResp) logging.FrameworkDebug(ctx, "Called provider defined Resource Create") resp.Diagnostics = createResp.Diagnostics @@ -90,7 +92,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest, "The resource may have been successfully created, but Terraform is not tracking it. " + "Applying the configuration again with no other action may result in duplicate resource errors." - if _, ok := resource.(tfsdk.ResourceWithImportState); ok { + if _, ok := resourceImpl.(resource.ResourceWithImportState); ok { detail += " Import the resource if the resource was actually created and Terraform should be tracking it." } diff --git a/internal/fwserver/server_createresource_test.go b/internal/fwserver/server_createresource_test.go index e3eff34d3..62c48125f 100644 --- a/internal/fwserver/server_createresource_test.go +++ b/internal/fwserver/server_createresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -96,9 +98,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -141,9 +143,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -186,9 +188,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var metadata testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metadata)...) @@ -228,9 +230,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -270,9 +272,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -309,9 +311,9 @@ func TestServerCreateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Intentionally missing resp.State.Set() }, }, nil diff --git a/internal/fwserver/server_deleteresource.go b/internal/fwserver/server_deleteresource.go index 91e16ad12..29b92a065 100644 --- a/internal/fwserver/server_deleteresource.go +++ b/internal/fwserver/server_deleteresource.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" ) @@ -16,7 +18,7 @@ type DeleteResourceRequest struct { PriorState *tfsdk.State ProviderMeta *tfsdk.Config ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // DeleteResourceResponse is the framework server response for a delete request @@ -36,7 +38,7 @@ func (s *Server) DeleteResource(ctx context.Context, req *DeleteResourceRequest, // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -45,13 +47,13 @@ func (s *Server) DeleteResource(ctx context.Context, req *DeleteResourceRequest, return } - deleteReq := tfsdk.DeleteResourceRequest{ + deleteReq := resource.DeleteRequest{ State: tfsdk.State{ Schema: req.ResourceSchema, Raw: tftypes.NewValue(req.ResourceSchema.TerraformType(ctx), nil), }, } - deleteResp := tfsdk.DeleteResourceResponse{ + deleteResp := resource.DeleteResponse{ State: tfsdk.State{ Schema: req.ResourceSchema, Raw: tftypes.NewValue(req.ResourceSchema.TerraformType(ctx), nil), @@ -68,7 +70,7 @@ func (s *Server) DeleteResource(ctx context.Context, req *DeleteResourceRequest, } logging.FrameworkDebug(ctx, "Calling provider defined Resource Delete") - resource.Delete(ctx, deleteReq, &deleteResp) + resourceImpl.Delete(ctx, deleteReq, &deleteResp) logging.FrameworkDebug(ctx, "Called provider defined Resource Delete") if !deleteResp.Diagnostics.HasError() { diff --git a/internal/fwserver/server_deleteresource_test.go b/internal/fwserver/server_deleteresource_test.go index 208243550..7d4c5b4fa 100644 --- a/internal/fwserver/server_deleteresource_test.go +++ b/internal/fwserver/server_deleteresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -96,9 +98,9 @@ func TestServerDeleteResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -132,9 +134,9 @@ func TestServerDeleteResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -169,9 +171,9 @@ func TestServerDeleteResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -216,9 +218,9 @@ func TestServerDeleteResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // Intentionally empty, should call resp.State.RemoveResource() automatically. }, }, nil diff --git a/internal/fwserver/server_getproviderschema_test.go b/internal/fwserver/server_getproviderschema_test.go index 040dfb8e2..15357cc9f 100644 --- a/internal/fwserver/server_getproviderschema_test.go +++ b/internal/fwserver/server_getproviderschema_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -36,8 +37,8 @@ func TestServerGetProviderSchema(t *testing.T) { "datasourceschemas": { server: &fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source1": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -127,7 +128,7 @@ func TestServerGetProviderSchema(t *testing.T) { }, "providermeta": { server: &fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{}, GetMetaSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -162,8 +163,8 @@ func TestServerGetProviderSchema(t *testing.T) { "resourceschemas": { server: &fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource1": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ diff --git a/internal/fwserver/server_importresourcestate.go b/internal/fwserver/server_importresourcestate.go index 28bb8ba2a..6b6b2e8be 100644 --- a/internal/fwserver/server_importresourcestate.go +++ b/internal/fwserver/server_importresourcestate.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -19,7 +21,7 @@ type ImportedResource struct { // ImportResourceState RPC. type ImportResourceStateRequest struct { ID string - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType // EmptyState is an empty State for the resource schema. This is used to // initialize the ImportedResource State of the ImportResourceStateResponse @@ -47,7 +49,7 @@ func (s *Server) ImportResourceState(ctx context.Context, req *ImportResourceSta // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -56,7 +58,7 @@ func (s *Server) ImportResourceState(ctx context.Context, req *ImportResourceSta return } - resourceWithImportState, ok := resource.(tfsdk.ResourceWithImportState) + resourceWithImportState, ok := resourceImpl.(resource.ResourceWithImportState) if !ok { // If there is a feature request for customizing this messaging, @@ -76,10 +78,10 @@ func (s *Server) ImportResourceState(ctx context.Context, req *ImportResourceSta return } - importReq := tfsdk.ImportResourceStateRequest{ + importReq := resource.ImportStateRequest{ ID: req.ID, } - importResp := tfsdk.ImportResourceStateResponse{ + importResp := resource.ImportStateResponse{ State: tfsdk.State{ Raw: req.EmptyState.Raw.Copy(), Schema: req.EmptyState.Schema, diff --git a/internal/fwserver/server_importresourcestate_test.go b/internal/fwserver/server_importresourcestate_test.go index 1a0e67cf0..fa2c87779 100644 --- a/internal/fwserver/server_importresourcestate_test.go +++ b/internal/fwserver/server_importresourcestate_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -86,15 +88,15 @@ func TestServerImportResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { if req.ID != "test-id" { resp.Diagnostics.AddError("unexpected req.ID value: %s", req.ID) } - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, @@ -121,7 +123,7 @@ func TestServerImportResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -147,10 +149,10 @@ func TestServerImportResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -182,11 +184,11 @@ func TestServerImportResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, @@ -213,10 +215,10 @@ func TestServerImportResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { // Intentionally empty }, }, nil diff --git a/internal/fwserver/server_planresourcechange.go b/internal/fwserver/server_planresourcechange.go index bd320713f..121031802 100644 --- a/internal/fwserver/server_planresourcechange.go +++ b/internal/fwserver/server_planresourcechange.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" ) @@ -22,7 +24,7 @@ type PlanResourceChangeRequest struct { ProposedNewState *tfsdk.Plan ProviderMeta *tfsdk.Config ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // PlanResourceChangeResponse is the framework server response for the @@ -42,7 +44,7 @@ func (s *Server) PlanResourceChange(ctx context.Context, req *PlanResourceChange // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -189,10 +191,10 @@ func (s *Server) PlanResourceChange(ctx context.Context, req *PlanResourceChange // delete resources, e.g. to inform practitioners that the resource // _can't_ be deleted in the API and will just be removed from // Terraform's state - if resource, ok := resource.(tfsdk.ResourceWithModifyPlan); ok { + if resourceWithModifyPlan, ok := resourceImpl.(resource.ResourceWithModifyPlan); ok { logging.FrameworkTrace(ctx, "Resource implements ResourceWithModifyPlan") - modifyPlanReq := tfsdk.ModifyResourcePlanRequest{ + modifyPlanReq := resource.ModifyPlanRequest{ Config: *req.Config, Plan: stateToPlan(*resp.PlannedState), State: *req.PriorState, @@ -202,14 +204,14 @@ func (s *Server) PlanResourceChange(ctx context.Context, req *PlanResourceChange modifyPlanReq.ProviderMeta = *req.ProviderMeta } - modifyPlanResp := tfsdk.ModifyResourcePlanResponse{ + modifyPlanResp := resource.ModifyPlanResponse{ Diagnostics: resp.Diagnostics, Plan: modifyPlanReq.Plan, RequiresReplace: path.Paths{}, } logging.FrameworkDebug(ctx, "Calling provider defined Resource ModifyPlan") - resource.ModifyPlan(ctx, modifyPlanReq, &modifyPlanResp) + resourceWithModifyPlan.ModifyPlan(ctx, modifyPlanReq, &modifyPlanResp) logging.FrameworkDebug(ctx, "Called provider defined Resource ModifyPlan") resp.Diagnostics = modifyPlanResp.Diagnostics diff --git a/internal/fwserver/server_planresourcechange_test.go b/internal/fwserver/server_planresourcechange_test.go index 87671b040..5841d3cbd 100644 --- a/internal/fwserver/server_planresourcechange_test.go +++ b/internal/fwserver/server_planresourcechange_test.go @@ -11,6 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -376,7 +378,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -416,7 +418,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierAttributePlan, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -456,7 +458,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierDiagnosticsError, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -502,7 +504,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierRequiresReplace, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -550,9 +552,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -600,9 +602,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -651,9 +653,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -701,9 +703,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -750,9 +752,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -800,9 +802,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on creation, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -855,9 +857,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -899,9 +901,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -944,9 +946,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -988,9 +990,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -1031,9 +1033,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) }, @@ -1084,9 +1086,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on creation, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -1139,7 +1141,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -1185,7 +1187,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierAttributePlan, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -1231,7 +1233,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierDiagnosticsError, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -1283,7 +1285,7 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchemaAttributePlanModifierRequiresReplace, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -1332,9 +1334,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -1388,9 +1390,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -1445,9 +1447,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -1501,9 +1503,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -1556,9 +1558,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -1612,9 +1614,9 @@ func TestServerPlanResourceChange(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on creation, // but the framework does not prevent you from // doing it and it might be overly burdensome on diff --git a/internal/fwserver/server_readdatasource.go b/internal/fwserver/server_readdatasource.go index 1640ce3ce..dd4bda724 100644 --- a/internal/fwserver/server_readdatasource.go +++ b/internal/fwserver/server_readdatasource.go @@ -3,8 +3,10 @@ package fwserver import ( "context" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -13,7 +15,7 @@ import ( type ReadDataSourceRequest struct { Config *tfsdk.Config DataSourceSchema tfsdk.Schema - DataSourceType tfsdk.DataSourceType + DataSourceType provider.DataSourceType ProviderMeta *tfsdk.Config } @@ -41,12 +43,12 @@ func (s *Server) ReadDataSource(ctx context.Context, req *ReadDataSourceRequest, return } - readReq := tfsdk.ReadDataSourceRequest{ + readReq := datasource.ReadRequest{ Config: tfsdk.Config{ Schema: req.DataSourceSchema, }, } - readResp := tfsdk.ReadDataSourceResponse{ + readResp := datasource.ReadResponse{ State: tfsdk.State{ Schema: req.DataSourceSchema, }, diff --git a/internal/fwserver/server_readdatasource_test.go b/internal/fwserver/server_readdatasource_test.go index c7d49eb1e..8358012ab 100644 --- a/internal/fwserver/server_readdatasource_test.go +++ b/internal/fwserver/server_readdatasource_test.go @@ -5,9 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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" @@ -83,9 +85,9 @@ func TestServerReadDataSource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -116,9 +118,9 @@ func TestServerReadDataSource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -150,9 +152,9 @@ func TestServerReadDataSource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -185,9 +187,9 @@ func TestServerReadDataSource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` diff --git a/internal/fwserver/server_readresource.go b/internal/fwserver/server_readresource.go index 6c5eb5067..06ad1c639 100644 --- a/internal/fwserver/server_readresource.go +++ b/internal/fwserver/server_readresource.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -12,7 +14,7 @@ import ( // ReadResource RPC. type ReadResourceRequest struct { CurrentState *tfsdk.State - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType Private []byte ProviderMeta *tfsdk.Config } @@ -43,7 +45,7 @@ func (s *Server) ReadResource(ctx context.Context, req *ReadResourceRequest, res // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -52,13 +54,13 @@ func (s *Server) ReadResource(ctx context.Context, req *ReadResourceRequest, res return } - readReq := tfsdk.ReadResourceRequest{ + readReq := resource.ReadRequest{ State: tfsdk.State{ Schema: req.CurrentState.Schema, Raw: req.CurrentState.Raw.Copy(), }, } - readResp := tfsdk.ReadResourceResponse{ + readResp := resource.ReadResponse{ State: tfsdk.State{ Schema: req.CurrentState.Schema, Raw: req.CurrentState.Raw.Copy(), @@ -70,7 +72,7 @@ func (s *Server) ReadResource(ctx context.Context, req *ReadResourceRequest, res } logging.FrameworkDebug(ctx, "Calling provider defined Resource Read") - resource.Read(ctx, readReq, &readResp) + resourceImpl.Read(ctx, readReq, &readResp) logging.FrameworkDebug(ctx, "Called provider defined Resource Read") resp.Diagnostics = readResp.Diagnostics diff --git a/internal/fwserver/server_readresource_test.go b/internal/fwserver/server_readresource_test.go index f7e5eec85..31e381932 100644 --- a/internal/fwserver/server_readresource_test.go +++ b/internal/fwserver/server_readresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -102,9 +104,9 @@ func TestServerReadResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -134,9 +136,9 @@ func TestServerReadResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -167,9 +169,9 @@ func TestServerReadResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -201,9 +203,9 @@ func TestServerReadResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -233,9 +235,9 @@ func TestServerReadResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/fwserver/server_updateresource.go b/internal/fwserver/server_updateresource.go index ef67add7b..b662fa4b0 100644 --- a/internal/fwserver/server_updateresource.go +++ b/internal/fwserver/server_updateresource.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" ) @@ -18,7 +20,7 @@ type UpdateResourceRequest struct { PriorState *tfsdk.State ProviderMeta *tfsdk.Config ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // UpdateResourceResponse is the framework server response for an update request @@ -38,7 +40,7 @@ func (s *Server) UpdateResource(ctx context.Context, req *UpdateResourceRequest, // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -49,7 +51,7 @@ func (s *Server) UpdateResource(ctx context.Context, req *UpdateResourceRequest, nullSchemaData := tftypes.NewValue(req.ResourceSchema.TerraformType(ctx), nil) - updateReq := tfsdk.UpdateResourceRequest{ + updateReq := resource.UpdateRequest{ Config: tfsdk.Config{ Schema: req.ResourceSchema, Raw: nullSchemaData, @@ -63,7 +65,7 @@ func (s *Server) UpdateResource(ctx context.Context, req *UpdateResourceRequest, Raw: nullSchemaData, }, } - updateResp := tfsdk.UpdateResourceResponse{ + updateResp := resource.UpdateResponse{ State: tfsdk.State{ Schema: req.ResourceSchema, Raw: nullSchemaData, @@ -89,7 +91,7 @@ func (s *Server) UpdateResource(ctx context.Context, req *UpdateResourceRequest, } logging.FrameworkDebug(ctx, "Calling provider defined Resource Update") - resource.Update(ctx, updateReq, &updateResp) + resourceImpl.Update(ctx, updateReq, &updateResp) logging.FrameworkDebug(ctx, "Called provider defined Resource Update") resp.Diagnostics = updateResp.Diagnostics diff --git a/internal/fwserver/server_updateresource_test.go b/internal/fwserver/server_updateresource_test.go index a17a62630..e486d6eb7 100644 --- a/internal/fwserver/server_updateresource_test.go +++ b/internal/fwserver/server_updateresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -105,9 +107,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -162,9 +164,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -219,9 +221,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -277,9 +279,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -334,9 +336,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -395,9 +397,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -448,9 +450,9 @@ func TestServerUpdateResource(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/fwserver/server_upgraderesourcestate.go b/internal/fwserver/server_upgraderesourcestate.go index 504757263..74696b019 100644 --- a/internal/fwserver/server_upgraderesourcestate.go +++ b/internal/fwserver/server_upgraderesourcestate.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -20,7 +22,7 @@ type UpgradeResourceStateRequest struct { RawState *tfprotov6.RawState ResourceSchema tfsdk.Schema - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType Version int64 } @@ -99,7 +101,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -108,7 +110,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS return } - resourceWithUpgradeState, ok := resource.(tfsdk.ResourceWithUpgradeState) + resourceWithUpgradeState, ok := resourceImpl.(resource.ResourceWithUpgradeState) if !ok { resp.Diagnostics.AddError( @@ -128,7 +130,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS // Panic prevention if resourceStateUpgraders == nil { - resourceStateUpgraders = make(map[int64]tfsdk.ResourceStateUpgrader, 0) + resourceStateUpgraders = make(map[int64]resource.StateUpgrader, 0) } resourceStateUpgrader, ok := resourceStateUpgraders[req.Version] @@ -143,7 +145,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS return } - upgradeResourceStateRequest := tfsdk.UpgradeResourceStateRequest{ + upgradeResourceStateRequest := resource.UpgradeStateRequest{ RawState: req.RawState, } @@ -169,7 +171,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS } } - upgradeResourceStateResponse := tfsdk.UpgradeResourceStateResponse{ + upgradeResourceStateResponse := resource.UpgradeStateResponse{ State: tfsdk.State{ Schema: req.ResourceSchema, // Raw is intentionally not set. diff --git a/internal/fwserver/server_upgraderesourcestate_test.go b/internal/fwserver/server_upgraderesourcestate_test.go index 796099862..e6855e3d4 100644 --- a/internal/fwserver/server_upgraderesourcestate_test.go +++ b/internal/fwserver/server_upgraderesourcestate_test.go @@ -14,6 +14,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -77,13 +79,13 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { rawStateValue, err := req.RawState.Unmarshal(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "id": tftypes.String, @@ -191,13 +193,13 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { var rawState struct { Id string `json:"id"` OptionalAttribute *bool `json:"optional_attribute,omitempty"` @@ -271,7 +273,7 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -302,10 +304,10 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { return nil }, }, nil @@ -338,11 +340,11 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { PriorSchema: &tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ @@ -360,7 +362,7 @@ func TestServerUpgradeResourceState(t *testing.T) { }, }, }, - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { // Expect error before reaching this logic. }, }, @@ -396,11 +398,11 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { PriorSchema: &tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ @@ -418,7 +420,7 @@ func TestServerUpgradeResourceState(t *testing.T) { }, }, }, - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { var priorStateData struct { Id string `tfsdk:"id"` OptionalAttribute *bool `tfsdk:"optional_attribute"` @@ -481,11 +483,11 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { PriorSchema: &tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ @@ -503,7 +505,7 @@ func TestServerUpgradeResourceState(t *testing.T) { }, }, }, - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { var priorStateData struct { Id string `tfsdk:"id"` OptionalAttribute *bool `tfsdk:"optional_attribute"` @@ -565,13 +567,13 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { // Purposfully not setting resp.DynamicValue or resp.State }, }, @@ -596,8 +598,8 @@ func TestServerUpgradeResourceState(t *testing.T) { "Version-current-flatmap": { server: &fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil @@ -618,7 +620,7 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { // Framework should allow non-ResourceWithUpgradeState return &testprovider.Resource{}, nil }, @@ -641,8 +643,8 @@ func TestServerUpgradeResourceState(t *testing.T) { "Version-current-json-match": { server: &fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil @@ -662,7 +664,7 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { // Framework should allow non-ResourceWithUpgradeState return &testprovider.Resource{}, nil }, @@ -695,7 +697,7 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { // Framework should allow non-ResourceWithUpgradeState return &testprovider.Resource{}, nil }, @@ -727,10 +729,10 @@ func TestServerUpgradeResourceState(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { return nil }, }, nil diff --git a/internal/fwserver/server_validatedatasourceconfig.go b/internal/fwserver/server_validatedatasourceconfig.go index 3796f4886..f8a76b4e2 100644 --- a/internal/fwserver/server_validatedatasourceconfig.go +++ b/internal/fwserver/server_validatedatasourceconfig.go @@ -3,8 +3,10 @@ package fwserver import ( "context" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -12,7 +14,7 @@ import ( // ValidateDataSourceConfig RPC. type ValidateDataSourceConfigRequest struct { Config *tfsdk.Config - DataSourceType tfsdk.DataSourceType + DataSourceType provider.DataSourceType } // ValidateDataSourceConfigResponse is the framework server response for the @@ -38,21 +40,21 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData return } - vdscReq := tfsdk.ValidateDataSourceConfigRequest{ + vdscReq := datasource.ValidateConfigRequest{ Config: *req.Config, } - if dataSource, ok := dataSource.(tfsdk.DataSourceWithConfigValidators); ok { + if dataSource, ok := dataSource.(datasource.DataSourceWithConfigValidators); ok { logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithConfigValidators") for _, configValidator := range dataSource.ConfigValidators(ctx) { - vdscResp := &tfsdk.ValidateDataSourceConfigResponse{ + vdscResp := &datasource.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } logging.FrameworkDebug( ctx, - "Calling provider defined DataSourceConfigValidator", + "Calling provider defined ConfigValidator", map[string]interface{}{ logging.KeyDescription: configValidator.Description(ctx), }, @@ -60,7 +62,7 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData configValidator.ValidateDataSource(ctx, vdscReq, vdscResp) logging.FrameworkDebug( ctx, - "Called provider defined DataSourceConfigValidator", + "Called provider defined ConfigValidator", map[string]interface{}{ logging.KeyDescription: configValidator.Description(ctx), }, @@ -70,10 +72,10 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData } } - if dataSource, ok := dataSource.(tfsdk.DataSourceWithValidateConfig); ok { + if dataSource, ok := dataSource.(datasource.DataSourceWithValidateConfig); ok { logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithValidateConfig") - vdscResp := &tfsdk.ValidateDataSourceConfigResponse{ + vdscResp := &datasource.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } diff --git a/internal/fwserver/server_validatedatasourceconfig_test.go b/internal/fwserver/server_validatedatasourceconfig_test.go index d515c9ed5..3f3c0269a 100644 --- a/internal/fwserver/server_validatedatasourceconfig_test.go +++ b/internal/fwserver/server_validatedatasourceconfig_test.go @@ -5,10 +5,12 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "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" @@ -164,13 +166,13 @@ func TestServerValidateDataSourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithConfigValidators{ DataSource: &testprovider.DataSource{}, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.DataSourceConfigValidator { - return []tfsdk.DataSourceConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []datasource.ConfigValidator { + return []datasource.ConfigValidator{ &testprovider.DataSourceConfigValidator{ - ValidateDataSourceMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateDataSourceMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -202,13 +204,13 @@ func TestServerValidateDataSourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithConfigValidators{ DataSource: &testprovider.DataSource{}, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.DataSourceConfigValidator { - return []tfsdk.DataSourceConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []datasource.ConfigValidator { + return []datasource.ConfigValidator{ &testprovider.DataSourceConfigValidator{ - ValidateDataSourceMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateDataSourceMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { resp.Diagnostics.AddError("error summary", "error detail") }, }, @@ -236,10 +238,10 @@ func TestServerValidateDataSourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithValidateConfig{ DataSource: &testprovider.DataSource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -268,10 +270,10 @@ func TestServerValidateDataSourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithValidateConfig{ DataSource: &testprovider.DataSource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/fwserver/server_validateproviderconfig.go b/internal/fwserver/server_validateproviderconfig.go index 731a4cdf2..fb40f1e16 100644 --- a/internal/fwserver/server_validateproviderconfig.go +++ b/internal/fwserver/server_validateproviderconfig.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -27,21 +28,21 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid return } - vpcReq := tfsdk.ValidateProviderConfigRequest{ + vpcReq := provider.ValidateConfigRequest{ Config: *req.Config, } - if provider, ok := s.Provider.(tfsdk.ProviderWithConfigValidators); ok { + if providerWithConfigValidators, ok := s.Provider.(provider.ProviderWithConfigValidators); ok { logging.FrameworkTrace(ctx, "Provider implements ProviderWithConfigValidators") - for _, configValidator := range provider.ConfigValidators(ctx) { - vpcRes := &tfsdk.ValidateProviderConfigResponse{ + for _, configValidator := range providerWithConfigValidators.ConfigValidators(ctx) { + vpcRes := &provider.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } logging.FrameworkDebug( ctx, - "Calling provider defined ProviderConfigValidator", + "Calling provider defined ConfigValidator", map[string]interface{}{ logging.KeyDescription: configValidator.Description(ctx), }, @@ -49,7 +50,7 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid configValidator.ValidateProvider(ctx, vpcReq, vpcRes) logging.FrameworkDebug( ctx, - "Called provider defined ProviderConfigValidator", + "Called provider defined ConfigValidator", map[string]interface{}{ logging.KeyDescription: configValidator.Description(ctx), }, @@ -59,15 +60,15 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid } } - if provider, ok := s.Provider.(tfsdk.ProviderWithValidateConfig); ok { + if providerWithValidateConfig, ok := s.Provider.(provider.ProviderWithValidateConfig); ok { logging.FrameworkTrace(ctx, "Provider implements ProviderWithValidateConfig") - vpcRes := &tfsdk.ValidateProviderConfigResponse{ + vpcRes := &provider.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } logging.FrameworkDebug(ctx, "Calling provider defined Provider ValidateConfig") - provider.ValidateConfig(ctx, vpcReq, vpcRes) + providerWithValidateConfig.ValidateConfig(ctx, vpcReq, vpcRes) logging.FrameworkDebug(ctx, "Called provider defined Provider ValidateConfig") resp.Diagnostics = vpcRes.Diagnostics diff --git a/internal/fwserver/server_validateproviderconfig_test.go b/internal/fwserver/server_validateproviderconfig_test.go index 1710cb855..c2607de62 100644 --- a/internal/fwserver/server_validateproviderconfig_test.go +++ b/internal/fwserver/server_validateproviderconfig_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "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" @@ -164,10 +165,10 @@ func TestServerValidateProviderConfig(t *testing.T) { return testSchema, nil }, }, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.ProviderConfigValidator { - return []tfsdk.ProviderConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []provider.ConfigValidator { + return []provider.ConfigValidator{ &testprovider.ProviderConfigValidator{ - ValidateProviderMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateProviderMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -200,10 +201,10 @@ func TestServerValidateProviderConfig(t *testing.T) { return testSchema, nil }, }, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.ProviderConfigValidator { - return []tfsdk.ProviderConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []provider.ConfigValidator { + return []provider.ConfigValidator{ &testprovider.ProviderConfigValidator{ - ValidateProviderMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateProviderMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { resp.Diagnostics.AddError("error summary", "error detail") }, }, @@ -232,7 +233,7 @@ func TestServerValidateProviderConfig(t *testing.T) { return testSchema, nil }, }, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -262,7 +263,7 @@ func TestServerValidateProviderConfig(t *testing.T) { return testSchema, nil }, }, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/fwserver/server_validateresourceconfig.go b/internal/fwserver/server_validateresourceconfig.go index 837021022..6e14710c9 100644 --- a/internal/fwserver/server_validateresourceconfig.go +++ b/internal/fwserver/server_validateresourceconfig.go @@ -5,6 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) @@ -12,7 +14,7 @@ import ( // ValidateResourceConfig RPC. type ValidateResourceConfigRequest struct { Config *tfsdk.Config - ResourceType tfsdk.ResourceType + ResourceType provider.ResourceType } // ValidateResourceConfigResponse is the framework server response for the @@ -29,7 +31,7 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour // Always instantiate new Resource instances. logging.FrameworkDebug(ctx, "Calling provider defined ResourceType NewResource") - resource, diags := req.ResourceType.NewResource(ctx, s.Provider) + resourceImpl, diags := req.ResourceType.NewResource(ctx, s.Provider) logging.FrameworkDebug(ctx, "Called provider defined ResourceType NewResource") resp.Diagnostics.Append(diags...) @@ -38,15 +40,15 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour return } - vdscReq := tfsdk.ValidateResourceConfigRequest{ + vdscReq := resource.ValidateConfigRequest{ Config: *req.Config, } - if resource, ok := resource.(tfsdk.ResourceWithConfigValidators); ok { + if resourceWithConfigValidators, ok := resourceImpl.(resource.ResourceWithConfigValidators); ok { logging.FrameworkTrace(ctx, "Resource implements ResourceWithConfigValidators") - for _, configValidator := range resource.ConfigValidators(ctx) { - vdscResp := &tfsdk.ValidateResourceConfigResponse{ + for _, configValidator := range resourceWithConfigValidators.ConfigValidators(ctx) { + vdscResp := &resource.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } @@ -70,15 +72,15 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour } } - if resource, ok := resource.(tfsdk.ResourceWithValidateConfig); ok { + if resourceWithValidateConfig, ok := resourceImpl.(resource.ResourceWithValidateConfig); ok { logging.FrameworkTrace(ctx, "Resource implements ResourceWithValidateConfig") - vdscResp := &tfsdk.ValidateResourceConfigResponse{ + vdscResp := &resource.ValidateConfigResponse{ Diagnostics: resp.Diagnostics, } logging.FrameworkDebug(ctx, "Calling provider defined Resource ValidateConfig") - resource.ValidateConfig(ctx, vdscReq, vdscResp) + resourceWithValidateConfig.ValidateConfig(ctx, vdscReq, vdscResp) logging.FrameworkDebug(ctx, "Called provider defined Resource ValidateConfig") resp.Diagnostics = vdscResp.Diagnostics diff --git a/internal/fwserver/server_validateresourceconfig_test.go b/internal/fwserver/server_validateresourceconfig_test.go index 4f2c73c4e..e1503236d 100644 --- a/internal/fwserver/server_validateresourceconfig_test.go +++ b/internal/fwserver/server_validateresourceconfig_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -164,13 +166,13 @@ func TestServerValidateResourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithConfigValidators{ Resource: &testprovider.Resource{}, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.ResourceConfigValidator { - return []tfsdk.ResourceConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []resource.ConfigValidator { + return []resource.ConfigValidator{ &testprovider.ResourceConfigValidator{ - ValidateResourceMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateResourceMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -202,13 +204,13 @@ func TestServerValidateResourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithConfigValidators{ Resource: &testprovider.Resource{}, - ConfigValidatorsMethod: func(ctx context.Context) []tfsdk.ResourceConfigValidator { - return []tfsdk.ResourceConfigValidator{ + ConfigValidatorsMethod: func(ctx context.Context) []resource.ConfigValidator { + return []resource.ConfigValidator{ &testprovider.ResourceConfigValidator{ - ValidateResourceMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateResourceMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { resp.Diagnostics.AddError("error summary", "error detail") }, }, @@ -236,10 +238,10 @@ func TestServerValidateResourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithValidateConfig{ Resource: &testprovider.Resource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -268,10 +270,10 @@ func TestServerValidateResourceConfig(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithValidateConfig{ Resource: &testprovider.Resource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto5server/server_applyresourcechange_test.go b/internal/proto5server/server_applyresourcechange_test.go index 884707807..4e34a9d86 100644 --- a/internal/proto5server/server_applyresourcechange_test.go +++ b/internal/proto5server/server_applyresourcechange_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -77,15 +79,15 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -97,10 +99,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -134,15 +136,15 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -154,10 +156,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -190,17 +192,17 @@ func TestServerApplyResourceChange(t *testing.T) { "create-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var metadata testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metadata)...) @@ -215,10 +217,10 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -257,22 +259,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -315,24 +317,24 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -366,21 +368,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Intentionally missing resp.State.Set() }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -421,18 +423,18 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -441,7 +443,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("Unexpected req.State Value", "Got: "+data.TestRequired.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -467,20 +469,20 @@ func TestServerApplyResourceChange(t *testing.T) { "delete-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -489,7 +491,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("Unexpected req.ProviderMeta Value", "Got: "+data.TestProviderMetaAttribute.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -521,22 +523,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -578,21 +580,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // Intentionally empty, should call resp.State.RemoveResource() automatically. }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -619,22 +621,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -678,22 +680,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -737,21 +739,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -794,23 +796,23 @@ func TestServerApplyResourceChange(t *testing.T) { "update-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -859,21 +861,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -923,21 +925,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -977,21 +979,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/proto5server/server_configureprovider.go b/internal/proto5server/server_configureprovider.go index bf3d06e44..115cb68de 100644 --- a/internal/proto5server/server_configureprovider.go +++ b/internal/proto5server/server_configureprovider.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/internal/toproto5" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) @@ -15,7 +15,7 @@ func (s *Server) ConfigureProvider(ctx context.Context, proto5Req *tfprotov5.Con ctx = s.registerContext(ctx) ctx = logging.InitContext(ctx) - fwResp := &tfsdk.ConfigureProviderResponse{} + fwResp := &provider.ConfigureResponse{} providerSchema, diags := s.FrameworkServer.ProviderSchema(ctx) diff --git a/internal/proto5server/server_configureprovider_test.go b/internal/proto5server/server_configureprovider_test.go index 3db9dd672..ec53a0dcd 100644 --- a/internal/proto5server/server_configureprovider_test.go +++ b/internal/proto5server/server_configureprovider_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "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/tfprotov5" @@ -67,7 +68,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { // Intentially empty, test is passing if it makes it this far }, }, @@ -83,7 +84,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -111,7 +112,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { if req.TerraformVersion != "1.0.0" { resp.Diagnostics.AddError("Incorrect req.TerraformVersion", "expected 1.0.0, got "+req.TerraformVersion) } @@ -131,7 +132,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto5server/server_getproviderschema_test.go b/internal/proto5server/server_getproviderschema_test.go index 302886324..0bf0de5f7 100644 --- a/internal/proto5server/server_getproviderschema_test.go +++ b/internal/proto5server/server_getproviderschema_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov5" @@ -30,8 +31,8 @@ func TestServerGetProviderSchema(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source1": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -136,7 +137,7 @@ func TestServerGetProviderSchema(t *testing.T) { "providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{}, GetMetaSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -178,8 +179,8 @@ func TestServerGetProviderSchema(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource1": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ diff --git a/internal/proto5server/server_importresourcestate_test.go b/internal/proto5server/server_importresourcestate_test.go index 52d131a78..80db18bcc 100644 --- a/internal/proto5server/server_importresourcestate_test.go +++ b/internal/proto5server/server_importresourcestate_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -59,21 +61,21 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { if req.ID != "test-id" { resp.Diagnostics.AddError("unexpected req.ID value: %s", req.ID) } - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, @@ -100,16 +102,16 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -144,17 +146,17 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, diff --git a/internal/proto5server/server_planresourcechange_test.go b/internal/proto5server/server_planresourcechange_test.go index 37047ebb0..18b0f3c74 100644 --- a/internal/proto5server/server_planresourcechange_test.go +++ b/internal/proto5server/server_planresourcechange_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -78,15 +80,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -126,15 +128,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -173,17 +175,17 @@ func TestServerPlanResourceChange(t *testing.T) { "create-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -228,15 +230,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -283,15 +285,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -331,15 +333,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on creation, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -384,15 +386,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -424,17 +426,17 @@ func TestServerPlanResourceChange(t *testing.T) { "delete-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -472,15 +474,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -520,15 +522,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) }, @@ -568,15 +570,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on destroy, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -614,15 +616,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -665,15 +667,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -716,15 +718,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -766,17 +768,17 @@ func TestServerPlanResourceChange(t *testing.T) { "update-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -824,15 +826,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -882,15 +884,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -933,15 +935,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.RequiresReplace = path.Paths{ path.Root("test_required"), } diff --git a/internal/proto5server/server_prepareproviderconfig_test.go b/internal/proto5server/server_prepareproviderconfig_test.go index 173591dae..698c0c489 100644 --- a/internal/proto5server/server_prepareproviderconfig_test.go +++ b/internal/proto5server/server_prepareproviderconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov5" @@ -96,7 +97,7 @@ func TestServerPrepareProviderConfig(t *testing.T) { return testSchema, nil }, }, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto5server/server_readdatasource_test.go b/internal/proto5server/server_readdatasource_test.go index e1c8a5ba1..ec1523e17 100644 --- a/internal/proto5server/server_readdatasource_test.go +++ b/internal/proto5server/server_readdatasource_test.go @@ -5,9 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov5" @@ -59,13 +61,13 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -86,15 +88,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -125,17 +127,17 @@ func TestServerReadDataSource(t *testing.T) { "request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -172,15 +174,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -216,15 +218,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` diff --git a/internal/proto5server/server_readresource_test.go b/internal/proto5server/server_readresource_test.go index 74e3e26db..f8d355c6a 100644 --- a/internal/proto5server/server_readresource_test.go +++ b/internal/proto5server/server_readresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -61,13 +63,13 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -88,15 +90,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -127,17 +129,17 @@ func TestServerReadResource(t *testing.T) { "request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -174,15 +176,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -218,15 +220,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -258,15 +260,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/proto5server/server_upgraderesourcestate_test.go b/internal/proto5server/server_upgraderesourcestate_test.go index e91ea8ebd..8c0f11718 100644 --- a/internal/proto5server/server_upgraderesourcestate_test.go +++ b/internal/proto5server/server_upgraderesourcestate_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -56,19 +58,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { expectedRawState := testNewTfprotov6RawState(t, map[string]interface{}{ "id": "test-id-value", "required_attribute": true, @@ -155,19 +157,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, _ tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, _ resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -209,19 +211,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, _ tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, _ resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { resp.State = tfsdk.State{ Raw: tftypes.NewValue(schemaType, map[string]tftypes.Value{ "id": tftypes.NewValue(tftypes.String, "test-id-value"), diff --git a/internal/proto5server/server_validatedatasourceconfig_test.go b/internal/proto5server/server_validatedatasourceconfig_test.go index d0e25cae1..e27935369 100644 --- a/internal/proto5server/server_validatedatasourceconfig_test.go +++ b/internal/proto5server/server_validatedatasourceconfig_test.go @@ -5,9 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov5" @@ -52,13 +54,13 @@ func TestServerValidateDataSourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -76,13 +78,13 @@ func TestServerValidateDataSourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -101,16 +103,16 @@ func TestServerValidateDataSourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithValidateConfig{ DataSource: &testprovider.DataSource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto5server/server_validateresourcetypeconfig_test.go b/internal/proto5server/server_validateresourcetypeconfig_test.go index 739be91ef..81bb3d469 100644 --- a/internal/proto5server/server_validateresourcetypeconfig_test.go +++ b/internal/proto5server/server_validateresourcetypeconfig_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -52,13 +54,13 @@ func TestServerValidateResourceTypeConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -76,13 +78,13 @@ func TestServerValidateResourceTypeConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -101,16 +103,16 @@ func TestServerValidateResourceTypeConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithValidateConfig{ Resource: &testprovider.Resource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto6server/server_applyresourcechange_test.go b/internal/proto6server/server_applyresourcechange_test.go index 1f40116ee..e0150e9ad 100644 --- a/internal/proto6server/server_applyresourcechange_test.go +++ b/internal/proto6server/server_applyresourcechange_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -77,15 +79,15 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -97,10 +99,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -134,15 +136,15 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -154,10 +156,10 @@ func TestServerApplyResourceChange(t *testing.T) { // Prevent missing resource state error diagnostic resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -190,17 +192,17 @@ func TestServerApplyResourceChange(t *testing.T) { "create-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var metadata testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metadata)...) @@ -215,10 +217,10 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -257,22 +259,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -315,24 +317,24 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -366,21 +368,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Intentionally missing resp.State.Set() }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Delete") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Create, Got: Update") }, }, nil @@ -421,18 +423,18 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -441,7 +443,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("Unexpected req.State Value", "Got: "+data.TestRequired.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -467,20 +469,20 @@ func TestServerApplyResourceChange(t *testing.T) { "delete-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -489,7 +491,7 @@ func TestServerApplyResourceChange(t *testing.T) { resp.Diagnostics.AddError("Unexpected req.ProviderMeta Value", "Got: "+data.TestProviderMetaAttribute.Value) } }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -521,22 +523,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -578,21 +580,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Create") }, - DeleteMethod: func(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // Intentionally empty, should call resp.State.RemoveResource() automatically. }, - UpdateMethod: func(_ context.Context, _ tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(_ context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Delete, Got: Update") }, }, nil @@ -619,22 +621,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -678,22 +680,22 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -737,21 +739,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -794,23 +796,23 @@ func TestServerApplyResourceChange(t *testing.T) { "update-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -859,21 +861,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -923,21 +925,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -977,21 +979,21 @@ func TestServerApplyResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - CreateMethod: func(_ context.Context, _ tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + CreateMethod: func(_ context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Create") }, - DeleteMethod: func(_ context.Context, _ tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { + DeleteMethod: func(_ context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { resp.Diagnostics.AddError("Unexpected Method Call", "Expected: Update, Got: Delete") }, - UpdateMethod: func(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { + UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/proto6server/server_configureprovider.go b/internal/proto6server/server_configureprovider.go index 3c3018d01..448d2d6e6 100644 --- a/internal/proto6server/server_configureprovider.go +++ b/internal/proto6server/server_configureprovider.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/internal/toproto6" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) @@ -15,7 +15,7 @@ func (s *Server) ConfigureProvider(ctx context.Context, proto6Req *tfprotov6.Con ctx = s.registerContext(ctx) ctx = logging.InitContext(ctx) - fwResp := &tfsdk.ConfigureProviderResponse{} + fwResp := &provider.ConfigureResponse{} providerSchema, diags := s.FrameworkServer.ProviderSchema(ctx) diff --git a/internal/proto6server/server_configureprovider_test.go b/internal/proto6server/server_configureprovider_test.go index 022a25b6e..ae3d1b538 100644 --- a/internal/proto6server/server_configureprovider_test.go +++ b/internal/proto6server/server_configureprovider_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "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/tfprotov6" @@ -67,7 +68,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { // Intentially empty, test is passing if it makes it this far }, }, @@ -83,7 +84,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { var got types.String resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("test"), &got)...) @@ -111,7 +112,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { if req.TerraformVersion != "1.0.0" { resp.Diagnostics.AddError("Incorrect req.TerraformVersion", "expected 1.0.0, got "+req.TerraformVersion) } @@ -131,7 +132,7 @@ func TestServerConfigureProvider(t *testing.T) { GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - ConfigureMethod: func(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { + ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto6server/server_getproviderschema_test.go b/internal/proto6server/server_getproviderschema_test.go index 09a371cab..ba8cdadd3 100644 --- a/internal/proto6server/server_getproviderschema_test.go +++ b/internal/proto6server/server_getproviderschema_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov6" @@ -30,8 +31,8 @@ func TestServerGetProviderSchema(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source1": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -136,7 +137,7 @@ func TestServerGetProviderSchema(t *testing.T) { "providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{}, GetMetaSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ @@ -178,8 +179,8 @@ func TestServerGetProviderSchema(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource1": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ diff --git a/internal/proto6server/server_importresourcestate_test.go b/internal/proto6server/server_importresourcestate_test.go index be3594dd2..cf61acd68 100644 --- a/internal/proto6server/server_importresourcestate_test.go +++ b/internal/proto6server/server_importresourcestate_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -59,21 +61,21 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { if req.ID != "test-id" { resp.Diagnostics.AddError("unexpected req.ID value: %s", req.ID) } - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, @@ -100,16 +102,16 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -144,17 +146,17 @@ func TestServerImportResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithImportState{ Resource: &testprovider.Resource{}, - ImportStateMethod: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) + ImportStateMethod: func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) }, }, nil }, diff --git a/internal/proto6server/server_planresourcechange_test.go b/internal/proto6server/server_planresourcechange_test.go index d6b66d1a9..e652515f2 100644 --- a/internal/proto6server/server_planresourcechange_test.go +++ b/internal/proto6server/server_planresourcechange_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -78,15 +80,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -126,15 +128,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -173,17 +175,17 @@ func TestServerPlanResourceChange(t *testing.T) { "create-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -228,15 +230,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -283,15 +285,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -331,15 +333,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on creation, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -384,15 +386,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -424,17 +426,17 @@ func TestServerPlanResourceChange(t *testing.T) { "delete-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -472,15 +474,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -520,15 +522,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) }, @@ -568,15 +570,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is a strange thing to signal on destroy, // but the framework does not prevent you from // doing it and it might be overly burdensome on @@ -614,15 +616,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -665,15 +667,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -716,15 +718,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -766,17 +768,17 @@ func TestServerPlanResourceChange(t *testing.T) { "update-request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testProviderMetaData resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &data)...) @@ -824,15 +826,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -882,15 +884,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { var data testSchemaData resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -933,15 +935,15 @@ func TestServerPlanResourceChange(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithModifyPlan{ - ModifyPlanMethod: func(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { + ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { resp.RequiresReplace = path.Paths{ path.Root("test_required"), } diff --git a/internal/proto6server/server_readdatasource_test.go b/internal/proto6server/server_readdatasource_test.go index 37e97004d..b77c3a4d8 100644 --- a/internal/proto6server/server_readdatasource_test.go +++ b/internal/proto6server/server_readdatasource_test.go @@ -5,9 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov6" @@ -59,13 +61,13 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -86,15 +88,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -125,17 +127,17 @@ func TestServerReadDataSource(t *testing.T) { "request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -172,15 +174,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -216,15 +218,15 @@ func TestServerReadDataSource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { + ReadMethod: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` diff --git a/internal/proto6server/server_readresource_test.go b/internal/proto6server/server_readresource_test.go index f2970004e..9ffbd1dfb 100644 --- a/internal/proto6server/server_readresource_test.go +++ b/internal/proto6server/server_readresource_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -61,13 +63,13 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -88,15 +90,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -127,17 +129,17 @@ func TestServerReadResource(t *testing.T) { "request-providermeta": { server: &Server{ FrameworkServer: fwserver.Server{ - Provider: &testprovider.ProviderWithProviderMeta{ + Provider: &testprovider.ProviderWithMetaSchema{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -174,15 +176,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -218,15 +220,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data struct { TestComputed types.String `tfsdk:"test_computed"` TestRequired types.String `tfsdk:"test_required"` @@ -258,15 +260,15 @@ func TestServerReadResource(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{ - ReadMethod: func(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { + ReadMethod: func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { resp.State.RemoveResource(ctx) }, }, nil diff --git a/internal/proto6server/server_upgraderesourcestate_test.go b/internal/proto6server/server_upgraderesourcestate_test.go index a0e7026e7..23c6e1a94 100644 --- a/internal/proto6server/server_upgraderesourcestate_test.go +++ b/internal/proto6server/server_upgraderesourcestate_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -56,19 +58,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { expectedRawState := testNewRawState(t, map[string]interface{}{ "id": "test-id-value", "required_attribute": true, @@ -155,19 +157,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, _ tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, _ resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, @@ -209,19 +211,19 @@ func TestServerUpgradeResourceState(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_resource": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return schema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithUpgradeState{ Resource: &testprovider.Resource{}, - UpgradeStateMethod: func(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ + UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ 0: { - StateUpgrader: func(_ context.Context, _ tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(_ context.Context, _ resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { resp.State = tfsdk.State{ Raw: tftypes.NewValue(schemaType, map[string]tftypes.Value{ "id": tftypes.NewValue(tftypes.String, "test-id-value"), diff --git a/internal/proto6server/server_validatedataresourceconfig_test.go b/internal/proto6server/server_validatedataresourceconfig_test.go index 0f59743ad..59be0a1ce 100644 --- a/internal/proto6server/server_validatedataresourceconfig_test.go +++ b/internal/proto6server/server_validatedataresourceconfig_test.go @@ -5,9 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov6" @@ -52,13 +54,13 @@ func TestServerValidateDataResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -76,13 +78,13 @@ func TestServerValidateDataResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSource{}, nil }, }, @@ -101,16 +103,16 @@ func TestServerValidateDataResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetDataSourcesMethod: func(_ context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + GetDataSourcesMethod: func(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ "test_data_source": &testprovider.DataSourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewDataSourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + NewDataSourceMethod: func(_ context.Context, _ provider.Provider) (datasource.DataSource, diag.Diagnostics) { return &testprovider.DataSourceWithValidateConfig{ DataSource: &testprovider.DataSource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto6server/server_validateproviderconfig_test.go b/internal/proto6server/server_validateproviderconfig_test.go index 807e32653..c78e4708f 100644 --- a/internal/proto6server/server_validateproviderconfig_test.go +++ b/internal/proto6server/server_validateproviderconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "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/tfprotov6" @@ -96,7 +97,7 @@ func TestServerValidateProviderConfig(t *testing.T) { return testSchema, nil }, }, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/proto6server/server_validateresourceconfig_test.go b/internal/proto6server/server_validateresourceconfig_test.go index ec7967a18..94a90ec21 100644 --- a/internal/proto6server/server_validateresourceconfig_test.go +++ b/internal/proto6server/server_validateresourceconfig_test.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -52,13 +54,13 @@ func TestServerValidateResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{}, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -76,13 +78,13 @@ func TestServerValidateResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.Resource{}, nil }, }, @@ -101,16 +103,16 @@ func TestServerValidateResourceConfig(t *testing.T) { server: &Server{ FrameworkServer: fwserver.Server{ Provider: &testprovider.Provider{ - GetResourcesMethod: func(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + GetResourcesMethod: func(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ "test_data_source": &testprovider.ResourceType{ GetSchemaMethod: func(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return testSchema, nil }, - NewResourceMethod: func(_ context.Context, _ tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + NewResourceMethod: func(_ context.Context, _ provider.Provider) (resource.Resource, diag.Diagnostics) { return &testprovider.ResourceWithValidateConfig{ Resource: &testprovider.Resource{}, - ValidateConfigMethod: func(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { + ValidateConfigMethod: func(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { resp.Diagnostics.AddWarning("warning summary", "warning detail") resp.Diagnostics.AddError("error summary", "error detail") }, diff --git a/internal/testing/testprovider/datasource.go b/internal/testing/testprovider/datasource.go index 061004dc0..e126cd442 100644 --- a/internal/testing/testprovider/datasource.go +++ b/internal/testing/testprovider/datasource.go @@ -3,19 +3,19 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource" ) -var _ tfsdk.DataSource = &DataSource{} +var _ datasource.DataSource = &DataSource{} -// Declarative tfsdk.DataSource for unit testing. +// Declarative datasource.DataSource for unit testing. type DataSource struct { // DataSource interface methods - ReadMethod func(context.Context, tfsdk.ReadDataSourceRequest, *tfsdk.ReadDataSourceResponse) + ReadMethod func(context.Context, datasource.ReadRequest, *datasource.ReadResponse) } -// Read satisfies the tfsdk.DataSource interface. -func (d *DataSource) Read(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) { +// Read satisfies the datasource.DataSource interface. +func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { if d.ReadMethod == nil { return } diff --git a/internal/testing/testprovider/datasourceconfigvalidator.go b/internal/testing/testprovider/datasourceconfigvalidator.go index ba8ece7df..6a00147e7 100644 --- a/internal/testing/testprovider/datasourceconfigvalidator.go +++ b/internal/testing/testprovider/datasourceconfigvalidator.go @@ -3,20 +3,20 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource" ) -var _ tfsdk.DataSourceConfigValidator = &DataSourceConfigValidator{} +var _ datasource.ConfigValidator = &DataSourceConfigValidator{} -// Declarative tfsdk.DataSourceConfigValidator for unit testing. +// Declarative datasource.ConfigValidator for unit testing. type DataSourceConfigValidator struct { // DataSourceConfigValidator interface methods DescriptionMethod func(context.Context) string MarkdownDescriptionMethod func(context.Context) string - ValidateDataSourceMethod func(context.Context, tfsdk.ValidateDataSourceConfigRequest, *tfsdk.ValidateDataSourceConfigResponse) + ValidateDataSourceMethod func(context.Context, datasource.ValidateConfigRequest, *datasource.ValidateConfigResponse) } -// Description satisfies the tfsdk.DataSourceConfigValidator interface. +// Description satisfies the datasource.ConfigValidator interface. func (v *DataSourceConfigValidator) Description(ctx context.Context) string { if v.DescriptionMethod == nil { return "" @@ -25,7 +25,7 @@ func (v *DataSourceConfigValidator) Description(ctx context.Context) string { return v.DescriptionMethod(ctx) } -// MarkdownDescription satisfies the tfsdk.DataSourceConfigValidator interface. +// MarkdownDescription satisfies the datasource.ConfigValidator interface. func (v *DataSourceConfigValidator) MarkdownDescription(ctx context.Context) string { if v.MarkdownDescriptionMethod == nil { return "" @@ -34,8 +34,8 @@ func (v *DataSourceConfigValidator) MarkdownDescription(ctx context.Context) str return v.MarkdownDescriptionMethod(ctx) } -// Validate satisfies the tfsdk.DataSourceConfigValidator interface. -func (v *DataSourceConfigValidator) ValidateDataSource(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { +// Validate satisfies the datasource.ConfigValidator interface. +func (v *DataSourceConfigValidator) ValidateDataSource(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { if v.ValidateDataSourceMethod == nil { return } diff --git a/internal/testing/testprovider/datasourcetype.go b/internal/testing/testprovider/datasourcetype.go index 9e7f9786e..37fc8a043 100644 --- a/internal/testing/testprovider/datasourcetype.go +++ b/internal/testing/testprovider/datasourcetype.go @@ -3,20 +3,22 @@ package testprovider import ( "context" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -var _ tfsdk.DataSourceType = &DataSourceType{} +var _ provider.DataSourceType = &DataSourceType{} -// Declarative tfsdk.DataSourceType for unit testing. +// Declarative provider.DataSourceType for unit testing. type DataSourceType struct { // DataSourceType interface methods GetSchemaMethod func(context.Context) (tfsdk.Schema, diag.Diagnostics) - NewDataSourceMethod func(context.Context, tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) + NewDataSourceMethod func(context.Context, provider.Provider) (datasource.DataSource, diag.Diagnostics) } -// GetSchema satisfies the tfsdk.DataSourceType interface. +// GetSchema satisfies the provider.DataSourceType interface. func (t *DataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { if t.GetSchemaMethod == nil { return tfsdk.Schema{}, nil @@ -25,8 +27,8 @@ func (t *DataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diag return t.GetSchemaMethod(ctx) } -// NewDataSource satisfies the tfsdk.DataSourceType interface. -func (t *DataSourceType) NewDataSource(ctx context.Context, p tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { +// NewDataSource satisfies the provider.DataSourceType interface. +func (t *DataSourceType) NewDataSource(ctx context.Context, p provider.Provider) (datasource.DataSource, diag.Diagnostics) { if t.NewDataSourceMethod == nil { return nil, nil } diff --git a/internal/testing/testprovider/datasourcewithconfigvalidators.go b/internal/testing/testprovider/datasourcewithconfigvalidators.go index 898154b86..fbe923635 100644 --- a/internal/testing/testprovider/datasourcewithconfigvalidators.go +++ b/internal/testing/testprovider/datasourcewithconfigvalidators.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource" ) -var _ tfsdk.DataSource = &DataSourceWithConfigValidators{} -var _ tfsdk.DataSourceWithConfigValidators = &DataSourceWithConfigValidators{} +var _ datasource.DataSource = &DataSourceWithConfigValidators{} +var _ datasource.DataSourceWithConfigValidators = &DataSourceWithConfigValidators{} -// Declarative tfsdk.DataSourceWithConfigValidators for unit testing. +// Declarative datasource.DataSourceWithConfigValidators for unit testing. type DataSourceWithConfigValidators struct { *DataSource // DataSourceWithConfigValidators interface methods - ConfigValidatorsMethod func(context.Context) []tfsdk.DataSourceConfigValidator + ConfigValidatorsMethod func(context.Context) []datasource.ConfigValidator } -// ConfigValidators satisfies the tfsdk.DataSourceWithConfigValidators interface. -func (p *DataSourceWithConfigValidators) ConfigValidators(ctx context.Context) []tfsdk.DataSourceConfigValidator { +// ConfigValidators satisfies the datasource.DataSourceWithConfigValidators interface. +func (p *DataSourceWithConfigValidators) ConfigValidators(ctx context.Context) []datasource.ConfigValidator { if p.ConfigValidatorsMethod == nil { return nil } diff --git a/internal/testing/testprovider/datasourcewithvalidateconfig.go b/internal/testing/testprovider/datasourcewithvalidateconfig.go index 25293e09f..2a2e94c3b 100644 --- a/internal/testing/testprovider/datasourcewithvalidateconfig.go +++ b/internal/testing/testprovider/datasourcewithvalidateconfig.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource" ) -var _ tfsdk.DataSource = &DataSourceWithValidateConfig{} -var _ tfsdk.DataSourceWithValidateConfig = &DataSourceWithValidateConfig{} +var _ datasource.DataSource = &DataSourceWithValidateConfig{} +var _ datasource.DataSourceWithValidateConfig = &DataSourceWithValidateConfig{} -// Declarative tfsdk.DataSourceWithValidateConfig for unit testing. +// Declarative datasource.DataSourceWithValidateConfig for unit testing. type DataSourceWithValidateConfig struct { *DataSource // DataSourceWithValidateConfig interface methods - ValidateConfigMethod func(context.Context, tfsdk.ValidateDataSourceConfigRequest, *tfsdk.ValidateDataSourceConfigResponse) + ValidateConfigMethod func(context.Context, datasource.ValidateConfigRequest, *datasource.ValidateConfigResponse) } -// ValidateConfig satisfies the tfsdk.DataSourceWithValidateConfig interface. -func (p *DataSourceWithValidateConfig) ValidateConfig(ctx context.Context, req tfsdk.ValidateDataSourceConfigRequest, resp *tfsdk.ValidateDataSourceConfigResponse) { +// ValidateConfig satisfies the datasource.DataSourceWithValidateConfig interface. +func (p *DataSourceWithValidateConfig) ValidateConfig(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) { if p.ValidateConfigMethod == nil { return } diff --git a/internal/testing/testprovider/provider.go b/internal/testing/testprovider/provider.go index 744b12725..4c9ce0751 100644 --- a/internal/testing/testprovider/provider.go +++ b/internal/testing/testprovider/provider.go @@ -4,22 +4,23 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -var _ tfsdk.Provider = &Provider{} +var _ provider.Provider = &Provider{} -// Declarative tfsdk.Provider for unit testing. +// Declarative provider.Provider for unit testing. type Provider struct { // Provider interface methods - ConfigureMethod func(context.Context, tfsdk.ConfigureProviderRequest, *tfsdk.ConfigureProviderResponse) - GetDataSourcesMethod func(context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) - GetResourcesMethod func(context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) + ConfigureMethod func(context.Context, provider.ConfigureRequest, *provider.ConfigureResponse) + GetDataSourcesMethod func(context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) + GetResourcesMethod func(context.Context) (map[string]provider.ResourceType, diag.Diagnostics) GetSchemaMethod func(context.Context) (tfsdk.Schema, diag.Diagnostics) } -// GetSchema satisfies the tfsdk.Provider interface. -func (p *Provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { +// GetSchema satisfies the provider.Provider interface. +func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { if p.ConfigureMethod == nil { return } @@ -27,25 +28,25 @@ func (p *Provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderReq p.ConfigureMethod(ctx, req, resp) } -// GetDataSources satisfies the tfsdk.Provider interface. -func (p *Provider) GetDataSources(ctx context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { +// GetDataSources satisfies the provider.Provider interface. +func (p *Provider) GetDataSources(ctx context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { if p.GetDataSourcesMethod == nil { - return map[string]tfsdk.DataSourceType{}, nil + return map[string]provider.DataSourceType{}, nil } return p.GetDataSourcesMethod(ctx) } -// GetResources satisfies the tfsdk.Provider interface. -func (p *Provider) GetResources(ctx context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { +// GetResources satisfies the provider.Provider interface. +func (p *Provider) GetResources(ctx context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { if p.GetResourcesMethod == nil { - return map[string]tfsdk.ResourceType{}, nil + return map[string]provider.ResourceType{}, nil } return p.GetResourcesMethod(ctx) } -// GetSchema satisfies the tfsdk.Provider interface. +// GetSchema satisfies the provider.Provider interface. func (p *Provider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { if p.GetSchemaMethod == nil { return tfsdk.Schema{}, nil diff --git a/internal/testing/testprovider/providerconfigvalidator.go b/internal/testing/testprovider/providerconfigvalidator.go index ba363a408..984c53009 100644 --- a/internal/testing/testprovider/providerconfigvalidator.go +++ b/internal/testing/testprovider/providerconfigvalidator.go @@ -3,20 +3,20 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" ) -var _ tfsdk.ProviderConfigValidator = &ProviderConfigValidator{} +var _ provider.ConfigValidator = &ProviderConfigValidator{} -// Declarative tfsdk.ProviderConfigValidator for unit testing. +// Declarative provider.ConfigValidator for unit testing. type ProviderConfigValidator struct { - // ProviderConfigValidator interface methods + // ConfigValidator interface methods DescriptionMethod func(context.Context) string MarkdownDescriptionMethod func(context.Context) string - ValidateProviderMethod func(context.Context, tfsdk.ValidateProviderConfigRequest, *tfsdk.ValidateProviderConfigResponse) + ValidateProviderMethod func(context.Context, provider.ValidateConfigRequest, *provider.ValidateConfigResponse) } -// Description satisfies the tfsdk.ProviderConfigValidator interface. +// Description satisfies the provider.ConfigValidator interface. func (v *ProviderConfigValidator) Description(ctx context.Context) string { if v.DescriptionMethod == nil { return "" @@ -25,7 +25,7 @@ func (v *ProviderConfigValidator) Description(ctx context.Context) string { return v.DescriptionMethod(ctx) } -// MarkdownDescription satisfies the tfsdk.ProviderConfigValidator interface. +// MarkdownDescription satisfies the provider.ConfigValidator interface. func (v *ProviderConfigValidator) MarkdownDescription(ctx context.Context) string { if v.MarkdownDescriptionMethod == nil { return "" @@ -34,8 +34,8 @@ func (v *ProviderConfigValidator) MarkdownDescription(ctx context.Context) strin return v.MarkdownDescriptionMethod(ctx) } -// Validate satisfies the tfsdk.ProviderConfigValidator interface. -func (v *ProviderConfigValidator) ValidateProvider(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { +// Validate satisfies the provider.ConfigValidator interface. +func (v *ProviderConfigValidator) ValidateProvider(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { if v.ValidateProviderMethod == nil { return } diff --git a/internal/testing/testprovider/providerwithconfigvalidators.go b/internal/testing/testprovider/providerwithconfigvalidators.go index e9eada770..e4294775f 100644 --- a/internal/testing/testprovider/providerwithconfigvalidators.go +++ b/internal/testing/testprovider/providerwithconfigvalidators.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" ) -var _ tfsdk.Provider = &ProviderWithConfigValidators{} -var _ tfsdk.ProviderWithConfigValidators = &ProviderWithConfigValidators{} +var _ provider.Provider = &ProviderWithConfigValidators{} +var _ provider.ProviderWithConfigValidators = &ProviderWithConfigValidators{} -// Declarative tfsdk.ProviderWithConfigValidators for unit testing. +// Declarative provider.ProviderWithConfigValidators for unit testing. type ProviderWithConfigValidators struct { *Provider // ProviderWithConfigValidators interface methods - ConfigValidatorsMethod func(context.Context) []tfsdk.ProviderConfigValidator + ConfigValidatorsMethod func(context.Context) []provider.ConfigValidator } -// GetMetaSchema satisfies the tfsdk.ProviderWithConfigValidators interface. -func (p *ProviderWithConfigValidators) ConfigValidators(ctx context.Context) []tfsdk.ProviderConfigValidator { +// GetMetaSchema satisfies the provider.ProviderWithConfigValidators interface. +func (p *ProviderWithConfigValidators) ConfigValidators(ctx context.Context) []provider.ConfigValidator { if p.ConfigValidatorsMethod == nil { return nil } diff --git a/internal/testing/testprovider/providerwithmeta.go b/internal/testing/testprovider/providerwithmeta.go index dd73863a7..93c869116 100644 --- a/internal/testing/testprovider/providerwithmeta.go +++ b/internal/testing/testprovider/providerwithmeta.go @@ -4,22 +4,23 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -var _ tfsdk.Provider = &ProviderWithProviderMeta{} -var _ tfsdk.ProviderWithProviderMeta = &ProviderWithProviderMeta{} +var _ provider.Provider = &ProviderWithMetaSchema{} +var _ provider.ProviderWithMetaSchema = &ProviderWithMetaSchema{} -// Declarative tfsdk.ProviderWithProviderMeta for unit testing. -type ProviderWithProviderMeta struct { +// Declarative provider.ProviderWithMetaSchema for unit testing. +type ProviderWithMetaSchema struct { *Provider - // ProviderWithProviderMeta interface methods + // ProviderWithMetaSchema interface methods GetMetaSchemaMethod func(context.Context) (tfsdk.Schema, diag.Diagnostics) } -// GetMetaSchema satisfies the tfsdk.ProviderWithProviderMeta interface. -func (p *ProviderWithProviderMeta) GetMetaSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { +// GetMetaSchema satisfies the provider.ProviderWithMetaSchema interface. +func (p *ProviderWithMetaSchema) GetMetaSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { if p.GetMetaSchemaMethod == nil { return tfsdk.Schema{}, nil } diff --git a/internal/testing/testprovider/providerwithvalidateconfig.go b/internal/testing/testprovider/providerwithvalidateconfig.go index b824db6cf..af29b7b7c 100644 --- a/internal/testing/testprovider/providerwithvalidateconfig.go +++ b/internal/testing/testprovider/providerwithvalidateconfig.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" ) -var _ tfsdk.Provider = &ProviderWithValidateConfig{} -var _ tfsdk.ProviderWithValidateConfig = &ProviderWithValidateConfig{} +var _ provider.Provider = &ProviderWithValidateConfig{} +var _ provider.ProviderWithValidateConfig = &ProviderWithValidateConfig{} -// Declarative tfsdk.ProviderWithValidateConfig for unit testing. +// Declarative provider.ProviderWithValidateConfig for unit testing. type ProviderWithValidateConfig struct { *Provider // ProviderWithValidateConfig interface methods - ValidateConfigMethod func(context.Context, tfsdk.ValidateProviderConfigRequest, *tfsdk.ValidateProviderConfigResponse) + ValidateConfigMethod func(context.Context, provider.ValidateConfigRequest, *provider.ValidateConfigResponse) } -// GetMetaSchema satisfies the tfsdk.ProviderWithValidateConfig interface. -func (p *ProviderWithValidateConfig) ValidateConfig(ctx context.Context, req tfsdk.ValidateProviderConfigRequest, resp *tfsdk.ValidateProviderConfigResponse) { +// GetMetaSchema satisfies the provider.ProviderWithValidateConfig interface. +func (p *ProviderWithValidateConfig) ValidateConfig(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) { if p.ValidateConfigMethod == nil { return } diff --git a/internal/testing/testprovider/resource.go b/internal/testing/testprovider/resource.go index 6cbc7f293..194e6666a 100644 --- a/internal/testing/testprovider/resource.go +++ b/internal/testing/testprovider/resource.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &Resource{} +var _ resource.Resource = &Resource{} -// Declarative tfsdk.Resource for unit testing. +// Declarative resource.Resource for unit testing. type Resource struct { // Resource interface methods - CreateMethod func(context.Context, tfsdk.CreateResourceRequest, *tfsdk.CreateResourceResponse) - DeleteMethod func(context.Context, tfsdk.DeleteResourceRequest, *tfsdk.DeleteResourceResponse) - ReadMethod func(context.Context, tfsdk.ReadResourceRequest, *tfsdk.ReadResourceResponse) - UpdateMethod func(context.Context, tfsdk.UpdateResourceRequest, *tfsdk.UpdateResourceResponse) + CreateMethod func(context.Context, resource.CreateRequest, *resource.CreateResponse) + DeleteMethod func(context.Context, resource.DeleteRequest, *resource.DeleteResponse) + ReadMethod func(context.Context, resource.ReadRequest, *resource.ReadResponse) + UpdateMethod func(context.Context, resource.UpdateRequest, *resource.UpdateResponse) } -// Create satisfies the tfsdk.Resource interface. -func (r *Resource) Create(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { +// Create satisfies the resource.Resource interface. +func (r *Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { if r.CreateMethod == nil { return } @@ -26,8 +26,8 @@ func (r *Resource) Create(ctx context.Context, req tfsdk.CreateResourceRequest, r.CreateMethod(ctx, req, resp) } -// Delete satisfies the tfsdk.Resource interface. -func (r *Resource) Delete(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) { +// Delete satisfies the resource.Resource interface. +func (r *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { if r.DeleteMethod == nil { return } @@ -35,8 +35,8 @@ func (r *Resource) Delete(ctx context.Context, req tfsdk.DeleteResourceRequest, r.DeleteMethod(ctx, req, resp) } -// Read satisfies the tfsdk.Resource interface. -func (r *Resource) Read(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { +// Read satisfies the resource.Resource interface. +func (r *Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { if r.ReadMethod == nil { return } @@ -44,8 +44,8 @@ func (r *Resource) Read(ctx context.Context, req tfsdk.ReadResourceRequest, resp r.ReadMethod(ctx, req, resp) } -// Update satisfies the tfsdk.Resource interface. -func (r *Resource) Update(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) { +// Update satisfies the resource.Resource interface. +func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { if r.UpdateMethod == nil { return } diff --git a/internal/testing/testprovider/resourceconfigvalidator.go b/internal/testing/testprovider/resourceconfigvalidator.go index 3ec939649..0ec358452 100644 --- a/internal/testing/testprovider/resourceconfigvalidator.go +++ b/internal/testing/testprovider/resourceconfigvalidator.go @@ -3,20 +3,20 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.ResourceConfigValidator = &ResourceConfigValidator{} +var _ resource.ConfigValidator = &ResourceConfigValidator{} -// Declarative tfsdk.ResourceConfigValidator for unit testing. +// Declarative resource.ConfigValidator for unit testing. type ResourceConfigValidator struct { // ResourceConfigValidator interface methods DescriptionMethod func(context.Context) string MarkdownDescriptionMethod func(context.Context) string - ValidateResourceMethod func(context.Context, tfsdk.ValidateResourceConfigRequest, *tfsdk.ValidateResourceConfigResponse) + ValidateResourceMethod func(context.Context, resource.ValidateConfigRequest, *resource.ValidateConfigResponse) } -// Description satisfies the tfsdk.ResourceConfigValidator interface. +// Description satisfies the resource.ConfigValidator interface. func (v *ResourceConfigValidator) Description(ctx context.Context) string { if v.DescriptionMethod == nil { return "" @@ -25,7 +25,7 @@ func (v *ResourceConfigValidator) Description(ctx context.Context) string { return v.DescriptionMethod(ctx) } -// MarkdownDescription satisfies the tfsdk.ResourceConfigValidator interface. +// MarkdownDescription satisfies the resource.ConfigValidator interface. func (v *ResourceConfigValidator) MarkdownDescription(ctx context.Context) string { if v.MarkdownDescriptionMethod == nil { return "" @@ -34,8 +34,8 @@ func (v *ResourceConfigValidator) MarkdownDescription(ctx context.Context) strin return v.MarkdownDescriptionMethod(ctx) } -// Validate satisfies the tfsdk.ResourceConfigValidator interface. -func (v *ResourceConfigValidator) ValidateResource(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { +// Validate satisfies the resource.ConfigValidator interface. +func (v *ResourceConfigValidator) ValidateResource(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { if v.ValidateResourceMethod == nil { return } diff --git a/internal/testing/testprovider/resourcetype.go b/internal/testing/testprovider/resourcetype.go index f3a7b9525..fdc1a76f7 100644 --- a/internal/testing/testprovider/resourcetype.go +++ b/internal/testing/testprovider/resourcetype.go @@ -4,19 +4,21 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -var _ tfsdk.ResourceType = &ResourceType{} +var _ provider.ResourceType = &ResourceType{} -// Declarative tfsdk.ResourceType for unit testing. +// Declarative provider.ResourceType for unit testing. type ResourceType struct { // ResourceType interface methods GetSchemaMethod func(context.Context) (tfsdk.Schema, diag.Diagnostics) - NewResourceMethod func(context.Context, tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) + NewResourceMethod func(context.Context, provider.Provider) (resource.Resource, diag.Diagnostics) } -// GetSchema satisfies the tfsdk.ResourceType interface. +// GetSchema satisfies the provider.ResourceType interface. func (t *ResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { if t.GetSchemaMethod == nil { return tfsdk.Schema{}, nil @@ -25,8 +27,8 @@ func (t *ResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagno return t.GetSchemaMethod(ctx) } -// NewResource satisfies the tfsdk.ResourceType interface. -func (t *ResourceType) NewResource(ctx context.Context, p tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { +// NewResource satisfies the provider.ResourceType interface. +func (t *ResourceType) NewResource(ctx context.Context, p provider.Provider) (resource.Resource, diag.Diagnostics) { if t.NewResourceMethod == nil { return nil, nil } diff --git a/internal/testing/testprovider/resourcewithconfigvalidators.go b/internal/testing/testprovider/resourcewithconfigvalidators.go index 7efb83bc7..bae123a3f 100644 --- a/internal/testing/testprovider/resourcewithconfigvalidators.go +++ b/internal/testing/testprovider/resourcewithconfigvalidators.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &ResourceWithConfigValidators{} -var _ tfsdk.ResourceWithConfigValidators = &ResourceWithConfigValidators{} +var _ resource.Resource = &ResourceWithConfigValidators{} +var _ resource.ResourceWithConfigValidators = &ResourceWithConfigValidators{} -// Declarative tfsdk.ResourceWithConfigValidators for unit testing. +// Declarative resource.ResourceWithConfigValidators for unit testing. type ResourceWithConfigValidators struct { *Resource // ResourceWithConfigValidators interface methods - ConfigValidatorsMethod func(context.Context) []tfsdk.ResourceConfigValidator + ConfigValidatorsMethod func(context.Context) []resource.ConfigValidator } -// ConfigValidators satisfies the tfsdk.ResourceWithConfigValidators interface. -func (p *ResourceWithConfigValidators) ConfigValidators(ctx context.Context) []tfsdk.ResourceConfigValidator { +// ConfigValidators satisfies the resource.ResourceWithConfigValidators interface. +func (p *ResourceWithConfigValidators) ConfigValidators(ctx context.Context) []resource.ConfigValidator { if p.ConfigValidatorsMethod == nil { return nil } diff --git a/internal/testing/testprovider/resourcewithimportstate.go b/internal/testing/testprovider/resourcewithimportstate.go index a18b33e44..cd36c88aa 100644 --- a/internal/testing/testprovider/resourcewithimportstate.go +++ b/internal/testing/testprovider/resourcewithimportstate.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &ResourceWithImportState{} -var _ tfsdk.ResourceWithImportState = &ResourceWithImportState{} +var _ resource.Resource = &ResourceWithImportState{} +var _ resource.ResourceWithImportState = &ResourceWithImportState{} -// Declarative tfsdk.ResourceWithImportState for unit testing. +// Declarative resource.ResourceWithImportState for unit testing. type ResourceWithImportState struct { *Resource // ResourceWithImportState interface methods - ImportStateMethod func(context.Context, tfsdk.ImportResourceStateRequest, *tfsdk.ImportResourceStateResponse) + ImportStateMethod func(context.Context, resource.ImportStateRequest, *resource.ImportStateResponse) } -// ImportState satisfies the tfsdk.ResourceWithImportState interface. -func (p *ResourceWithImportState) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { +// ImportState satisfies the resource.ResourceWithImportState interface. +func (p *ResourceWithImportState) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { if p.ImportStateMethod == nil { return } diff --git a/internal/testing/testprovider/resourcewithmodifyplan.go b/internal/testing/testprovider/resourcewithmodifyplan.go index 9b2309ec9..ef7df89e8 100644 --- a/internal/testing/testprovider/resourcewithmodifyplan.go +++ b/internal/testing/testprovider/resourcewithmodifyplan.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &ResourceWithModifyPlan{} -var _ tfsdk.ResourceWithModifyPlan = &ResourceWithModifyPlan{} +var _ resource.Resource = &ResourceWithModifyPlan{} +var _ resource.ResourceWithModifyPlan = &ResourceWithModifyPlan{} -// Declarative tfsdk.ResourceWithModifyPlan for unit testing. +// Declarative resource.ResourceWithModifyPlan for unit testing. type ResourceWithModifyPlan struct { *Resource // ResourceWithModifyPlan interface methods - ModifyPlanMethod func(context.Context, tfsdk.ModifyResourcePlanRequest, *tfsdk.ModifyResourcePlanResponse) + ModifyPlanMethod func(context.Context, resource.ModifyPlanRequest, *resource.ModifyPlanResponse) } -// ModifyPlan satisfies the tfsdk.ResourceWithModifyPlan interface. -func (p *ResourceWithModifyPlan) ModifyPlan(ctx context.Context, req tfsdk.ModifyResourcePlanRequest, resp *tfsdk.ModifyResourcePlanResponse) { +// ModifyPlan satisfies the resource.ResourceWithModifyPlan interface. +func (p *ResourceWithModifyPlan) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { if p.ModifyPlanMethod == nil { return } diff --git a/internal/testing/testprovider/resourcewithupgradestate.go b/internal/testing/testprovider/resourcewithupgradestate.go index 08c313f6f..f3a93e959 100644 --- a/internal/testing/testprovider/resourcewithupgradestate.go +++ b/internal/testing/testprovider/resourcewithupgradestate.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &ResourceWithUpgradeState{} -var _ tfsdk.ResourceWithUpgradeState = &ResourceWithUpgradeState{} +var _ resource.Resource = &ResourceWithUpgradeState{} +var _ resource.ResourceWithUpgradeState = &ResourceWithUpgradeState{} -// Declarative tfsdk.ResourceWithUpgradeState for unit testing. +// Declarative resource.ResourceWithUpgradeState for unit testing. type ResourceWithUpgradeState struct { *Resource // ResourceWithUpgradeState interface methods - UpgradeStateMethod func(context.Context) map[int64]tfsdk.ResourceStateUpgrader + UpgradeStateMethod func(context.Context) map[int64]resource.StateUpgrader } -// UpgradeState satisfies the tfsdk.ResourceWithUpgradeState interface. -func (p *ResourceWithUpgradeState) UpgradeState(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { +// UpgradeState satisfies the resource.ResourceWithUpgradeState interface. +func (p *ResourceWithUpgradeState) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { if p.UpgradeStateMethod == nil { return nil } diff --git a/internal/testing/testprovider/resourcewithvalidateconfig.go b/internal/testing/testprovider/resourcewithvalidateconfig.go index 81dc18b98..28af85967 100644 --- a/internal/testing/testprovider/resourcewithvalidateconfig.go +++ b/internal/testing/testprovider/resourcewithvalidateconfig.go @@ -3,22 +3,22 @@ package testprovider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ tfsdk.Resource = &ResourceWithValidateConfig{} -var _ tfsdk.ResourceWithValidateConfig = &ResourceWithValidateConfig{} +var _ resource.Resource = &ResourceWithValidateConfig{} +var _ resource.ResourceWithValidateConfig = &ResourceWithValidateConfig{} -// Declarative tfsdk.ResourceWithValidateConfig for unit testing. +// Declarative resource.ResourceWithValidateConfig for unit testing. type ResourceWithValidateConfig struct { *Resource // ResourceWithValidateConfig interface methods - ValidateConfigMethod func(context.Context, tfsdk.ValidateResourceConfigRequest, *tfsdk.ValidateResourceConfigResponse) + ValidateConfigMethod func(context.Context, resource.ValidateConfigRequest, *resource.ValidateConfigResponse) } -// ValidateConfig satisfies the tfsdk.ResourceWithValidateConfig interface. -func (p *ResourceWithValidateConfig) ValidateConfig(ctx context.Context, req tfsdk.ValidateResourceConfigRequest, resp *tfsdk.ValidateResourceConfigResponse) { +// ValidateConfig satisfies the resource.ResourceWithValidateConfig interface. +func (p *ResourceWithValidateConfig) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { if p.ValidateConfigMethod == nil { return } diff --git a/internal/toproto5/configureprovider.go b/internal/toproto5/configureprovider.go index 553113e07..1c8b8cb65 100644 --- a/internal/toproto5/configureprovider.go +++ b/internal/toproto5/configureprovider.go @@ -3,13 +3,13 @@ package toproto5 import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) // ConfigureProviderResponse returns the *tfprotov5.ConfigureProviderResponse // equivalent of a *fwserver.ConfigureProviderResponse. -func ConfigureProviderResponse(ctx context.Context, fw *tfsdk.ConfigureProviderResponse) *tfprotov5.ConfigureProviderResponse { +func ConfigureProviderResponse(ctx context.Context, fw *provider.ConfigureResponse) *tfprotov5.ConfigureProviderResponse { if fw == nil { return nil } diff --git a/internal/toproto5/configureprovider_test.go b/internal/toproto5/configureprovider_test.go index 010aec4bc..015b2aaa0 100644 --- a/internal/toproto5/configureprovider_test.go +++ b/internal/toproto5/configureprovider_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/toproto5" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov5" ) @@ -15,7 +15,7 @@ func TestConfigureProviderResponse(t *testing.T) { t.Parallel() testCases := map[string]struct { - input *tfsdk.ConfigureProviderResponse + input *provider.ConfigureResponse expected *tfprotov5.ConfigureProviderResponse }{ "nil": { @@ -23,11 +23,11 @@ func TestConfigureProviderResponse(t *testing.T) { expected: nil, }, "empty": { - input: &tfsdk.ConfigureProviderResponse{}, + input: &provider.ConfigureResponse{}, expected: &tfprotov5.ConfigureProviderResponse{}, }, "diagnostics": { - input: &tfsdk.ConfigureProviderResponse{ + input: &provider.ConfigureResponse{ Diagnostics: diag.Diagnostics{ diag.NewWarningDiagnostic("test warning summary", "test warning details"), diag.NewErrorDiagnostic("test error summary", "test error details"), diff --git a/internal/toproto6/configureprovider.go b/internal/toproto6/configureprovider.go index e507068d0..66c2a3555 100644 --- a/internal/toproto6/configureprovider.go +++ b/internal/toproto6/configureprovider.go @@ -3,13 +3,13 @@ package toproto6 import ( "context" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) // ConfigureProviderResponse returns the *tfprotov6.ConfigureProviderResponse // equivalent of a *fwserver.ConfigureProviderResponse. -func ConfigureProviderResponse(ctx context.Context, fw *tfsdk.ConfigureProviderResponse) *tfprotov6.ConfigureProviderResponse { +func ConfigureProviderResponse(ctx context.Context, fw *provider.ConfigureResponse) *tfprotov6.ConfigureProviderResponse { if fw == nil { return nil } diff --git a/internal/toproto6/configureprovider_test.go b/internal/toproto6/configureprovider_test.go index 8427178dd..a9b9fa9e1 100644 --- a/internal/toproto6/configureprovider_test.go +++ b/internal/toproto6/configureprovider_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/toproto6" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) @@ -15,7 +15,7 @@ func TestConfigureProviderResponse(t *testing.T) { t.Parallel() testCases := map[string]struct { - input *tfsdk.ConfigureProviderResponse + input *provider.ConfigureResponse expected *tfprotov6.ConfigureProviderResponse }{ "nil": { @@ -23,11 +23,11 @@ func TestConfigureProviderResponse(t *testing.T) { expected: nil, }, "empty": { - input: &tfsdk.ConfigureProviderResponse{}, + input: &provider.ConfigureResponse{}, expected: &tfprotov6.ConfigureProviderResponse{}, }, "diagnostics": { - input: &tfsdk.ConfigureProviderResponse{ + input: &provider.ConfigureResponse{ Diagnostics: diag.Diagnostics{ diag.NewWarningDiagnostic("test warning summary", "test warning details"), diag.NewErrorDiagnostic("test error summary", "test error details"), diff --git a/provider/config_validator.go b/provider/config_validator.go new file mode 100644 index 000000000..3c3004476 --- /dev/null +++ b/provider/config_validator.go @@ -0,0 +1,25 @@ +package provider + +import "context" + +// ConfigValidator describes reusable Provider configuration validation functionality. +type ConfigValidator interface { + // Description describes the validation in plain text formatting. + // + // This information may be automatically added to provider plain text + // descriptions by external tooling. + Description(context.Context) string + + // MarkdownDescription describes the validation in Markdown formatting. + // + // This information may be automatically added to provider Markdown + // descriptions by external tooling. + MarkdownDescription(context.Context) string + + // ValidateProvider performs the validation. + // + // This method name is separate from the ConfigValidator + // interface ValidateDataSource method name and ResourceConfigValidator + // interface ValidateResource method name to allow generic validators. + ValidateProvider(context.Context, ValidateConfigRequest, *ValidateConfigResponse) +} diff --git a/provider/configure.go b/provider/configure.go new file mode 100644 index 000000000..29a41271a --- /dev/null +++ b/provider/configure.go @@ -0,0 +1,35 @@ +package provider + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ConfigureRequest represents a request containing the values the user +// specified for the provider configuration block, along with other runtime +// information from Terraform or the Plugin SDK. An instance of this request +// struct is supplied as an argument to the provider's Configure function. +type ConfigureRequest struct { + // TerraformVersion is the version of Terraform executing the request. + // This is supplied for logging, analytics, and User-Agent purposes + // only. Providers should not try to gate provider behavior on + // Terraform versions. + TerraformVersion string + + // Config is the configuration the user supplied for the provider. This + // information should usually be persisted to the underlying type + // that's implementing the Provider interface, for use in later + // resource CRUD operations. + Config tfsdk.Config +} + +// ConfigureResponse represents a response to a +// ConfigureRequest. An instance of this response struct is supplied as +// an argument to the provider's Configure function, in which the provider +// should set values on the ConfigureResponse as appropriate. +type ConfigureResponse struct { + // Diagnostics report errors or warnings related to configuring the + // provider. An empty slice indicates success, with no warnings or + // errors generated. + Diagnostics diag.Diagnostics +} diff --git a/provider/data_source_type.go b/provider/data_source_type.go new file mode 100644 index 000000000..e43193fd8 --- /dev/null +++ b/provider/data_source_type.go @@ -0,0 +1,20 @@ +package provider + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// A DataSourceType is a type of data source. For each type of data source this +// provider supports, it should define a type implementing DataSourceType and +// return an instance of it in the map returned by Provider.GetDataSources. +type DataSourceType interface { + // GetSchema returns the schema for this data source. + GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) + + // NewDataSource instantiates a new DataSource of this DataSourceType. + NewDataSource(context.Context, Provider) (datasource.DataSource, diag.Diagnostics) +} diff --git a/provider/doc.go b/provider/doc.go new file mode 100644 index 000000000..e39c5b235 --- /dev/null +++ b/provider/doc.go @@ -0,0 +1,3 @@ +// Package provider contains all interfaces, request types, and response +// types for a provider implementation. +package provider diff --git a/tfsdk/provider.go b/provider/provider.go similarity index 52% rename from tfsdk/provider.go rename to provider/provider.go index c5f5efcee..d330539a2 100644 --- a/tfsdk/provider.go +++ b/provider/provider.go @@ -1,16 +1,17 @@ -package tfsdk +package provider import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) // Provider is the core interface that all Terraform providers must implement. type Provider interface { // GetSchema returns the schema for this provider's configuration. If // this provider has no configuration, return an empty schema.Schema. - GetSchema(context.Context) (Schema, diag.Diagnostics) + GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) // Configure is called at the beginning of the provider lifecycle, when // Terraform sends to the provider the values the user specified in the @@ -19,7 +20,7 @@ type Provider interface { // Values from provider configuration are often used to initialise an // API client, which should be stored on the struct implementing the // Provider interface. - Configure(context.Context, ConfigureProviderRequest, *ConfigureProviderResponse) + Configure(context.Context, ConfigureRequest, *ConfigureResponse) // GetResources returns a mapping of resource names to type // implementations. @@ -40,12 +41,43 @@ type Provider interface { GetDataSources(context.Context) (map[string]DataSourceType, diag.Diagnostics) } -// ProviderWithProviderMeta is a provider with a provider meta schema. +// ProviderWithConfigValidators is an interface type that extends Provider to include declarative validations. +// +// Declaring validation using this methodology simplifies implementation of +// reusable functionality. These also include descriptions, which can be used +// for automating documentation. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type ProviderWithConfigValidators interface { + Provider + + // ConfigValidators returns a list of functions which will all be performed during validation. + ConfigValidators(context.Context) []ConfigValidator +} + +// ProviderWithMetaSchema is a provider with a provider meta schema. // This functionality is currently experimental and subject to change or break // without warning; it should only be used by providers that are collaborating // on its use with the Terraform team. -type ProviderWithProviderMeta interface { +type ProviderWithMetaSchema interface { Provider + // GetMetaSchema returns the provider meta schema. - GetMetaSchema(context.Context) (Schema, diag.Diagnostics) + GetMetaSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) +} + +// ProviderWithValidateConfig is an interface type that extends Provider to include imperative validation. +// +// Declaring validation using this methodology simplifies one-off +// functionality that typically applies to a single provider. Any documentation +// of this functionality must be manually added into schema descriptions. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type ProviderWithValidateConfig interface { + Provider + + // ValidateConfig performs the validation. + ValidateConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse) } diff --git a/provider/resource_type.go b/provider/resource_type.go new file mode 100644 index 000000000..b6a7fb01b --- /dev/null +++ b/provider/resource_type.go @@ -0,0 +1,20 @@ +package provider + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// A ResourceType is a type of resource. For each type of resource this provider +// supports, it should define a type implementing ResourceType and return an +// instance of it in the map returned by Provider.GetResources. +type ResourceType interface { + // GetSchema returns the schema for this resource. + GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) + + // NewResource instantiates a new Resource of this ResourceType. + NewResource(context.Context, Provider) (resource.Resource, diag.Diagnostics) +} diff --git a/provider/validate_config.go b/provider/validate_config.go new file mode 100644 index 000000000..2102f3f13 --- /dev/null +++ b/provider/validate_config.go @@ -0,0 +1,30 @@ +package provider + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ValidateConfigRequest represents a request to validate the +// configuration of a provider. An instance of this request struct is +// supplied as an argument to the Provider ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigRequest struct { + // Config is the configuration the user supplied for the provider. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config +} + +// ValidateConfigResponse represents a response to a +// ValidateConfigRequest. An instance of this response struct is +// supplied as an argument to the Provider ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigResponse struct { + // Diagnostics report errors or warnings related to validating the provider + // configuration. An empty slice indicates success, with no warnings or + // errors generated. + Diagnostics diag.Diagnostics +} diff --git a/providerserver/providerserver.go b/providerserver/providerserver.go index 39798724f..920bebef9 100644 --- a/providerserver/providerserver.go +++ b/providerserver/providerserver.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwserver" "github.com/hashicorp/terraform-plugin-framework/internal/proto5server" "github.com/hashicorp/terraform-plugin-framework/internal/proto6server" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -18,7 +18,7 @@ import ( // based on the given Provider and suitable for usage with the // github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.Serve() // function and various terraform-plugin-mux functions. -func NewProtocol5(p tfsdk.Provider) func() tfprotov5.ProviderServer { +func NewProtocol5(p provider.Provider) func() tfprotov5.ProviderServer { return func() tfprotov5.ProviderServer { return &proto5server.Server{ FrameworkServer: fwserver.Server{ @@ -33,7 +33,7 @@ func NewProtocol5(p tfsdk.Provider) func() tfprotov5.ProviderServer { // github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.TestCase.ProtoV5ProviderFactories. // // The error return is not currently used, but it may be in the future. -func NewProtocol5WithError(p tfsdk.Provider) func() (tfprotov5.ProviderServer, error) { +func NewProtocol5WithError(p provider.Provider) func() (tfprotov5.ProviderServer, error) { return func() (tfprotov5.ProviderServer, error) { return &proto5server.Server{ FrameworkServer: fwserver.Server{ @@ -47,7 +47,7 @@ func NewProtocol5WithError(p tfsdk.Provider) func() (tfprotov5.ProviderServer, e // based on the given Provider and suitable for usage with the // github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.Serve() // function and various terraform-plugin-mux functions. -func NewProtocol6(p tfsdk.Provider) func() tfprotov6.ProviderServer { +func NewProtocol6(p provider.Provider) func() tfprotov6.ProviderServer { return func() tfprotov6.ProviderServer { return &proto6server.Server{ FrameworkServer: fwserver.Server{ @@ -62,7 +62,7 @@ func NewProtocol6(p tfsdk.Provider) func() tfprotov6.ProviderServer { // github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.TestCase.ProtoV6ProviderFactories. // // The error return is not currently used, but it may be in the future. -func NewProtocol6WithError(p tfsdk.Provider) func() (tfprotov6.ProviderServer, error) { +func NewProtocol6WithError(p provider.Provider) func() (tfprotov6.ProviderServer, error) { return func() (tfprotov6.ProviderServer, error) { return &proto6server.Server{ FrameworkServer: fwserver.Server{ @@ -73,7 +73,7 @@ func NewProtocol6WithError(p tfsdk.Provider) func() (tfprotov6.ProviderServer, e } // Serve serves a provider, blocking until the context is canceled. -func Serve(ctx context.Context, providerFunc func() tfsdk.Provider, opts ServeOpts) error { +func Serve(ctx context.Context, providerFunc func() provider.Provider, opts ServeOpts) error { err := opts.validate(ctx) if err != nil { diff --git a/resource/config_validator.go b/resource/config_validator.go new file mode 100644 index 000000000..217a54c0e --- /dev/null +++ b/resource/config_validator.go @@ -0,0 +1,25 @@ +package resource + +import "context" + +// ConfigValidator describes reusable Resource configuration validation functionality. +type ConfigValidator interface { + // Description describes the validation in plain text formatting. + // + // This information may be automatically added to resource plain text + // descriptions by external tooling. + Description(context.Context) string + + // MarkdownDescription describes the validation in Markdown formatting. + // + // This information may be automatically added to resource Markdown + // descriptions by external tooling. + MarkdownDescription(context.Context) string + + // ValidateResource performs the validation. + // + // This method name is separate from the datasource.ConfigValidator + // interface ValidateDataSource method name and provider.ConfigValidator + // interface ValidateProvider method name to allow generic validators. + ValidateResource(context.Context, ValidateConfigRequest, *ValidateConfigResponse) +} diff --git a/resource/create.go b/resource/create.go new file mode 100644 index 000000000..d7f304ca7 --- /dev/null +++ b/resource/create.go @@ -0,0 +1,40 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// CreateRequest represents a request for the provider to create a +// resource. An instance of this request struct is supplied as an argument to +// the resource's Create function. +type CreateRequest struct { + // Config is the configuration the user supplied for the resource. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config + + // Plan is the planned state for the resource. + Plan tfsdk.Plan + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// CreateResponse represents a response to a CreateRequest. An +// instance of this response struct is supplied as +// an argument to the resource's Create function, in which the provider +// should set values on the CreateResponse as appropriate. +type CreateResponse struct { + // State is the state of the resource following the Create operation. + // This field is pre-populated from CreateRequest.Plan and + // should be set during the resource's Create operation. + State tfsdk.State + + // Diagnostics report errors or warnings related to creating the + // resource. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/resource/delete.go b/resource/delete.go new file mode 100644 index 000000000..6ce30b24a --- /dev/null +++ b/resource/delete.go @@ -0,0 +1,34 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// DeleteRequest represents a request for the provider to delete a +// resource. An instance of this request struct is supplied as an argument to +// the resource's Delete function. +type DeleteRequest struct { + // State is the current state of the resource prior to the Delete + // operation. + State tfsdk.State + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// DeleteResponse represents a response to a DeleteRequest. An +// instance of this response struct is supplied as +// an argument to the resource's Delete function, in which the provider +// should set values on the DeleteResponse as appropriate. +type DeleteResponse struct { + // State is the state of the resource following the Delete operation. + // This field is pre-populated from UpdateResourceRequest.Plan and + // should be set during the resource's Update operation. + State tfsdk.State + + // Diagnostics report errors or warnings related to deleting the + // resource. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/resource/doc.go b/resource/doc.go new file mode 100644 index 000000000..e76624bf2 --- /dev/null +++ b/resource/doc.go @@ -0,0 +1,3 @@ +// Package resource contains all interfaces, request types, and response types +// for a managed resource implementation. +package resource diff --git a/resource/import_state.go b/resource/import_state.go new file mode 100644 index 000000000..e6026faff --- /dev/null +++ b/resource/import_state.go @@ -0,0 +1,53 @@ +package resource + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ImportStateRequest represents a request for the provider to import a +// resource. An instance of this request struct is supplied as an argument to +// the Resource's ImportState method. +type ImportStateRequest struct { + // ID represents the import identifier supplied by the practitioner when + // calling the import command. In many cases, this may align with the + // unique identifier for the resource, which can optionally be stored + // as an Attribute. However, this identifier can also be treated as + // its own type of value and parsed during import. This value + // is not stored in the state unless the provider explicitly stores it. + ID string +} + +// ImportStateResponse represents a response to a ImportStateRequest. +// An instance of this response struct is supplied as an argument to the +// Resource's ImportState method, in which the provider should set values on +// the ImportStateResponse as appropriate. +type ImportStateResponse struct { + // Diagnostics report errors or warnings related to importing the + // resource. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics + + // State is the state of the resource following the import operation. + // It must contain enough information so Terraform can successfully + // refresh the resource, e.g. call the Resource Read method. + State tfsdk.State +} + +// ImportStatePassthroughID is a helper function to set the import +// identifier to a given state attribute path. The attribute must accept a +// string value. +func ImportStatePassthroughID(ctx context.Context, attrPath path.Path, req ImportStateRequest, resp *ImportStateResponse) { + if attrPath.Equal(path.Empty()) { + resp.Diagnostics.AddError( + "Resource Import Passthrough Missing Attribute Path", + "This is always an error in the provider. Please report the following to the provider developer:\n\n"+ + "Resource ImportState method call to ImportStatePassthroughID path must be set to a valid attribute path that can accept a string value.", + ) + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, attrPath, req.ID)...) +} diff --git a/resource/modify_plan.go b/resource/modify_plan.go new file mode 100644 index 000000000..d3c300aec --- /dev/null +++ b/resource/modify_plan.go @@ -0,0 +1,48 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ModifyPlanRequest represents a request for the provider to modify the +// planned new state that Terraform has generated for the resource. +type ModifyPlanRequest struct { + // Config is the configuration the user supplied for the resource. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config + + // State is the current state of the resource. + State tfsdk.State + + // Plan is the planned new state for the resource. + Plan tfsdk.Plan + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// ModifyPlanResponse represents a response to a +// ModifyPlanRequest. An instance of this response struct is supplied +// as an argument to the resource's ModifyPlan function, in which the provider +// should modify the Plan and populate the RequiresReplace field as appropriate. +type ModifyPlanResponse struct { + // Plan is the planned new state for the resource. + Plan tfsdk.Plan + + // RequiresReplace is a list of attribute paths that require the + // resource to be replaced. They should point to the specific field + // that changed that requires the resource to be destroyed and + // recreated. + RequiresReplace path.Paths + + // Diagnostics report errors or warnings related to determining the + // planned state of the requested resource. Returning an empty slice + // indicates a successful plan modification with no warnings or errors + // generated. + Diagnostics diag.Diagnostics +} diff --git a/resource/read.go b/resource/read.go new file mode 100644 index 000000000..01b302c51 --- /dev/null +++ b/resource/read.go @@ -0,0 +1,35 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ReadRequest represents a request for the provider to read a +// resource, i.e., update values in state according to the real state of the +// resource. An instance of this request struct is supplied as an argument to +// the resource's Read function. +type ReadRequest struct { + // State is the current state of the resource prior to the Read + // operation. + State tfsdk.State + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// ReadResponse represents a response to a ReadRequest. An +// instance of this response struct is supplied as +// an argument to the resource's Read function, in which the provider +// should set values on the ReadResponse as appropriate. +type ReadResponse struct { + // State is the state of the resource following the Read operation. + // This field is pre-populated from ReadRequest.State and + // should be set during the resource's Read operation. + State tfsdk.State + + // Diagnostics report errors or warnings related to reading the + // resource. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/resource/resource.go b/resource/resource.go new file mode 100644 index 000000000..571510db9 --- /dev/null +++ b/resource/resource.go @@ -0,0 +1,134 @@ +package resource + +import ( + "context" +) + +// Resource represents a resource instance. This is the core interface that all +// resources must implement. +// +// It is also conventional for resources to implement the +// ResourceWithImportState interface, which enables practitioners to import +// existing infrastructure into Terraform. +type Resource interface { + // Create is called when the provider must create a new resource. Config + // and planned state values should be read from the + // CreateRequest and new state values set on the CreateResponse. + Create(context.Context, CreateRequest, *CreateResponse) + + // Read is called when the provider must read resource values in order + // to update state. Planned state values should be read from the + // ReadRequest and new state values set on the ReadResponse. + Read(context.Context, ReadRequest, *ReadResponse) + + // Update is called to update the state of the resource. Config, planned + // state, and prior state values should be read from the + // UpdateRequest and new state values set on the UpdateResponse. + Update(context.Context, UpdateRequest, *UpdateResponse) + + // Delete is called when the provider must delete the resource. Config + // values may be read from the DeleteRequest. + // + // If execution completes without error, the framework will automatically + // call DeleteResponse.State.RemoveResource(), so it can be omitted + // from provider logic. + Delete(context.Context, DeleteRequest, *DeleteResponse) +} + +// ResourceWithConfigValidators is an interface type that extends Resource to include declarative validations. +// +// Declaring validation using this methodology simplifies implmentation of +// reusable functionality. These also include descriptions, which can be used +// for automating documentation. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type ResourceWithConfigValidators interface { + Resource + + // ConfigValidators returns a list of functions which will all be performed during validation. + ConfigValidators(context.Context) []ConfigValidator +} + +// Optional interface on top of Resource that enables provider control over +// the ImportResourceState RPC. This RPC is called by Terraform when the +// `terraform import` command is executed. Afterwards, the ReadResource RPC +// is executed to allow providers to fully populate the resource state. +type ResourceWithImportState interface { + Resource + + // ImportState is called when the provider must import the state of a + // resource instance. This method must return enough state so the Read + // method can properly refresh the full resource. + // + // If setting an attribute with the import identifier, it is recommended + // to use the ImportStatePassthroughID() call in this method. + ImportState(context.Context, ImportStateRequest, *ImportStateResponse) +} + +// ResourceWithModifyPlan represents a resource instance with a ModifyPlan +// function. +type ResourceWithModifyPlan interface { + Resource + + // ModifyPlan is called when the provider has an opportunity to modify + // the plan: once during the plan phase when Terraform is determining + // the diff that should be shown to the user for approval, and once + // during the apply phase with any unknown values from configuration + // filled in with their final values. + // + // The planned new state is represented by + // ModifyPlanResponse.Plan. It must meet the following + // constraints: + // 1. Any non-Computed attribute set in config must preserve the exact + // config value or return the corresponding attribute value from the + // prior state (ModifyPlanRequest.State). + // 2. Any attribute with a known value must not have its value changed + // in subsequent calls to ModifyPlan or Create/Read/Update. + // 3. Any attribute with an unknown value may either remain unknown + // or take on any value of the expected type. + // + // Any errors will prevent further resource-level plan modifications. + ModifyPlan(context.Context, ModifyPlanRequest, *ModifyPlanResponse) +} + +// Optional interface on top of Resource that enables provider control over +// the UpgradeResourceState RPC. This RPC is automatically called by Terraform +// when the current Schema type Version field is greater than the stored state. +// Terraform does not store previous Schema information, so any breaking +// changes to state data types must be handled by providers. +// +// Terraform CLI can execute the UpgradeResourceState RPC even when the prior +// state version matches the current schema version. The framework will +// automatically intercept this request and attempt to respond with the +// existing state. In this situation the framework will not execute any +// provider defined logic, so declaring it for this version is extraneous. +type ResourceWithUpgradeState interface { + Resource + + // A mapping of prior state version to current schema version state upgrade + // implementations. Only the specified state upgrader for the prior state + // version is called, rather than each version in between, so it must + // encapsulate all logic to convert the prior state to the current schema + // version. + // + // Version keys begin at 0, which is the default schema version when + // undefined. The framework will return an error diagnostic should the + // requested state version not be implemented. + UpgradeState(context.Context) map[int64]StateUpgrader +} + +// ResourceWithValidateConfig is an interface type that extends Resource to include imperative validation. +// +// Declaring validation using this methodology simplifies one-off +// functionality that typically applies to a single resource. Any documentation +// of this functionality must be manually added into schema descriptions. +// +// Validation will include ConfigValidators and ValidateConfig, if both are +// implemented, in addition to any Attribute or Type validation. +type ResourceWithValidateConfig interface { + Resource + + // ValidateConfig performs the validation. + ValidateConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse) +} diff --git a/resource/state_upgrader.go b/resource/state_upgrader.go new file mode 100644 index 000000000..f3854de65 --- /dev/null +++ b/resource/state_upgrader.go @@ -0,0 +1,37 @@ +package resource + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// Implementation handler for a UpgradeState operation. +// +// This is used to encapsulate all upgrade logic from a prior state to the +// current schema version when a Resource implements the +// ResourceWithUpgradeState interface. +type StateUpgrader struct { + // Schema information for the prior state version. While not required, + // setting this will populate the UpgradeStateRequest type State + // field similar to other Resource data types. This allows for easier data + // handling such as calling Get() or GetAttribute(). + // + // If not set, prior state data is available in the + // UpgradeResourceStateRequest type RawState field. + PriorSchema *tfsdk.Schema + + // Provider defined logic for upgrading a resource state from the prior + // state version to the current schema version. + // + // The context.Context parameter contains framework-defined loggers and + // supports request cancellation. + // + // The UpgradeStateRequest parameter contains the prior state data. + // If PriorSchema was set, the State field will be available. Otherwise, + // the RawState must be used. + // + // The UpgradeStateResponse parameter should contain the upgraded + // state data and can be used to signal any logic warnings or errors. + StateUpgrader func(context.Context, UpgradeStateRequest, *UpgradeStateResponse) +} diff --git a/resource/update.go b/resource/update.go new file mode 100644 index 000000000..3d0f87cd6 --- /dev/null +++ b/resource/update.go @@ -0,0 +1,44 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// UpdateRequest represents a request for the provider to update a +// resource. An instance of this request struct is supplied as an argument to +// the resource's Update function. +type UpdateRequest struct { + // Config is the configuration the user supplied for the resource. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config + + // Plan is the planned state for the resource. + Plan tfsdk.Plan + + // State is the current state of the resource prior to the Update + // operation. + State tfsdk.State + + // ProviderMeta is metadata from the provider_meta block of the module. + ProviderMeta tfsdk.Config +} + +// UpdateResponse represents a response to an UpdateRequest. An +// instance of this response struct is supplied as +// an argument to the resource's Update function, in which the provider +// should set values on the UpdateResponse as appropriate. +type UpdateResponse struct { + // State is the state of the resource following the Update operation. + // This field is pre-populated from UpdateResourceRequest.Plan and + // should be set during the resource's Update operation. + State tfsdk.State + + // Diagnostics report errors or warnings related to updating the + // resource. An empty slice indicates a successful operation with no + // warnings or errors generated. + Diagnostics diag.Diagnostics +} diff --git a/resource/upgrade_state.go b/resource/upgrade_state.go new file mode 100644 index 000000000..ea4510f87 --- /dev/null +++ b/resource/upgrade_state.go @@ -0,0 +1,71 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" +) + +// Request information for the provider logic to update a resource state +// from a prior state version to the current schema version. An instance of +// this is supplied as a parameter to a StateUpgrader, which ultimately comes +// from a Resource's UpgradeState method. +type UpgradeStateRequest struct { + // Previous state of the resource in JSON (Terraform CLI 0.12 and later) + // or flatmap format, depending on which version of Terraform CLI last + // wrote the resource state. This data is always available, regardless + // whether the wrapping StateUpgrader type PriorSchema field was + // present. + // + // This is advanced functionality for providers wanting to skip the full + // redeclaration of older schemas and instead use lower level handlers to + // transform data. A typical implementation for working with this data will + // call the Unmarshal() method. + // + // TODO: Create framework defined type that is not protocol specific. + // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/340 + RawState *tfprotov6.RawState + + // Previous state of the resource if the wrapping StateUpgrader + // type PriorSchema field was present. When available, this allows for + // easier data handling such as calling Get() or GetAttribute(). + State *tfsdk.State +} + +// Response information for the provider logic to update a resource state +// from a prior state version to the current schema version. An instance of +// this is supplied as a parameter to a StateUpgrader, which ultimately came +// from a Resource's UpgradeState method. +type UpgradeStateResponse struct { + // Diagnostics report errors or warnings related to upgrading the resource + // state. An empty slice indicates a successful operation with no warnings + // or errors generated. + Diagnostics diag.Diagnostics + + // Upgraded state of the resource, which should match the current schema + // version. If set, this will override State. + // + // This field is intended only for advanced provider functionality, such as + // skipping the full redeclaration of older schemas or using lower level + // handlers to transform data. Call tfprotov6.NewDynamicValue() to set this + // value. + // + // All data must be populated to prevent data loss during the upgrade + // operation. No prior state data is copied automatically. + // + // TODO: Remove in preference of requiring State, rather than using either + // a new framework defined type or keeping this protocol specific type. + // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/340 + DynamicValue *tfprotov6.DynamicValue + + // Upgraded state of the resource, which should match the current schema + // version. If DynamicValue is set, it will override this value. + // + // This field allows for easier data handling such as calling Set() or + // SetAttribute(). It is generally recommended over working with the lower + // level types and functionality required for DynamicValue. + // + // All data must be populated to prevent data loss during the upgrade + // operation. No prior state data is copied automatically. + State tfsdk.State +} diff --git a/resource/validate_config.go b/resource/validate_config.go new file mode 100644 index 000000000..43e508a48 --- /dev/null +++ b/resource/validate_config.go @@ -0,0 +1,30 @@ +package resource + +import ( + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// ValidateConfigRequest represents a request to validate the +// configuration of a resource. An instance of this request struct is +// supplied as an argument to the Resource ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigRequest struct { + // Config is the configuration the user supplied for the resource. + // + // This configuration may contain unknown values if a user uses + // interpolation or other functionality that would prevent Terraform + // from knowing the value at request time. + Config tfsdk.Config +} + +// ValidateConfigResponse represents a response to a +// ValidateConfigRequest. An instance of this response struct is +// supplied as an argument to the Resource ValidateConfig receiver method +// or automatically passed through to each ConfigValidator. +type ValidateConfigResponse struct { + // Diagnostics report errors or warnings related to validating the resource + // configuration. An empty slice indicates success, with no warnings or + // errors generated. + Diagnostics diag.Diagnostics +} diff --git a/tfsdk/data_source.go b/tfsdk/data_source.go deleted file mode 100644 index 2b99a826c..000000000 --- a/tfsdk/data_source.go +++ /dev/null @@ -1,28 +0,0 @@ -package tfsdk - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" -) - -// A DataSourceType is a type of data source. For each type of data source this -// provider supports, it should define a type implementing DataSourceType and -// return an instance of it in the map returned by Provider.GetDataSources. -type DataSourceType interface { - // GetSchema returns the schema for this data source. - GetSchema(context.Context) (Schema, diag.Diagnostics) - - // NewDataSource instantiates a new DataSource of this DataSourceType. - NewDataSource(context.Context, Provider) (DataSource, diag.Diagnostics) -} - -// DataSource represents a data source instance. This is the core interface that -// all data sources must implement. -type DataSource interface { - // Read is called when the provider must read data source values in - // order to update state. Config values should be read from the - // ReadDataSourceRequest and new state values set on the - // ReadDataSourceResponse. - Read(context.Context, ReadDataSourceRequest, *ReadDataSourceResponse) -} diff --git a/tfsdk/data_source_validation.go b/tfsdk/data_source_validation.go deleted file mode 100644 index 7f2997824..000000000 --- a/tfsdk/data_source_validation.go +++ /dev/null @@ -1,58 +0,0 @@ -package tfsdk - -import ( - "context" -) - -// DataSourceConfigValidator describes reusable data source configuration validation functionality. -type DataSourceConfigValidator interface { - // Description describes the validation in plain text formatting. - // - // This information may be automatically added to data source plain text - // descriptions by external tooling. - Description(context.Context) string - - // MarkdownDescription describes the validation in Markdown formatting. - // - // This information may be automatically added to data source Markdown - // descriptions by external tooling. - MarkdownDescription(context.Context) string - - // ValidateDataSource performs the validation. - // - // This method name is separate from the ProviderConfigValidator - // interface ValidateProvider method name and ResourceConfigValidator - // interface ValidateResource method name to allow generic validators. - ValidateDataSource(context.Context, ValidateDataSourceConfigRequest, *ValidateDataSourceConfigResponse) -} - -// DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations. -// -// Declaring validation using this methodology simplifies implmentation of -// reusable functionality. These also include descriptions, which can be used -// for automating documentation. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type DataSourceWithConfigValidators interface { - DataSource - - // ConfigValidators returns a list of DataSourceConfigValidators. Each DataSourceConfigValidator's Validate method will be called when validating the data source. - ConfigValidators(context.Context) []DataSourceConfigValidator -} - -// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation. -// -// Declaring validation using this methodology simplifies one-off -// functionality that typically applies to a single data source. Any -// documentation of this functionality must be manually added into schema -// descriptions. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type DataSourceWithValidateConfig interface { - DataSource - - // ValidateConfig performs the validation. - ValidateConfig(context.Context, ValidateDataSourceConfigRequest, *ValidateDataSourceConfigResponse) -} diff --git a/tfsdk/doc.go b/tfsdk/doc.go index fc5425664..72f057bbf 100644 --- a/tfsdk/doc.go +++ b/tfsdk/doc.go @@ -1,3 +1,2 @@ -// Package tfsdk contains core framework functionality for data sources, -// providers, resources, schemas, and schema data. +// Package tfsdk contains core framework functionality for schemas and schema data. package tfsdk diff --git a/tfsdk/provider_validation.go b/tfsdk/provider_validation.go deleted file mode 100644 index 0a63e560f..000000000 --- a/tfsdk/provider_validation.go +++ /dev/null @@ -1,57 +0,0 @@ -package tfsdk - -import ( - "context" -) - -// ProviderConfigValidator describes reusable Provider configuration validation functionality. -type ProviderConfigValidator interface { - // Description describes the validation in plain text formatting. - // - // This information may be automatically added to provider plain text - // descriptions by external tooling. - Description(context.Context) string - - // MarkdownDescription describes the validation in Markdown formatting. - // - // This information may be automatically added to provider Markdown - // descriptions by external tooling. - MarkdownDescription(context.Context) string - - // ValidateProvider performs the validation. - // - // This method name is separate from the DataSourceConfigValidator - // interface ValidateDataSource method name and ResourceConfigValidator - // interface ValidateResource method name to allow generic validators. - ValidateProvider(context.Context, ValidateProviderConfigRequest, *ValidateProviderConfigResponse) -} - -// ProviderWithConfigValidators is an interface type that extends Provider to include declarative validations. -// -// Declaring validation using this methodology simplifies implementation of -// reusable functionality. These also include descriptions, which can be used -// for automating documentation. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type ProviderWithConfigValidators interface { - Provider - - // ConfigValidators returns a list of functions which will all be performed during validation. - ConfigValidators(context.Context) []ProviderConfigValidator -} - -// ProviderWithValidateConfig is an interface type that extends Provider to include imperative validation. -// -// Declaring validation using this methodology simplifies one-off -// functionality that typically applies to a single provider. Any documentation -// of this functionality must be manually added into schema descriptions. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type ProviderWithValidateConfig interface { - Provider - - // ValidateConfig performs the validation. - ValidateConfig(context.Context, ValidateProviderConfigRequest, *ValidateProviderConfigResponse) -} diff --git a/tfsdk/request.go b/tfsdk/request.go deleted file mode 100644 index bdf9437f6..000000000 --- a/tfsdk/request.go +++ /dev/null @@ -1,122 +0,0 @@ -package tfsdk - -// ConfigureProviderRequest represents a request containing the values the user -// specified for the provider configuration block, along with other runtime -// information from Terraform or the Plugin SDK. An instance of this request -// struct is supplied as an argument to the provider's Configure function. -type ConfigureProviderRequest struct { - // TerraformVersion is the version of Terraform executing the request. - // This is supplied for logging, analytics, and User-Agent purposes - // only. Providers should not try to gate provider behavior on - // Terraform versions. - TerraformVersion string - - // Config is the configuration the user supplied for the provider. This - // information should usually be persisted to the underlying type - // that's implementing the Provider interface, for use in later - // resource CRUD operations. - Config Config -} - -// CreateResourceRequest represents a request for the provider to create a -// resource. An instance of this request struct is supplied as an argument to -// the resource's Create function. -type CreateResourceRequest struct { - // Config is the configuration the user supplied for the resource. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config - - // Plan is the planned state for the resource. - Plan Plan - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} - -// ReadResourceRequest represents a request for the provider to read a -// resource, i.e., update values in state according to the real state of the -// resource. An instance of this request struct is supplied as an argument to -// the resource's Read function. -type ReadResourceRequest struct { - // State is the current state of the resource prior to the Read - // operation. - State State - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} - -// UpdateResourceRequest represents a request for the provider to update a -// resource. An instance of this request struct is supplied as an argument to -// the resource's Update function. -type UpdateResourceRequest struct { - // Config is the configuration the user supplied for the resource. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config - - // Plan is the planned state for the resource. - Plan Plan - - // State is the current state of the resource prior to the Update - // operation. - State State - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} - -// DeleteResourceRequest represents a request for the provider to delete a -// resource. An instance of this request struct is supplied as an argument to -// the resource's Delete function. -type DeleteResourceRequest struct { - // State is the current state of the resource prior to the Delete - // operation. - State State - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} - -// ModifyResourcePlanRequest represents a request for the provider to modify the -// planned new state that Terraform has generated for the resource. -type ModifyResourcePlanRequest struct { - // Config is the configuration the user supplied for the resource. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config - - // State is the current state of the resource. - State State - - // Plan is the planned new state for the resource. Terraform 1.3 and later - // supports resource destroy planning, in which this will contain a null - // value. - Plan Plan - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} - -// ReadDataSourceRequest represents a request for the provider to read a data -// source, i.e., update values in state according to the real state of the -// data source. An instance of this request struct is supplied as an argument -// to the data source's Read function. -type ReadDataSourceRequest struct { - // Config is the configuration the user supplied for the data source. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config - - // ProviderMeta is metadata from the provider_meta block of the module. - ProviderMeta Config -} diff --git a/tfsdk/request_import.go b/tfsdk/request_import.go deleted file mode 100644 index 34196fa23..000000000 --- a/tfsdk/request_import.go +++ /dev/null @@ -1,14 +0,0 @@ -package tfsdk - -// ImportResourceStateRequest represents a request for the provider to import a -// resource. An instance of this request struct is supplied as an argument to -// the Resource's ImportState method. -type ImportResourceStateRequest struct { - // ID represents the import identifier supplied by the practitioner when - // calling the import command. In many cases, this may align with the - // unique identifier for the resource, which can optionally be stored - // as an Attribute. However, this identifier can also be treated as - // its own type of value and parsed during import. This value - // is not stored in the state unless the provider explicitly stores it. - ID string -} diff --git a/tfsdk/request_validation.go b/tfsdk/request_validation.go deleted file mode 100644 index 293d0d29a..000000000 --- a/tfsdk/request_validation.go +++ /dev/null @@ -1,40 +0,0 @@ -package tfsdk - -// ValidateDataSourceConfigRequest represents a request to validate the -// configuration of a data source. An instance of this request struct is -// supplied as an argument to the DataSource ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateDataSourceConfigRequest struct { - // Config is the configuration the user supplied for the data source. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config -} - -// ValidateProviderConfigRequest represents a request to validate the -// configuration of a provider. An instance of this request struct is -// supplied as an argument to the Provider ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateProviderConfigRequest struct { - // Config is the configuration the user supplied for the provider. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config -} - -// ValidateResourceConfigRequest represents a request to validate the -// configuration of a resource. An instance of this request struct is -// supplied as an argument to the Resource ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateResourceConfigRequest struct { - // Config is the configuration the user supplied for the resource. - // - // This configuration may contain unknown values if a user uses - // interpolation or other functionality that would prevent Terraform - // from knowing the value at request time. - Config Config -} diff --git a/tfsdk/resource.go b/tfsdk/resource.go deleted file mode 100644 index fd99a8c99..000000000 --- a/tfsdk/resource.go +++ /dev/null @@ -1,78 +0,0 @@ -package tfsdk - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" -) - -// A ResourceType is a type of resource. For each type of resource this provider -// supports, it should define a type implementing ResourceType and return an -// instance of it in the map returned by Provider.GetResources. -type ResourceType interface { - // GetSchema returns the schema for this resource. - GetSchema(context.Context) (Schema, diag.Diagnostics) - - // NewResource instantiates a new Resource of this ResourceType. - NewResource(context.Context, Provider) (Resource, diag.Diagnostics) -} - -// Resource represents a resource instance. This is the core interface that all -// resources must implement. -// -// It is also conventional for resources to implement the -// ResourceWithImportState interface, which enables practitioners to import -// existing infrastructure into Terraform. -type Resource interface { - // Create is called when the provider must create a new resource. Config - // and planned state values should be read from the - // CreateResourceRequest and new state values set on the - // CreateResourceResponse. - Create(context.Context, CreateResourceRequest, *CreateResourceResponse) - - // Read is called when the provider must read resource values in order - // to update state. Planned state values should be read from the - // ReadResourceRequest and new state values set on the - // ReadResourceResponse. - Read(context.Context, ReadResourceRequest, *ReadResourceResponse) - - // Update is called to update the state of the resource. Config, planned - // state, and prior state values should be read from the - // UpdateResourceRequest and new state values set on the - // UpdateResourceResponse. - Update(context.Context, UpdateResourceRequest, *UpdateResourceResponse) - - // Delete is called when the provider must delete the resource. Config - // values may be read from the DeleteResourceRequest. - // - // If execution completes without error, the framework will automatically - // call DeleteResourceResponse.State.RemoveResource(), so it can be omitted - // from provider logic. - Delete(context.Context, DeleteResourceRequest, *DeleteResourceResponse) -} - -// ResourceWithModifyPlan represents a resource instance with a ModifyPlan -// function. -type ResourceWithModifyPlan interface { - Resource - - // ModifyPlan is called when the provider has an opportunity to modify - // the plan: once during the plan phase when Terraform is determining - // the diff that should be shown to the user for approval, and once - // during the apply phase with any unknown values from configuration - // filled in with their final values. - // - // The planned new state is represented by - // ModifyResourcePlanResponse.Plan. It must meet the following - // constraints: - // 1. Any non-Computed attribute set in config must preserve the exact - // config value or return the corresponding attribute value from the - // prior state (ModifyResourcePlanRequest.State). - // 2. Any attribute with a known value must not have its value changed - // in subsequent calls to ModifyPlan or Create/Read/Update. - // 3. Any attribute with an unknown value may either remain unknown - // or take on any value of the expected type. - // - // Any errors will prevent further resource-level plan modifications. - ModifyPlan(context.Context, ModifyResourcePlanRequest, *ModifyResourcePlanResponse) -} diff --git a/tfsdk/resource_import.go b/tfsdk/resource_import.go deleted file mode 100644 index f9e478576..000000000 --- a/tfsdk/resource_import.go +++ /dev/null @@ -1,38 +0,0 @@ -package tfsdk - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/path" -) - -// Optional interface on top of Resource that enables provider control over -// the ImportResourceState RPC. This RPC is called by Terraform when the -// `terraform import` command is executed. Afterwards, the ReadResource RPC -// is executed to allow providers to fully populate the resource state. -type ResourceWithImportState interface { - Resource - - // ImportState is called when the provider must import the state of a - // resource instance. This method must return enough state so the Read - // method can properly refresh the full resource. - // - // If setting an attribute with the import identifier, it is recommended - // to use the ResourceImportStatePassthroughID() call in this method. - ImportState(context.Context, ImportResourceStateRequest, *ImportResourceStateResponse) -} - -// ResourceImportStatePassthroughID is a helper function to set the import -// identifier to a given state attribute path. The attribute must accept a -// string value. -func ResourceImportStatePassthroughID(ctx context.Context, attrPath path.Path, req ImportResourceStateRequest, resp *ImportResourceStateResponse) { - if attrPath.Equal(path.Empty()) { - resp.Diagnostics.AddError( - "Resource Import Passthrough Missing Attribute Path", - "This is always an error in the provider. Please report the following to the provider developer:\n\n"+ - "Resource ImportState method call to ResourceImportStatePassthroughID path must be set to a valid attribute path that can accept a string value.", - ) - } - - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, attrPath, req.ID)...) -} diff --git a/tfsdk/resource_upgrade_state.go b/tfsdk/resource_upgrade_state.go deleted file mode 100644 index 69c86264c..000000000 --- a/tfsdk/resource_upgrade_state.go +++ /dev/null @@ -1,130 +0,0 @@ -package tfsdk - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" -) - -// Optional interface on top of Resource that enables provider control over -// the UpgradeResourceState RPC. This RPC is automatically called by Terraform -// when the current Schema type Version field is greater than the stored state. -// Terraform does not store previous Schema information, so any breaking -// changes to state data types must be handled by providers. -// -// Terraform CLI can execute the UpgradeResourceState RPC even when the prior -// state version matches the current schema version. The framework will -// automatically intercept this request and attempt to respond with the -// existing state. In this situation the framework will not execute any -// provider defined logic, so declaring it for this version is extraneous. -type ResourceWithUpgradeState interface { - Resource - - // A mapping of prior state version to current schema version state upgrade - // implementations. Only the specified state upgrader for the prior state - // version is called, rather than each version in between, so it must - // encapsulate all logic to convert the prior state to the current schema - // version. - // - // Version keys begin at 0, which is the default schema version when - // undefined. The framework will return an error diagnostic should the - // requested state version not be implemented. - UpgradeState(context.Context) map[int64]ResourceStateUpgrader -} - -// Implementation handler for a UpgradeResourceState operation. -// -// This is used to encapsulate all upgrade logic from a prior state to the -// current schema version when a Resource implements the -// ResourceWithUpgradeState interface. -type ResourceStateUpgrader struct { - // Schema information for the prior state version. While not required, - // setting this will populate the UpgradeResourceStateRequest type State - // field similar to other Resource data types. This allows for easier data - // handling such as calling Get() or GetAttribute(). - // - // If not set, prior state data is available in the - // UpgradeResourceStateRequest type RawState field. - PriorSchema *Schema - - // Provider defined logic for upgrading a resource state from the prior - // state version to the current schema version. - // - // The context.Context parameter contains framework-defined loggers and - // supports request cancellation. - // - // The UpgradeResourceStateRequest parameter contains the prior state data. - // If PriorSchema was set, the State field will be available. Otherwise, - // the RawState must be used. - // - // The UpgradeResourceStateResponse parameter should contain the upgraded - // state data and can be used to signal any logic warnings or errors. - StateUpgrader func(context.Context, UpgradeResourceStateRequest, *UpgradeResourceStateResponse) -} - -// Request information for the provider logic to update a resource state -// from a prior state version to the current schema version. An instance of -// this is supplied as a parameter to the StateUpgrader function defined in a -// ResourceStateUpgrader, which ultimately comes from a Resource's -// UpgradeState method. -type UpgradeResourceStateRequest struct { - // Previous state of the resource in JSON (Terraform CLI 0.12 and later) - // or flatmap format, depending on which version of Terraform CLI last - // wrote the resource state. This data is always available, regardless - // whether the wrapping ResourceStateUpgrader type PriorSchema field was - // present. - // - // This is advanced functionality for providers wanting to skip the full - // redeclaration of older schemas and instead use lower level handlers to - // transform data. A typical implementation for working with this data will - // call the Unmarshal() method. - // - // TODO: Create framework defined type that is not protocol specific. - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/340 - RawState *tfprotov6.RawState - - // Previous state of the resource if the wrapping ResourceStateUpgrader - // type PriorSchema field was present. When available, this allows for - // easier data handling such as calling Get() or GetAttribute(). - State *State -} - -// Response information for the provider logic to update a resource state -// from a prior state version to the current schema version. An instance of -// this is supplied as a parameter to the StateUpgrader function defined in a -// ResourceStateUpgrader, which ultimately came from a Resource's -// UpgradeState method. -type UpgradeResourceStateResponse struct { - // Diagnostics report errors or warnings related to upgrading the resource - // state. An empty slice indicates a successful operation with no warnings - // or errors generated. - Diagnostics diag.Diagnostics - - // Upgraded state of the resource, which should match the current schema - // version. If set, this will override State. - // - // This field is intended only for advanced provider functionality, such as - // skipping the full redeclaration of older schemas or using lower level - // handlers to transform data. Call tfprotov6.NewDynamicValue() to set this - // value. - // - // All data must be populated to prevent data loss during the upgrade - // operation. No prior state data is copied automatically. - // - // TODO: Remove in preference of requiring State, rather than using either - // a new framework defined type or keeping this protocol specific type. - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/340 - DynamicValue *tfprotov6.DynamicValue - - // Upgraded state of the resource, which should match the current schema - // version. If DynamicValue is set, it will override this value. - // - // This field allows for easier data handling such as calling Set() or - // SetAttribute(). It is generally recommended over working with the lower - // level types and functionality required for DynamicValue. - // - // All data must be populated to prevent data loss during the upgrade - // operation. No prior state data is copied automatically. - State State -} diff --git a/tfsdk/resource_validation.go b/tfsdk/resource_validation.go deleted file mode 100644 index 2992a3b8c..000000000 --- a/tfsdk/resource_validation.go +++ /dev/null @@ -1,57 +0,0 @@ -package tfsdk - -import ( - "context" -) - -// ResourceConfigValidator describes reusable Resource configuration validation functionality. -type ResourceConfigValidator interface { - // Description describes the validation in plain text formatting. - // - // This information may be automatically added to resource plain text - // descriptions by external tooling. - Description(context.Context) string - - // MarkdownDescription describes the validation in Markdown formatting. - // - // This information may be automatically added to resource Markdown - // descriptions by external tooling. - MarkdownDescription(context.Context) string - - // ValidateResource performs the validation. - // - // This method name is separate from the DataSourceConfigValidator - // interface ValidateDataSource method name and ProviderConfigValidator - // interface ValidateProvider method name to allow generic validators. - ValidateResource(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse) -} - -// ResourceWithConfigValidators is an interface type that extends Resource to include declarative validations. -// -// Declaring validation using this methodology simplifies implmentation of -// reusable functionality. These also include descriptions, which can be used -// for automating documentation. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type ResourceWithConfigValidators interface { - Resource - - // ConfigValidators returns a list of functions which will all be performed during validation. - ConfigValidators(context.Context) []ResourceConfigValidator -} - -// ResourceWithValidateConfig is an interface type that extends Resource to include imperative validation. -// -// Declaring validation using this methodology simplifies one-off -// functionality that typically applies to a single resource. Any documentation -// of this functionality must be manually added into schema descriptions. -// -// Validation will include ConfigValidators and ValidateConfig, if both are -// implemented, in addition to any Attribute or Type validation. -type ResourceWithValidateConfig interface { - Resource - - // ValidateConfig performs the validation. - ValidateConfig(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse) -} diff --git a/tfsdk/response.go b/tfsdk/response.go deleted file mode 100644 index 2805b825f..000000000 --- a/tfsdk/response.go +++ /dev/null @@ -1,117 +0,0 @@ -package tfsdk - -import ( - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/path" -) - -// ConfigureProviderResponse represents a response to a -// ConfigureProviderRequest. An instance of this response struct is supplied as -// an argument to the provider's Configure function, in which the provider -// should set values on the ConfigureProviderResponse as appropriate. -type ConfigureProviderResponse struct { - // Diagnostics report errors or warnings related to configuring the - // provider. An empty slice indicates success, with no warnings or - // errors generated. - Diagnostics diag.Diagnostics -} - -// CreateResourceResponse represents a response to a CreateResourceRequest. An -// instance of this response struct is supplied as -// an argument to the resource's Create function, in which the provider -// should set values on the CreateResourceResponse as appropriate. -type CreateResourceResponse struct { - // State is the state of the resource following the Create operation. - // This field is pre-populated from CreateResourceRequest.Plan and - // should be set during the resource's Create operation. - State State - - // Diagnostics report errors or warnings related to creating the - // resource. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics -} - -// ReadResourceResponse represents a response to a ReadResourceRequest. An -// instance of this response struct is supplied as -// an argument to the resource's Read function, in which the provider -// should set values on the ReadResourceResponse as appropriate. -type ReadResourceResponse struct { - // State is the state of the resource following the Read operation. - // This field is pre-populated from ReadResourceRequest.State and - // should be set during the resource's Read operation. - State State - - // Diagnostics report errors or warnings related to reading the - // resource. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics -} - -// UpdateResourceResponse represents a response to an UpdateResourceRequest. An -// instance of this response struct is supplied as -// an argument to the resource's Update function, in which the provider -// should set values on the UpdateResourceResponse as appropriate. -type UpdateResourceResponse struct { - // State is the state of the resource following the Update operation. - // This field is pre-populated from UpdateResourceRequest.Plan and - // should be set during the resource's Update operation. - State State - - // Diagnostics report errors or warnings related to updating the - // resource. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics -} - -// DeleteResourceResponse represents a response to a DeleteResourceRequest. An -// instance of this response struct is supplied as -// an argument to the resource's Delete function, in which the provider -// should set values on the DeleteResourceResponse as appropriate. -type DeleteResourceResponse struct { - // State is the state of the resource following the Delete operation. - // This field is pre-populated from UpdateResourceRequest.Plan and - // should be set during the resource's Update operation. - State State - - // Diagnostics report errors or warnings related to deleting the - // resource. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics -} - -// ModifyResourcePlanResponse represents a response to a -// ModifyResourcePlanRequest. An instance of this response struct is supplied -// as an argument to the resource's ModifyPlan function, in which the provider -// should modify the Plan and populate the RequiresReplace field as appropriate. -type ModifyResourcePlanResponse struct { - // Plan is the planned new state for the resource. - Plan Plan - - // RequiresReplace is a list of attribute paths that require the - // resource to be replaced. They should point to the specific field - // that changed that requires the resource to be destroyed and - // recreated. - RequiresReplace path.Paths - - // Diagnostics report errors or warnings related to determining the - // planned state of the requested resource. Returning an empty slice - // indicates a successful plan modification with no warnings or errors - // generated. - Diagnostics diag.Diagnostics -} - -// ReadDataSourceResponse represents a response to a ReadDataSourceRequest. An -// instance of this response struct is supplied as an argument to the data -// source's Read function, in which the provider should set values on the -// ReadDataSourceResponse as appropriate. -type ReadDataSourceResponse struct { - // State is the state of the data source following the Read operation. - // This field should be set during the resource's Read operation. - State State - - // Diagnostics report errors or warnings related to reading the data - // source. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics -} diff --git a/tfsdk/response_import.go b/tfsdk/response_import.go deleted file mode 100644 index ad8a72b8b..000000000 --- a/tfsdk/response_import.go +++ /dev/null @@ -1,21 +0,0 @@ -package tfsdk - -import ( - "github.com/hashicorp/terraform-plugin-framework/diag" -) - -// ImportResourceStateResponse represents a response to a ImportResourceStateRequest. -// An instance of this response struct is supplied as an argument to the -// Resource's ImportState method, in which the provider should set values on -// the ImportResourceStateResponse as appropriate. -type ImportResourceStateResponse struct { - // Diagnostics report errors or warnings related to importing the - // resource. An empty slice indicates a successful operation with no - // warnings or errors generated. - Diagnostics diag.Diagnostics - - // State is the state of the resource following the import operation. - // It must contain enough information so Terraform can successfully - // refresh the resource, e.g. call the Resource Read method. - State State -} diff --git a/tfsdk/response_validation.go b/tfsdk/response_validation.go deleted file mode 100644 index 65123800c..000000000 --- a/tfsdk/response_validation.go +++ /dev/null @@ -1,38 +0,0 @@ -package tfsdk - -import ( - "github.com/hashicorp/terraform-plugin-framework/diag" -) - -// ValidateDataSourceConfigResponse represents a response to a -// ValidateDataSourceConfigRequest. An instance of this response struct is -// supplied as an argument to the DataSource ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateDataSourceConfigResponse struct { - // Diagnostics report errors or warnings related to validating the data - // source configuration. An empty slice indicates success, with no warnings - // or errors generated. - Diagnostics diag.Diagnostics -} - -// ValidateResourceConfigResponse represents a response to a -// ValidateResourceConfigRequest. An instance of this response struct is -// supplied as an argument to the Resource ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateResourceConfigResponse struct { - // Diagnostics report errors or warnings related to validating the resource - // configuration. An empty slice indicates success, with no warnings or - // errors generated. - Diagnostics diag.Diagnostics -} - -// ValidateProviderConfigResponse represents a response to a -// ValidateProviderConfigRequest. An instance of this response struct is -// supplied as an argument to the Provider ValidateConfig receiver method -// or automatically passed through to each ConfigValidator. -type ValidateProviderConfigResponse struct { - // Diagnostics report errors or warnings related to validating the provider - // configuration. An empty slice indicates success, with no warnings or - // errors generated. - Diagnostics diag.Diagnostics -} diff --git a/website/docs/plugin/framework/accessing-values.mdx b/website/docs/plugin/framework/accessing-values.mdx index 760630f92..dba20f70e 100644 --- a/website/docs/plugin/framework/accessing-values.mdx +++ b/website/docs/plugin/framework/accessing-values.mdx @@ -16,7 +16,7 @@ The data is usually stored in a request object: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) + req resource.CreateRequest, resp *resource.CreateResponse) ``` In this example, `req` holds the configuration and plan, and there is no state @@ -40,7 +40,7 @@ type resourceData struct { } func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { var plan resourceData diags := req.Plan.Get(ctx, &plan) resp.Diagnostics.Append(diags...) @@ -93,8 +93,8 @@ type will always be the type produced by that attribute's `attr.Type`. ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { - attr, diags := req.Config.GetAttribute(ctx, tftypes.NewAttributePath().WithAttributeName("age")) + req resource.CreateRequest, resp *resource.CreateResponse) { + attr, diags := req.Config.GetAttribute(ctx, path.Root("age")) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return @@ -103,11 +103,6 @@ func (m myResource) Create(ctx context.Context, } ``` --> **Note:** The call to `tftypes.NewAttributePath` is creating an [attribute -path](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tftypes#AttributePath) -pointing to the specific attribute. A less-verbose way to specify attribute -paths is coming soon. - -> **Note:** Helpers to access `attr.Value`s using the same reflection rules `Get` has are planned, to avoid the need to type assert. We hope to release them soon. diff --git a/website/docs/plugin/framework/acctests.mdx b/website/docs/plugin/framework/acctests.mdx index 4dd2af52a..622fea34e 100644 --- a/website/docs/plugin/framework/acctests.mdx +++ b/website/docs/plugin/framework/acctests.mdx @@ -26,7 +26,7 @@ Use the [`providerserver.NewProtocol6WithError`](https://pkg.go.dev/github.com/h resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error) { - // newProvider is an example function that returns a tfsdk.Provider + // newProvider is an example function that returns a provider.Provider "example_provider": providerserver.NewProtocol6WithError(newProvider()), }, CheckDestroy: testAccCheckExampleResourceDestroy, @@ -47,7 +47,7 @@ Use the [`providerserver.NewProtocol5WithError`](https://pkg.go.dev/github.com/h resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error) { - // newProvider is an example function that returns a tfsdk.Provider + // newProvider is an example function that returns a provider.Provider "example_provider": providerserver.NewProtocol5WithError(newProvider()), }, CheckDestroy: testAccCheckExampleResourceDestroy, @@ -73,7 +73,7 @@ testing_new.go:53: no "id" found in attributes To avoid this, add a root level `id` attribute to resource and data source schemas. Ensure the attribute value is appropriately [written to state](/plugin/framework/writing-state). Conventionally, `id` is a computed attribute that contains the identifier for the resource. -For example, in the `GetSchema` method implementation of a [`DataSourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceType) or [`ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceType): +For example, in the `GetSchema` method implementation of a [`provider.DataSourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#DataSourceType) or [`provider.ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ResourceType): ```go func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { diff --git a/website/docs/plugin/framework/data-sources.mdx b/website/docs/plugin/framework/data-sources.mdx index c234ed4c5..9a14b8661 100644 --- a/website/docs/plugin/framework/data-sources.mdx +++ b/website/docs/plugin/framework/data-sources.mdx @@ -13,8 +13,8 @@ Providers have data sources that tell Terraform how to request external data and ## Define Data Source Archetype -Implement the [`tfsdk.DataSourceType` -interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceType) +Implement the [`provider.DataSourceType` +interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#DataSourceType) for every type of data source you want to support, such as disk images, compute instance groups, access policies, etc. It allows you to describe the data source archetype, which is the functionality related to all instances of that @@ -27,12 +27,12 @@ what fields are available in the data source's configuration and state. ### NewDataSource -`NewDataSource` returns a new instance of that data source type. It needs to instantiate a new [`tfsdk.DataSource` -implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSource) +`NewDataSource` returns a new instance of that data source type. It needs to instantiate a new [`datasource.DataSource` +implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#DataSource) that expects to operate on data with the structure defined in `GetSchema`. -The `NewDataSource` method is passed a [`tfsdk.Provider` -implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Provider). +The `NewDataSource` method is passed a [`provider.Provider` +implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#Provider). This is the [provider type](/plugin/framework/providers) after its `Configure` method was called. The `NewDataSource` method can type-assert on this and inject it into the `DataSource`, allowing the `DataSource` to have @@ -59,7 +59,7 @@ func (c computeImageDataSourceType) GetSchema(_ context.Context) (tfsdk.Schema, } func (c computeImageDataSourceType) NewDataSource(_ context.Context, - p tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { + p provider.Provider) (datasource.DataSource, diag.Diagnostics) { return computeImageDataSource{ client: p.(*provider).client, }, nil @@ -72,7 +72,7 @@ Data sources are scoped to a single instance of the data source type. They modif ### Read -`Read` updates Terraform's state to reflect the API data described in the configuration. There is no plan or state to work with in `Read`. Data sources should [retrieve the data they need](/plugin/framework/accessing-values) from the configuration included in the [`tfsdk.ReadDataSourceRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ReadDataSourceRequest). +`Read` updates Terraform's state to reflect the API data described in the configuration. There is no plan or state to work with in `Read`. Data sources should [retrieve the data they need](/plugin/framework/accessing-values) from the configuration included in the [`datasource.ReadRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#ReadRequest). They can then use the configured API client injected into the data source by the data source type's `NewDataSource` method, and [write the results to the state](/plugin/framework/writing-state). @@ -88,9 +88,9 @@ instance of the data source type. **Example** ```go -func (p *provider) GetDataSources(_ context.Context) (map[string]tfsdk.DataSourceType, +func (p *provider) GetDataSources(_ context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ + return map[string]provider.DataSourceType{ "example_compute_image": computeImageDataSourceType{}, }, nil } diff --git a/website/docs/plugin/framework/diagnostics.mdx b/website/docs/plugin/framework/diagnostics.mdx index a10788cc8..78933fce3 100644 --- a/website/docs/plugin/framework/diagnostics.mdx +++ b/website/docs/plugin/framework/diagnostics.mdx @@ -29,7 +29,7 @@ functions or methods: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) + req resource.CreateRequest, resp *resource.CreateResponse) ``` This is the most common form for Diagnostics: a slice that has one or more @@ -114,7 +114,7 @@ For example: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { // ... prior logic ... diags := req.Config.Get(ctx, &resourceData) resp.Diagnostics.Append(diags...) @@ -136,7 +136,7 @@ For example: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { // ... prior logic ... diags := req.Config.Get(ctx, &resourceData) resp.Diagnostics.Append(diags...) @@ -199,7 +199,7 @@ For example: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { // ... prior logic ... resp, err := http.Post("https://example.com") diff --git a/website/docs/plugin/framework/providers.mdx b/website/docs/plugin/framework/providers.mdx index f4e659449..c3359372d 100644 --- a/website/docs/plugin/framework/providers.mdx +++ b/website/docs/plugin/framework/providers.mdx @@ -12,16 +12,16 @@ Providers are Terraform plugins that define [resources](/plugin/framework/resour ## Implement Provider Interface -Any type that fills the [tfsdk.Provider interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Provider) can be a provider. The provider interface has four required methods: `GetSchema`, `Configure`, `GetResources`, and `GetDataSources`. We recommend that you define a `struct` type to fill this interface. +Any type that fills the [provider.Provider interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#Provider) can be a provider. The provider interface has four required methods: `GetSchema`, `Configure`, `GetResources`, and `GetDataSources`. We recommend that you define a `struct` type to fill this interface. An example provider implementation with a field storing an example API client: ```go -// Ensure the implementation satisfies the tfsdk.Provider interface. -var _ tfsdk.Provider = &exampleProvider{} +// Ensure the implementation satisfies the provider.Provider interface. +var _ provider.Provider = &exampleProvider{} -// exampleProvider implements the tfsdk.Provider interface. This implementation -// will be passed to data sources and resources as the tfsdk.Provider parameter +// exampleProvider implements the provider.Provider interface. This implementation +// will be passed to data sources and resources as the provider.Provider parameter // in each NewDataSource and NewResource method call respectively. type exampleProvider struct{ // Typically fields including API clients or configuration necessary for @@ -34,7 +34,7 @@ type exampleProvider struct{ Version string } -// GetSchema satisfies the tfsdk.Provider interface for exampleProvider. +// GetSchema satisfies the provider.Provider interface for exampleProvider. func (p *exampleProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ @@ -43,21 +43,21 @@ func (p *exampleProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Dia }, nil } -// Configure satisfies the tfsdk.Provider interface for exampleProvider. -func (p *exampleProvider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) { +// Configure satisfies the provider.Provider interface for exampleProvider. +func (p *exampleProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { // Provider specific implementation. } -// GetDataSources satisfies the tfsdk.Provider interface for exampleProvider. -func (p *exampleProvider) GetDataSources(ctx context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) { - return map[string]tfsdk.DataSourceType{ +// GetDataSources satisfies the provider.Provider interface for exampleProvider. +func (p *exampleProvider) GetDataSources(ctx context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) { + return map[string]provider.DataSourceType{ // Provider specific implementation }, nil } -// GetResources satisfies the tfsdk.Provider interface for exampleProvider. -func (p *exampleProvider) GetResources(ctx context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ +// GetResources satisfies the provider.Provider interface for exampleProvider. +func (p *exampleProvider) GetResources(ctx context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { + return map[string]provider.ResourceType{ // Provider specific implementation }, nil } @@ -66,8 +66,8 @@ func (p *exampleProvider) GetResources(ctx context.Context) (map[string]tfsdk.Re Conventionally, many providers also create a helper function named `New` which can simplify [provider server](/plugin/framework/provider-servers) implementations. ```go -func New(version string) func() tfsdk.Provider { - return func() tfsdk.Provider { +func New(version string) func() provider.Provider { + return func() provider.Provider { return &exampleProvider{ Version: version, } diff --git a/website/docs/plugin/framework/resources/import.mdx b/website/docs/plugin/framework/resources/import.mdx index 4823ac8c7..30a3bd192 100644 --- a/website/docs/plugin/framework/resources/import.mdx +++ b/website/docs/plugin/framework/resources/import.mdx @@ -6,17 +6,17 @@ description: >- # Resource Import -Practitioners can use the [`terraform import` command](/cli/commands/import) to let Terraform begin managing existing infrastructure resources. Resources can implement the `ImportState` method, which must either specify enough Terraform state for the `Read` method to refresh [`tfsdk.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Resource) or return an error. +Practitioners can use the [`terraform import` command](/cli/commands/import) to let Terraform begin managing existing infrastructure resources. Resources can implement the `ImportState` method, which must either specify enough Terraform state for the `Read` method to refresh [`resource.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#Resource) or return an error. ## Single Attribute -When the `Read` method requires a single attribute to refresh, use the [`tfsdk.ResourceImportStatePassthroughID` function](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceImportStatePassthroughID) to write the import identifier argument for `terraform import`. +When the `Read` method requires a single attribute to refresh, use the [`resource.ImportStatePassthroughID` function](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStatePassthroughID) to write the import identifier argument for `terraform import`. In the following example, the `terraform import` command passes the import identifier to the `id` attribute in Terraform state. ```go -func (r exampleResource) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - tfsdk.ResourceImportStatePassthroughID(ctx, path.Root("id"), req, resp) +func (r exampleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } ``` @@ -24,11 +24,11 @@ func (r exampleResource) ImportState(ctx context.Context, req tfsdk.ImportResour When the `Read` method requires multiple attributes to refresh, you must write custom logic in the `ImportState` method. Specifically, the implementation must: -1. Use the import identifier from the [`tfsdk.ImportResourceStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ImportResourceStateRequest). +1. Use the import identifier from the [`resource.ImportStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStateRequest). 1. Perform the custom logic. -1. [Set state data](/plugin/framework/writing-state) in the [`tfsdk.ImportResourceStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ImportResourceStateResponse). +1. [Set state data](/plugin/framework/writing-state) in the [`resource.ImportStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStateResponse). -For example, if the `tfsdk.ResourceType` implementation has the following `GetSchema` method: +For example, if the `provider.ResourceType` implementation has the following `GetSchema` method: ```go func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { @@ -48,10 +48,10 @@ func (t exampleResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag. } ``` -Along with a `tfsdk.Resource` implementation with the following `Read` method: +Along with a `resource.Resource` implementation with the following `Read` method: ```go -func (r exampleResource) Read(ctx context.Context, req tfsdk.ReadResourceRequest, resp *tfsdk.ReadResourceResponse) { +func (r exampleResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var attrOne, attrTwo string resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("attr_one"), &attrOne)...) @@ -70,7 +70,7 @@ The `terraform import` command will need to accept both attribute values as a si You could define the `ImportState` method using a comma-separated value as follows: ```go -func (r exampleResource) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { +func (r exampleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, ",") if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { diff --git a/website/docs/plugin/framework/resources/index.mdx b/website/docs/plugin/framework/resources/index.mdx index 8f51046e9..29149f3df 100644 --- a/website/docs/plugin/framework/resources/index.mdx +++ b/website/docs/plugin/framework/resources/index.mdx @@ -17,8 +17,8 @@ Providers act as a translation layer between Terraform and an API, offering one ## Define Resource Archetype -Implement the [`tfsdk.ResourceType` -interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceType) for every type of +Implement the [`provider.ResourceType` +interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ResourceType) for every type of resource you want to support: compute instances, disks, access policies, etc. It allows you to describe the resource archetype, which is the functionality related to all instances of that resource type in the configuration, state, plan, and API. `ResourceType` has the following methods: @@ -28,10 +28,10 @@ allows you to describe the resource archetype, which is the functionality relate ### NewResource -`NewResource` returns a new instance of that resource type. It instantiates a new [`tfsdk.Resource` implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Resource) +`NewResource` returns a new instance of that resource type. It instantiates a new [`resource.Resource` implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#Resource) that expects to operate on data with the structure defined in `GetSchema`. It does not need to create the instance on the API. -The `NewResource` method is passed a [`tfsdk.Provider` implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Provider). +The `NewResource` method is passed a [`provider.Provider` implementation](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#Provider). This is the [provider type](/plugin/framework/providers) after its `Configure` method was called. The `NewResource` method can type-assert on this and inject it into the `Resource`, allowing the `Resource` to have @@ -57,7 +57,7 @@ func (c computeInstanceResourceType) GetSchema(_ context.Context) (tfsdk.Schema, } func (c computeInstanceResourceType) NewResource(_ context.Context, - p tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) { + p provider.Provider) (resource.Resource, diag.Diagnostics) { return computeInstanceResource{ client: p.(*provider).client, }, nil @@ -72,7 +72,7 @@ Resources are scoped to a single instance of a resource type. They modify a spec `Create` makes the necessary API calls to create the resource and then persist that resource's data into the Terraform state. This is usually accomplished by: -1. [Reading the plan data](/plugin/framework/accessing-values) from the [`tfsdk.CreateResourceRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#CreateResourceRequest) +1. [Reading the plan data](/plugin/framework/accessing-values) from the [`resource.CreateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#CreateRequest) 1. Using the configured API client injected into the resource by the resource type's `NewResource` method 1. [Writing to the state](/plugin/framework/writing-state). @@ -87,7 +87,7 @@ value when it's set in the state; the state can never hold any unknown values. `Read` updates Terraform's state to reflect the latest state of the resource in the API. -There is no plan or config to work with in `Read`. Resources should [retrieve the data they need](/plugin/framework/accessing-values) from the current state included in the [`tfsdk.ReadResourceRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ReadResourceRequest). They can then use the configured API client injected into the resource by the +There is no plan or config to work with in `Read`. Resources should [retrieve the data they need](/plugin/framework/accessing-values) from the current state included in the [`resource.ReadRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ReadRequest). They can then use the configured API client injected into the resource by the resource type's `NewResource` method, and [write the results to the state](/plugin/framework/writing-state). @@ -109,7 +109,7 @@ The provider can set any value in state, but you should be mindful of values tha `Update` makes the necessary API calls to modify the existing resource to match the configuration and then to persist that resource's data into the Terraform state. This is usually accomplished by: -1. [Reading the plan data](/plugin/framework/accessing-values) from the [`tfsdk.UpdateResourceRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpdateResourceRequest) +1. [Reading the plan data](/plugin/framework/accessing-values) from the [`resource.UpdateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpdateRequest) 1. Using the configured API client injected into the resource by the resource type's `NewResource` method 1. [Writing to the state](/plugin/framework/writing-state). @@ -126,7 +126,7 @@ value when it's set in the state; the state can never hold any unknown values. `Delete` makes the necessary API calls to destroy a resource and then to remove that resource from the Terraform state. This is usually accomplished by: 1. [Reading the prior state data](/plugin/framework/accessing-values) from the - [`tfsdk.DeleteResourceRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DeleteResourceRequest) + [`resource.DeleteRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#DeleteRequest) 1. Using the configured API client injected into the resource by the resource type's `NewResource` method @@ -136,10 +136,10 @@ Terraform 1.3 and later enables deletion planning, which resources can implement `ImportState` is an optional method that implements resource [import](/cli/import). This functionality creates an initial Terraform state to bring the resource under management via the [`terraform import` command](/cli/commands/import). This method must provide enough state for the resource to be successfully refreshed via the `Read` method. This is usually accomplished by: -1. Using the import identifier from the [`tfsdk.ImportResourceStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ImportResourceStateRequest) to [set state data](/plugin/framework/writing-state) in the - [`tfsdk.ImportResourceStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ImportResourceStateResponse). +1. Using the import identifier from the [`resource.ImportStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStateRequest) to [set state data](/plugin/framework/writing-state) in the + [`resource.ImportStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStateResponse). -The [`tfsdk.ResourceImportStatePassthroughID` function](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceImportStatePassthroughID) is available to simplify writing the import identifier to an attribute. +The [`resource.ImportStatePassthroughID` function](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ImportStatePassthroughID) is available to simplify writing the import identifier to an attribute. Refer to [Resource Import](/plugin/framework/resources/import) for more details and code examples. @@ -158,9 +158,9 @@ the value must be an instance of the resource type. **Example** ```go -func (p *provider) GetResources(_ context.Context) (map[string]tfsdk.ResourceType, +func (p *provider) GetResources(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { - return map[string]tfsdk.ResourceType{ + return map[string]provider.ResourceType{ "example_compute_instance": computeInstanceResourceType{}, }, nil } diff --git a/website/docs/plugin/framework/resources/plan-modification.mdx b/website/docs/plugin/framework/resources/plan-modification.mdx index b4ea56e51..d8f08f0c2 100644 --- a/website/docs/plugin/framework/resources/plan-modification.mdx +++ b/website/docs/plugin/framework/resources/plan-modification.mdx @@ -114,12 +114,12 @@ func stringDefault(defaultValue string) stringDefaultModifier { ## Resource Plan Modification -Resources also support plan modification across all attributes. This is helpful when working with logic that applies to the resource as a whole, or in Terraform 1.3 and later, to return diagnostics during resource destruction. Implement the [`tfsdk.ResourceWithModifyPlan` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceWithModifyPlan) to support resource-level plan modification. For example: +Resources also support plan modification across all attributes. This is helpful when working with logic that applies to the resource as a whole, or in Terraform 1.3 and later, to return diagnostics during resource destruction. Implement the [`resource.ResourceWithModifyPlan` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ResourceWithModifyPlan) to support resource-level plan modification. For example: ```go -// Ensure the Resource satisfies the tfsdk.ResourceWithModifyPlan interface. -// Other methods to implement the tfsdk.Resource interface are omitted for brevity -var _ tfsdk.ResourceWithModifyPlan = exampleResource{} +// Ensure the Resource satisfies the resource.ResourceWithModifyPlan interface. +// Other methods to implement the resource.Resource interface are omitted for brevity +var _ resource.ResourceWithModifyPlan = exampleResource{} type exampleResource struct {} diff --git a/website/docs/plugin/framework/resources/state-upgrade.mdx b/website/docs/plugin/framework/resources/state-upgrade.mdx index 82f46668d..93266846d 100644 --- a/website/docs/plugin/framework/resources/state-upgrade.mdx +++ b/website/docs/plugin/framework/resources/state-upgrade.mdx @@ -22,13 +22,13 @@ A resource schema captures the structure and types of the resource [state](/lang ## Implementing State Upgrade Support -Ensure the [`tfsdk.Schema` type `Version` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Schema.Version) for the [`tfsdk.ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceType) is greater than `0`, then implement the [`tfsdk.ResourceWithStateUpgrade` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceWithStateUpgrade) for the [`tfsdk.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Resource). Conventionally the version is incremented by `1` for each state upgrade. +Ensure the [`tfsdk.Schema` type `Version` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#Schema.Version) for the [`provider.ResourceType`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ResourceType) is greater than `0`, then implement the [`resource.ResourceWithStateUpgrade` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ResourceWithStateUpgrade) for the [`resource.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#Resource). Conventionally the version is incremented by `1` for each state upgrade. This example shows a `ResourceType` which incremented the `Schema` type `Version` field: ```go // Other ResourceType methods are omitted in this example -var _ tfsdk.ResourceType = exampleResourceType{} +var _ provider.ResourceType = exampleResourceType{} type exampleResourceType struct{/* ... */} @@ -47,45 +47,45 @@ This example shows a `Resource` with the necessary `StateUpgrade` method to impl ```go // Other Resource methods are omitted in this example -var _ tfsdk.Resource = exampleResource{} -var _ tfsdk.ResourceWithUpgradeState = exampleResource{} +var _ resource.Resource = exampleResource{} +var _ resource.ResourceWithUpgradeState = exampleResource{} type exampleResource struct{/* ... */} -func (r exampleResource) UpgradeState(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ +func (r exampleResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ // State upgrade implementation from 0 (prior state version) to 2 (Schema.Version) 0: { // Optionally, the PriorSchema field can be defined. - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { /* ... */ }, + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { /* ... */ }, }, // State upgrade implementation from 1 (prior state version) to 2 (Schema.Version) 1: { // Optionally, the PriorSchema field can be defined. - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { /* ... */ }, + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { /* ... */ }, }, } } ``` -Each [`tfsdk.ResourceStateUpgrader`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceStateUpgrader) implementation is expected to wholly upgrade the resource state from the prior version to the current version. The framework does not iterate through intermediate version implementations as incrementing versions by 1 is only conventional and not required. +Each [`resource.StateUpgrader`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#StateUpgrader) implementation is expected to wholly upgrade the resource state from the prior version to the current version. The framework does not iterate through intermediate version implementations as incrementing versions by 1 is only conventional and not required. -All state data must be populated in the [`tfsdk.UpgradeResourceStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateResponse). The framework does not copy any prior state data from the [`tfsdk.UpgradeResourceStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateRequest). +All state data must be populated in the [`resource.UpgradeStateResponse`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateResponse). The framework does not copy any prior state data from the [`resource.UpgradeStateRequest`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateRequest). -There are two approaches to implementing the provider logic for state upgrades in `ResourceStateUpgrader`. The recommended approach is defining the prior schema matching the resource state, which allows for prior state access similar to other parts of the framework. The second, more advanced, approach is accessing the prior resource state using lower level data handlers. +There are two approaches to implementing the provider logic for state upgrades in `StateUpgrader`. The recommended approach is defining the prior schema matching the resource state, which allows for prior state access similar to other parts of the framework. The second, more advanced, approach is accessing the prior resource state using lower level data handlers. -### ResourceStateUpgrader With PriorSchema +### StateUpgrader With PriorSchema -Implement the [`ResourceStateUpgrader` type `PriorSchema` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceStateUpgrader.PriorSchema) to enable the framework to populate the [`tfsdk.UpgradeResourceStateRequest` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateRequest.State) for the provider defined state upgrade logic. Access the request `State` using methods such as [`Get()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Get) or [`GetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.GetAttribute). Write the [`tfsdk.UpgradeResourceStateResponse` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateResponse.State) using methods such as [`Set()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Set) or [`SetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.SetAttribute). +Implement the [`StateUpgrader` type `PriorSchema` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#StateUpgrader.PriorSchema) to enable the framework to populate the [`resource.UpgradeStateRequest` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateRequest.State) for the provider defined state upgrade logic. Access the request `State` using methods such as [`Get()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Get) or [`GetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.GetAttribute). Write the [`resource.UpgradeStateResponse` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateResponse.State) using methods such as [`Set()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Set) or [`SetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.SetAttribute). This example shows a resource that changes the type for two attributes, using the `PriorSchema` approach: ```go // Other ResourceType methods are omitted in this example -var _ tfsdk.ResourceType = exampleResourceType{} +var _ provider.ResourceType = exampleResourceType{} // Other Resource methods are omitted in this example -var _ tfsdk.Resource = exampleResource{} -var _ tfsdk.ResourceWithUpgradeState = exampleResource{} +var _ resource.Resource = exampleResource{} +var _ resource.ResourceWithUpgradeState = exampleResource{} type exampleResourceType struct{/* ... */} type exampleResource struct{/* ... */} @@ -124,8 +124,8 @@ func (t exampleResourceType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di } } -func (r exampleResource) UpgradeState(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ +func (r exampleResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) 0: { PriorSchema: &tfsdk.Schema{ @@ -144,7 +144,7 @@ func (r exampleResource) UpgradeState(ctx context.Context) map[int64]tfsdk.Resou }, }, }, - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { var priorStateData exampleResourceDataV0 resp.Diagnostics.Append(req.State.Get(ctx, &priorStateData)...) @@ -170,18 +170,18 @@ func (r exampleResource) UpgradeState(ctx context.Context) map[int64]tfsdk.Resou } ``` -### ResourceStateUpgrader Without PriorSchema +### StateUpgrader Without PriorSchema -Read prior state data from the [`tfsdk.UpgradeResourceStateRequest` type `RawState` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateRequest.RawState). Write the [`tfsdk.UpgradeResourceStateResponse` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateResponse.State) using methods such as [`Set()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Set) or [`SetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.SetAttribute), or for more advanced use cases, write the [`tfsdk.UpgradeResourceStateResponse` type `DynamicValue` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#UpgradeResourceStateResponse.DynamicValue). +Read prior state data from the [`resource.UpgradeStateRequest` type `RawState` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateRequest.RawState). Write the [`resource.UpgradeStateResponse` type `State` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateResponse.State) using methods such as [`Set()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.Set) or [`SetAttribute()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#State.SetAttribute), or for more advanced use cases, write the [`resource.UpgradeStateResponse` type `DynamicValue` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#UpgradeStateResponse.DynamicValue). This example shows a resource that changes the type for two attributes, using the `RawState` approach for the request and `DynamicValue` approach for the response: ```go // Other ResourceType methods are omitted in this example -var _ tfsdk.ResourceType = exampleResourceType{} +var _ provider.ResourceType = exampleResourceType{} // Other Resource methods are omitted in this example -var _ tfsdk.Resource = exampleResource{} -var _ tfsdk.ResourceWithUpgradeState = exampleResource{} +var _ resource.Resource = exampleResource{} +var _ resource.ResourceWithUpgradeState = exampleResource{} var exampleResourceTftypesDataV0 = tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ @@ -224,11 +224,11 @@ func (t exampleResourceType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di } } -func (r exampleResource) UpgradeState(ctx context.Context) map[int64]tfsdk.ResourceStateUpgrader { - return map[int64]tfsdk.ResourceStateUpgrader{ +func (r exampleResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) 0: { - StateUpgrader: func(ctx context.Context, req tfsdk.UpgradeResourceStateRequest, resp *tfsdk.UpgradeResourceStateResponse) { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { // Refer also to the RawState type JSON field which can be used // with json.Unmarshal() rawStateValue, err := req.RawState.Unmarshal(exampleResourceTftypesDataV0) diff --git a/website/docs/plugin/framework/validation.mdx b/website/docs/plugin/framework/validation.mdx index bf0c8a15f..60e6f5ca3 100644 --- a/website/docs/plugin/framework/validation.mdx +++ b/website/docs/plugin/framework/validation.mdx @@ -321,26 +321,26 @@ Provider, resource, and data source schemas also support validation across all a The framework performs provider validation in addition to attribute and type validation. You can implement either or both of the following interfaces. -The [`tfsdk.ProviderWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ProviderWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you write consistent validators across multiple providers. You must implement the [`tfsdk.ProviderConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ProviderConfigValidator) for each validator. For example: +The [`provider.ProviderWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ProviderWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you write consistent validators across multiple providers. You must implement the [`provider.ConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ConfigValidator) for each validator. For example: ```go -// Other methods to implement the tfsdk.Provider interface are omitted for brevity +// Other methods to implement the provider.Provider interface are omitted for brevity type exampleProvider struct {} -func (p exampleProvider) ConfigValidators(ctx context.Context) []tfsdk.ProviderConfigValidator { - return []tfsdk.ProviderConfigValidator{ +func (p exampleProvider) ConfigValidators(ctx context.Context) []provider.ConfigValidator { + return []provider.ConfigValidator{ /* ... */ } } ``` -The [`tfsdk.ProviderWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ProviderWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single provider. For example: +The [`provider.ProviderWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/provider#ProviderWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single provider. For example: ```go -// Other methods to implement the tfsdk.Provider interface are omitted for brevity +// Other methods to implement the provider.Provider interface are omitted for brevity type exampleProvider struct {} -func (p exampleProvider) ValidateConfig(ctx context.Context, req ValidateProviderConfigRequest, resp *ValidateProviderConfigResponse) { +func (p exampleProvider) ValidateConfig(ctx context.Context, req ValidateConfigRequest, resp *ValidateConfigResponse) { // Retrieve values via req.Config.Get() or req.Config.GetAttribute(), // then return any warnings or errors via resp.Diagnostics. } @@ -350,26 +350,26 @@ func (p exampleProvider) ValidateConfig(ctx context.Context, req ValidateProvide The framework performs resource schema validation in addition to any attribute and type validation. You can implement either or both of the following interfaces. -The [`tfsdk.ResourceWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you create consistent validators across multiple resources. You must implement the [`tfsdk.ResourceConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceConfigValidator) for each validator. For example: +The [`resource.ResourceWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ResourceWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you create consistent validators across multiple resources. You must implement the [`resource.ConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ConfigValidator) for each validator. For example: ```go -// Other methods to implement the tfsdk.Resource interface are omitted for brevity +// Other methods to implement the resource.Resource interface are omitted for brevity type exampleResource struct {} -func (r exampleResource) ConfigValidators(ctx context.Context) []tfsdk.ResourceConfigValidator { - return []tfsdk.ResourceConfigValidator{ +func (r exampleResource) ConfigValidators(ctx context.Context) []resource.ConfigValidator { + return []resource.ConfigValidator{ /* ... */ } } ``` -The [`tfsdk.ResourceWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#ResourceWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single resource. For example: +The [`resource.ResourceWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ResourceWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single resource. For example: ```go -// Other methods to implement the tfsdk.Resource interface are omitted for brevity +// Other methods to implement the resource.Resource interface are omitted for brevity type exampleResource struct {} -func (r exampleResource) ValidateConfig(ctx context.Context, req ValidateResourceConfigRequest, resp *ValidateResourceConfigResponse) { +func (r exampleResource) ValidateConfig(ctx context.Context, req ValidateConfigRequest, resp *ValidateConfigResponse) { // Retrieve values via req.Config.Get() or req.Config.GetAttribute(), // then return any warnings or errors via resp.Diagnostics. } @@ -379,26 +379,26 @@ func (r exampleResource) ValidateConfig(ctx context.Context, req ValidateResourc The framework performs data source schema validation in addition to any attribute and type validation. You can implement either or both of the following interfaces. -The [`tfsdk.DataSourceWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you write consistent validators across multiple data sources. You must implement the [`tfsdk.DataSourceConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceConfigValidator) for each validator. For example: +The [`datasource.DataSourceWithConfigValidators` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#DataSourceWithConfigValidators) follows a similar pattern to attribute validation and allows for a more declarative approach. This lets you write consistent validators across multiple data sources. You must implement the [`datasource.ConfigValidator` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#ConfigValidator) for each validator. For example: ```go -// Other methods to implement the tfsdk.DataSource interface are omitted for brevity +// Other methods to implement the datasource.DataSource interface are omitted for brevity type exampleDataSource struct {} -func (d exampleDataSource) ConfigValidators(ctx context.Context) []tfsdk.DataSourceConfigValidator { - return []tfsdk.DataSourceConfigValidator{ +func (d exampleDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator { + return []datasource.ConfigValidator{ /* ... */ } } ``` -The [`tfsdk.DataSourceWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/tfsdk#DataSourceWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single data source. For example: +The [`datasource.DataSourceWithValidateConfig` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#DataSourceWithValidateConfig) is more imperative in design and is useful for validating unique functionality that typically applies to a single data source. For example: ```go -// Other methods to implement the tfsdk.DataSource interface are omitted for brevity +// Other methods to implement the datasource.DataSource interface are omitted for brevity type exampleDataSource struct {} -func (d exampleDataSource) ValidateConfig(ctx context.Context, req ValidateDataSourceConfigRequest, resp *ValidateDataSourceConfigResponse) { +func (d exampleDataSource) ValidateConfig(ctx context.Context, req ValidateConfigRequest, resp *ValidateConfigResponse) { // Retrieve values via req.Config.Get() or req.Config.GetAttribute(), // then return any warnings or errors via resp.Diagnostics. } diff --git a/website/docs/plugin/framework/writing-state.mdx b/website/docs/plugin/framework/writing-state.mdx index c3021d77d..e0179e902 100644 --- a/website/docs/plugin/framework/writing-state.mdx +++ b/website/docs/plugin/framework/writing-state.mdx @@ -16,7 +16,7 @@ response object: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) + req resource.CreateRequest, resp *resource.CreateResponse) ``` In this example, `resp` holds the state that the provider developer should @@ -38,7 +38,7 @@ type resourceData struct { } func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { var newState resourceData // update newState by modifying each property as usual for Go values newState.Name.Value = "J. Doe" @@ -93,9 +93,9 @@ runtime. ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { age := types.Number{Value: big.NewFloat(7)} - diags := resp.State.SetAttribute(ctx, tftypes.NewAttributePath().WithAttributeName("age"), &age) + diags := resp.State.SetAttribute(ctx, path.Root("age"), &age) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return @@ -107,10 +107,10 @@ Like `Set`, `SetAttribute` can also do some conversion to standard Go types: ```go func (m myResource) Create(ctx context.Context, - req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { + req resource.CreateRequest, resp *resource.CreateResponse) { var age int64 age = 7 - diags := resp.State.SetAttribute(ctx, tftypes.NewAttributePath().WithAttributeName("age"), &age) + diags := resp.State.SetAttribute(ctx, path.Root("age"), &age) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return @@ -120,11 +120,6 @@ func (m myResource) Create(ctx context.Context, See [below](#conversion-rules) for the rules about conversion. --> **Note:** The call to `tftypes.NewAttributePath` is creating an [attribute -path](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tftypes#AttributePath) -pointing to the specific attribute being updated. A less-verbose way to specify -attribute paths is coming soon. - ## Conversion Rules The following is a list of schema types and the Go types they know how to From d56ea09a2a50a6014186a039ed232f63dac907ef Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 29 Jul 2022 14:28:59 -0400 Subject: [PATCH 2/3] Update CHANGELOG for #432 --- .changelog/{pending.txt => 432.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{pending.txt => 432.txt} (100%) diff --git a/.changelog/pending.txt b/.changelog/432.txt similarity index 100% rename from .changelog/pending.txt rename to .changelog/432.txt From 0062c6c390f23c990d15f2c92cfbef878a23a4d3 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 1 Aug 2022 13:34:19 -0400 Subject: [PATCH 3/3] resource: Copy ModifyPlanRequest.Plan comment prior to rebasing --- resource/modify_plan.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resource/modify_plan.go b/resource/modify_plan.go index d3c300aec..0ead46623 100644 --- a/resource/modify_plan.go +++ b/resource/modify_plan.go @@ -19,7 +19,9 @@ type ModifyPlanRequest struct { // State is the current state of the resource. State tfsdk.State - // Plan is the planned new state for the resource. + // Plan is the planned new state for the resource. Terraform 1.3 and later + // supports resource destroy planning, in which this will contain a null + // value. Plan tfsdk.Plan // ProviderMeta is metadata from the provider_meta block of the module.