Skip to content

Conversation

@austinvalle
Copy link
Member

@austinvalle austinvalle commented Mar 13, 2023

contributes to hashicorp/terraform-plugin-sdk#1151

Related PRs:

Notes

@austinvalle
Copy link
Member Author

Should we stack this new page under a section? I initially removed the section because there is only one page right now:
image

Given this sample resource:

```go
package provider
Copy link
Member Author

@austinvalle austinvalle Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I correctly transcribed the original SDK deprecation code examples over, this is a first attempt 😄

Original docs: https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/deprecations

}
}

func (e *exampleWidgetResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I transcribed the original SDK deprecation code examples over, but is there a better place to return this diag when deprecating an entire resource?

Original example: https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/deprecations#provider-data-source-or-resource-removal

1. Add the new resource to the provider [`Resources`](/terraform/plugin/framework/providers#resources) function
1. Follow the rest of the procedures in the [Provider Data Source or Resource Removal section](#provider-data-source-or-resource-removal).

### Example Resource Renaming
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I transcribed the original SDK deprecation code examples over, but is there a better place to return this diag when deprecating an entire resource?

Original example: https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/deprecations#provider-data-source-or-resource-rename

1. Add a [`DeprecationMessage`](/terraform/plugin/framework/handling-data/schemas#deprecationmessage-1) to the schema definition of the existing (now the "old") attribute, noting to use the new attribute in the message.
1. Add `**Deprecated**` to the documentation of the existing (now the "old") attribute, noting to use the new attribute.
1. Add a note to the documentation that either the existing (now the "old") attribute or new attribute must be configured.
1. Add the type-specific [validator](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators) `{type}validator.ExactlyOneOf` to the schema definition of the new attribute, with a path expression matching the old attribute. This will ensure at least one of the attributes is configured, but present an error to the operator if both are configured at the same time. For example, an attribute of type string would use the [`stringvalidator.ExactlyOneOf`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator#ExactlyOneOf) validator.
Copy link
Member Author

@austinvalle austinvalle Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially had this as the ConflictsWith validator, not sure which one is recommended

Original docs: https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/deprecations#renaming-a-required-attribute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe ConflictsWith or ExactlyOneOf can be used with equivalent results but I think I would lean towards the latter as seems from a semantic point of view to be more aligned with the intent.

@austinvalle austinvalle changed the title (WIP) Add deprecation documentation (from Best Practices - SDKv2) Add deprecation documentation (from Best Practices - SDKv2) Mar 13, 2023
@austinvalle austinvalle added the documentation Improvements or additions to documentation label Mar 13, 2023
@austinvalle austinvalle marked this pull request as ready for review March 13, 2023 20:31
@austinvalle austinvalle requested a review from a team as a code owner March 13, 2023 20:31
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

LGTM 🎸

@austinvalle austinvalle added this to the v1.2.0 milestone Mar 20, 2023
@austinvalle austinvalle merged commit 680bab7 into main Mar 20, 2023
@austinvalle austinvalle deleted the av/migrate-best-practices branch March 20, 2023 21:10
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants