-
Notifications
You must be signed in to change notification settings - Fork 101
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Module version
v1.14.1 (latest)
Relevant provider source code
"computed_attr": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
Expected Behavior
If the prior state value for computed_attr
is null
, that should be preserved and stored in the plan (if the attribute is unconfigured) because null
is a known value.
What I believe the current logic is attempting to do, is prevent this plan modifier from running when the resource is creating (i.e. the entire state is null), which it is achieving, but a little too aggressively since it checks the specific attribute's state value instead:
terraform-plugin-framework/resource/schema/stringplanmodifier/use_state_for_unknown.go
Lines 39 to 42 in 15bac5c
// Do nothing if there is no state value. | |
if req.StateValue.IsNull() { | |
return | |
} |
We should consider updating this logic to:
func (m useStateForUnknownModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
// NOTE: This is the bug fix, do nothing if we are creating
if req.State.Raw.IsNull() {
return
}
// Do nothing if there is a known planned value.
if !req.PlanValue.IsUnknown() {
return
}
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up.
if req.ConfigValue.IsUnknown() {
return
}
resp.PlanValue = req.StateValue
}
Actual Behavior
If the prior state value for computed_attr
is null
, an unknown value is being planned during update.
gdavison, bschaatsbergen, ewbankkit, jar-b, AtelierSnek and 3 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working