Skip to content

Fix minor issues and store state for private_networking atomically - #28

Open
Siddharth More (siddimore) wants to merge 1 commit into
getditto:mainfrom
siddimore:fix/minorIssues
Open

Siddharth More (siddimore) wants to merge 1 commit into
getditto:mainfrom
siddimore:fix/minorIssues

Conversation

@siddimore

Copy link
Copy Markdown

Summary

Fixes six bugs across the bootstrap and privatenetworking packages 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.WriteFile to persist Terraform state a truncate-then-write that corrupts the state file if the process crashes mid-write.

Fix: Exported PersistTerraformState from state_persistence.go.

Note: privatenetworking is described as a temporary stopgap. If it's being retired soon, this fix may be unnecessary.


private_networking.go: All os.Stat errors treated as "file not found"

os.Stat errors 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) guard


gcp.go: panic(err) reachable from user input

pflag's Bool type rejects empty string, so if a user entered an invalid boolean value would fail and trigger a panic. This crashed the CLI with a stack trace instead of a graceful error.

Fix: Capture the error in a visitErr closure variable, skip remaining flags, and return it after VisitAll completes. Added a comment explaining why the "impossible" case is actually reachable.


state_migration_backup.go: Read error swallowed during backup verification

os.ReadFile and bytes.Equal errors 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 MarshalJSON error

json.Unmarshal populated variable m that was never used (raw bytes were printed directly). MarshalJSON error was _-discarded — if it failed.

Fix: Removed the json.Unmarshal


logger.go: Structured logs written to stdout instead of stderr

aws scopes add writes a parseable scope-ref to cmd.OutOrStdout() for machine consumption. With logs on stdout, any info-level log output contaminated that stream when piping or redirecting.

Fix: Changed os.Stdout → os.Stderr

@siddimore
Siddharth More (siddimore) requested a review from a team as a code owner August 5, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant