Skip to content

Commit

Permalink
Documentation for mapping between SDKv2 and the Framework (#660)
Browse files Browse the repository at this point in the history
* Adding table to provide mapping between SDKv2 schema validators and framework attribute and data source, provider and resource validators (#659)

* Adding a table to provide mapping between SDK schema fields and Framework (#659)

* Apply suggestions from code review

Co-authored-by: Brian Flad <[email protected]>

* Adding a table to provide mapping between SDK schema fields and Framework for Blocks (#659)

* Add import statements for usage of timeouts module (#659)

* Apply suggestions from code review

Co-authored-by: Brian Flad <[email protected]>

---------

Co-authored-by: Brian Flad <[email protected]>
  • Loading branch information
bendbennett and bflad authored Feb 10, 2023
1 parent 1be6094 commit d8f5d5a
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
9 changes: 9 additions & 0 deletions website/docs/plugin/framework/data-sources/timeouts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ resource "timeouts_example" "example" {
}
```

Import the [timeouts module](https://github.com/hashicorp/terraform-plugin-framework-timeouts).

```go
import (
/* ... */
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
)
````
You can use this module to mutate the `schema.Schema` as follows:
```go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@ This page explains how to migrate nested blocks that are not computed (i.e., do
[Blocks with Computed Fields](/plugin/framework/migrating/attributes-blocks/blocks-computed) for more details
about migrating nested blocks that contain fields that are computed.

The following table describes the mapping between [SDK Schema Fields](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/schema#Schema) and the Framework.

| SDK Schema Field | Framework |
|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Type | [ListNestedBlock](/plugin/framework/migrating/attributes-blocks/blocks), [SetNestedBlock](/plugin/framework/migrating/attributes-blocks/blocks) |
| ConfigMode | Schema must be explictly defined using [Attributes](/plugin/framework/migrating/attributes-blocks/attribute-schema) and [Blocks](/plugin/framework/migrating/attributes-blocks/blocks) |
| Required | [listvalidator.IsRequired](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/listvalidator#IsRequired), [setvalidator.IsRequired](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator#IsRequired) |
| Optional | N/A - no implementation required |
| Computed | [Blocks with Computed Fields](/plugin/framework/migrating/attributes-blocks/blocks-computed) |
| ForceNew | [RequiresReplace](/plugin/framework/migrating/attributes-blocks/force-new) on `PlanModifiers` field on attribute within block or implementation of [ResourceWithModifyPlan](/plugin/framework/migrating/resources/plan-modification#framework) interface |
| DiffSuppressFunc | [PlanModifiers](/framework/migrating/resources/plan-modification#framework) field on attribute within block or implementation of [ResourceWithModifyPlan](/plugin/framework/migrating/resources/plan-modification#framework) interface |
| DiffSuppressOnRefresh | [Read](/plugin/framework/migrating/resources/crud) method on resource |
| Default | [PlanModifiers](/framework/migrating/resources/plan-modification#framework) field on attribute within block or implementation of [ResourceWithModifyPlan](/plugin/framework/migrating/resources/plan-modification#framework) interface |
| DefaultFunc | [PlanModifiers](/framework/migrating/resources/plan-modification#framework) field on attribute within block or implementation of [ResourceWithModifyPlan](/plugin/framework/migrating/resources/plan-modification#framework) interface |
| Description | `Description` field on block |
| InputDefault | N/A - no longer valid |
| StateFunc | Requires implementation of bespoke logic before storing state, for instance in resource [Create method](plugin/framework/migrating/resources/crud#framework-1) |
| Elem | `NestedObject` within block |
| MaxItems | Use [listValidator.SizeAtMost](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/listvalidator#SizeAtMost) or [setvalidator.SizeAtMost](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator#SizeAtMost) on `Validators` field on `ListNestedBlock` or `SetNestedBlock` |
| MinItems | Use [listValidator.SizeAtLeast](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/listvalidator#SizeAtLeast) or [setvalidator.SizeAtLeast](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator#SizeAtLeast) on `Validators` field on `ListNestedBlock` or `SetNestedBlock` |
| Set | N/A - no implementation required | |
| ComputedWhen | N/A - no longer valid |
| ConflictsWith | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) |
| ExactlyOneOf | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) |
| AtLeastOneOf | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) |
| RequiredWith | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) |
| Deprecated | `DeprecationMessage` field on attribute within block |
| ValidateFunc | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) and [Custom Validators](/plugin/framework/migrating/attributes-blocks/validators-custom) |
| ValidateDiagFunc | [Predefined Validators](/plugin/framework/migrating/attributes-blocks/validators-predefined) and [Custom Validators](/plugin/framework/migrating/attributes-blocks/validators-custom) |
| Sensitive | N/A - only supported on attributes |


## Nested Block Example

The following example shows a nested block in Terraform resource configuration. The `subject` nested
Expand Down
Loading

0 comments on commit d8f5d5a

Please sign in to comment.