Plan Modification
Your provider can modify the Terraform plan to match the expected end state. This can include replacing unknown values with expected known values or marking a resource that must be replaced. Refer to Plan Modification in the Framework documentation for details.
This page explains how to migrate resource CustomizeDiff
functions in SDKv2 to PlanModifiers
in the plugin
Framework.
SDKv2
In SDKv2, plan modification is implemented with the CustomizeDiff
field on the schema.Resource
struct. The following
code shows a basic implementation of plan modification with SDKv2.
Framework
In the Framework, you implement plan modification either by implementing the ResourceWithModifyPlan
interface on your
resource type, or by implementing PlanModifiers
on individual attributes. This page demonstrates how to implement the
plan modifiers on individual attributes. Refer to
Attributes - Force New in this guide for further information on how
to implement a plan modifier on an attribute.
The ResourceWithModifyPlan
interface requires a ModifyPlan
function.
The following code shows how you can implement the ModifyPlan
function on your resource.Resource
type.
Migration Notes
Remember the following differences between SDKv2 and the Framework when completing the migration.
- In SDKv2, you implement plan modification with the
CustomizeDiff
field on theschema.Resource
struct. In the Framework, you can either implement plan modification for the entire resource by implementing theResourceWithModifyPlan
interface, or on individual attributes by addingPlanModifiers
to your resource attributes. - Many existing CustomizeDiff implementations may be better suited to implementation as attribute plan modifiers in the Framework.
Example
SDKv2
In SDKv2, the CustomizeDiff
field on the schema.Resource
struct refers to a function or set of functions that
implement plan modification.
The following example shows the use of CustomizeDiff
to keep two attributes
synchronized (i.e., ensure that they contain the same value) with SDKv2.
The following example shows the implementation of the planSyncIfChange
function.
Framework
Many existing CustomizeDiff
implementations would be better suited to migration to attribute plan modifiers in the
Framework. This code shows the implementation using attribute plan modifiers with the Framework.
The following shows an implementation of SyncAttributePlanModifier
in the Framework.