-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package planmodify | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
) | ||
|
||
// UseNullForRemovedWithState sets plan to null if the list has an state, but | ||
// the configuration is now null | ||
func UseNullForRemovedWithState() planmodifier.List { | ||
return useNullForRemovedWithStateModifier{} | ||
} | ||
|
||
type useNullForRemovedWithStateModifier struct{} | ||
|
||
func (m useNullForRemovedWithStateModifier) Description(_ context.Context) string { | ||
return "Removes the value if the list has an state, but the configuration changes to null" | ||
} | ||
|
||
func (m useNullForRemovedWithStateModifier) MarkdownDescription(_ context.Context) string { | ||
return "Removes the value if the list has an state, but the configuration changes to null" | ||
} | ||
|
||
func (m useNullForRemovedWithStateModifier) PlanModifyList(_ context.Context, req planmodifier.ListRequest, resp *planmodifier.ListResponse) { | ||
// Do nothing if there is no state value. | ||
if req.StateValue.IsNull() { | ||
return | ||
} | ||
|
||
// Do nothing if there is a known or an unknown configuration value. | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
resp.PlanValue = req.ConfigValue | ||
} |