in ec/ecresource/deploymentresource/elasticsearch/v2/node_roles.go [134:186]
func useStateAndNodeRolesInPlanModifiers(ctx context.Context, configValue attr.Value, plan tfsdk.Plan, state tfsdk.State, planValue attr.Value) (useState bool, useNodeRoles bool, diags diag.Diagnostics) {
if !planValue.IsUnknown() {
return false, false, nil
}
if configValue.IsUnknown() {
return false, false, nil
}
var stateVersion types.String
if diags := state.GetAttribute(ctx, path.Root("version"), &stateVersion); diags.HasError() {
return false, false, diags
}
// If resource has state, then it should contain version.
// So if there is no version in state, plan modifier is called for Create.
// In that case there is no state to use.
// We cannot use StateValue from request parameter for this purpose,
// because null can be a valid state for node_roles and node_types in Update.
// E.g. node_roles' state can be null if node_types are used.
if stateVersion.IsNull() {
return false, false, nil
}
// if template changed return
templateChanged, diags := planmodifiers.AttributeChanged(ctx, path.Root("deployment_template_id"), plan, state)
if diags.HasError() {
return false, false, diags
}
if templateChanged {
return false, false, nil
}
var planVersion types.String
if diags := plan.GetAttribute(ctx, path.Root("version"), &planVersion); diags.HasError() {
return false, false, diags
}
var elasticsearch types.Object
if diags := plan.GetAttribute(ctx, path.Root("elasticsearch"), &elasticsearch); diags.HasError() {
return false, false, diags
}
if useNodeRoles, diags = UseNodeRoles(ctx, stateVersion, planVersion, elasticsearch); diags.HasError() {
return false, false, diags
}
return true, useNodeRoles, nil
}