Skip to content

Commit 674b795

Browse files
committed
refactor: Address PR comments
1 parent a0ad4a7 commit 674b795

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

internal/common/customplanmodifier/create_only_bool.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// This is useful for attributes only supported in create and not in update.
1717
// It shows a helpful error message helping the user to update their config to match the state.
1818
// Never use a schema.Default for create only attributes, instead use `WithDefault`, the default will lead to plan changes that are not expected after import.
19-
// Implement CopyFromPlan if the attribute is not in the API Response.
19+
// If the attribute is not in the API Response implement CopyFromPlan behavior when converting API Model to TF Model.
2020
func CreateOnlyBool() planmodifier.Bool {
2121
return &createOnlyBoolPlanModifier{}
2222
}
@@ -25,6 +25,7 @@ func CreateOnlyBool() planmodifier.Bool {
2525
// This avoids any custom logic in the resource "Create" handler.
2626
// On update the default has no impact and the UseStateForUnknown behavior is observed instead.
2727
// Always use Optional+Computed when using a default value.
28+
// If the attribute is not in the API Response implement CopyFromPlan behavior when converting API Model to TF Model.
2829
func CreateOnlyBoolWithDefault(b bool) planmodifier.Bool {
2930
return &createOnlyBoolPlanModifier{defaultBool: &b}
3031
}
@@ -38,7 +39,7 @@ func (d *createOnlyBoolPlanModifier) Description(ctx context.Context) string {
3839
}
3940

4041
func (d *createOnlyBoolPlanModifier) MarkdownDescription(ctx context.Context) string {
41-
return "Ensures the update operation fails when updating an attribute. If the read after import don't equal the configuration value it will also raise an error."
42+
return "Ensures the update operation fails when updating an attribute. If the read after import doesn't equal the configuration value it will also raise an error."
4243
}
4344

4445
// isCreate uses the full state to check if this is a create operation
@@ -65,18 +66,6 @@ func (d *createOnlyBoolPlanModifier) PlanModifyBool(ctx context.Context, req pla
6566
}
6667
}
6768

68-
func (d *createOnlyBoolPlanModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
69-
if isCreate(&req.State) {
70-
return
71-
}
72-
if isUpdated(req.StateValue, req.PlanValue) {
73-
d.addDiags(&resp.Diagnostics, req.Path, req.StateValue)
74-
}
75-
if !IsKnown(req.PlanValue) {
76-
resp.PlanValue = req.StateValue
77-
}
78-
}
79-
8069
// isUpdated checks if the attribute was updated.
8170
// Special case when the attribute is removed/set to null in the plan:
8271
// Computed Attribute: returns false (unknown in the plan)

internal/common/customplanmodifier/create_only_string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// It shows a helpful error message helping the user to update their config to match the state.
1616
// Never use a schema.Default for create only attributes, instead use `WithDefault`, the default will lead to plan changes that are not expected after import.
1717
// No default value implemented for string until we have a use case.
18-
// Implement CopyFromPlan if the attribute is not in the API Response.
18+
// If the attribute is not in the API Response implement CopyFromPlan behavior when converting API Model to TF Model.
1919
func CreateOnlyString() planmodifier.String {
2020
return &createOnlyStringPlanModifier{}
2121
}

0 commit comments

Comments
 (0)