Skip to content

fix_block_reorgs and keep_distance_from_tip set to 0 can produce a permanent Terraform diff #84

Description

@dumanoglu1

Summary

fix_block_reorgs = 0 and keep_distance_from_tip = 0 are valid Terraform config values, but readStreamFromAPI() converts API responses of 0 into types.Int64Null() when refreshing state. That can produce a permanent config 0 vs state null diff for these optional, non-computed fields.

Where

internal/provider/stream_resource.go currently special-cases zero values in readStreamFromAPI():

if fixBlockReorgs, ok := result["fix_block_reorgs"].(float64); ok {
    if fixBlockReorgs == 0 {
        data.FixBlockReorgs = types.Int64Null()
    } else {
        data.FixBlockReorgs = types.Int64Value(int64(fixBlockReorgs))
    }
}

The same pattern is used for keep_distance_from_tip.

Why this matters

Both attributes are schema.Int64Attribute{Optional: true} and their validators allow 0. Since they are not Computed, Terraform expects provider state to preserve a configured zero value after refresh. Collapsing API 0 to null makes an explicit user config indistinguishable from an omitted field and can leave a never-resolving plan diff.

Expected behavior

If the API response includes either field, the provider should preserve the numeric value exactly, including 0. If the API omits the field entirely, leaving it null is still fine.

Proposed fix

Remove the 0 -> types.Int64Null() special case and set:

data.FixBlockReorgs = types.Int64Value(int64(fixBlockReorgs))
data.KeepDistanceFromTip = types.Int64Value(int64(keepDistanceFromTip))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions