Fix minor issues and store state for private_networking atomically - #28
Open
Siddharth More (siddimore) wants to merge 1 commit into
Open
Siddharth More (siddimore) wants to merge 1 commit into
Siddharth More (siddimore) wants to merge 1 commit into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes six bugs across the
bootstrapandprivatenetworkingpackages covering state corruption, silent error swallowing, a production panic, and log stream contamination.Changes
private_networking.go: Non-atomic state write + error not propagated
Both the destroy and apply paths used
os.WriteFileto persist Terraform state a truncate-then-write that corrupts the state file if the process crashes mid-write.Fix: Exported
PersistTerraformStatefrom state_persistence.go.private_networking.go: All
os.Staterrors treated as "file not found"os.Staterrors on the state file were silently treated as "no state file exists", including permission errors and I/O errors. This caused Terraform to start from blank state, diverging from the real infrastructure state.Fix: Added
errors.Is(err, os.ErrNotExist)guardgcp.go:
panic(err)reachable from user inputpflag'sBooltype rejects empty string, so if a user entered an invalid boolean value would fail and trigger apanic. This crashed the CLI with a stack trace instead of a graceful error.Fix: Capture the error in a
visitErrclosure variable, skip remaining flags, and return it afterVisitAllcompletes. Added a comment explaining why the "impossible" case is actually reachable.state_migration_backup.go: Read error swallowed during backup verification
os.ReadFileandbytes.Equalerrors were collapsed into a single opaque"could not be verified"message with no underlying cause.Fix: Separated into two distinct checks
bootstrap.go: Dead variable and silent
MarshalJSONerrorjson.Unmarshalpopulated variablemthat was never used (raw bytes were printed directly).MarshalJSONerror was_-discarded — if it failed.Fix: Removed the
json.Unmarshallogger.go: Structured logs written to
stdoutinstead ofstderraws scopes addwrites a parseable scope-ref tocmd.OutOrStdout()for machine consumption. With logs on stdout, anyinfo-level log output contaminated that stream when piping or redirecting.Fix: Changed
os.Stdout→os.Stderr