Skip to content

Conversation

@vietcgi
Copy link
Contributor

@vietcgi vietcgi commented Nov 19, 2025

Problem

When running terraform init -json, some backend configuration messages were output as plain text instead of JSON.

Solution

Replaced 11 m.Ui.Output() calls in backend code with View abstraction, which properly formats output based on the -json flag.

Changes

  • Added 11 message codes to init.go MessageRegistry
  • Updated 4 functions to use View abstraction for all backend messages

Testing

  • All init tests pass
  • Tested on macOS and Linux
  • Cross-compiled for all platforms

Fixes #37911

Fixes hashicorp#37911 by converting all backend configuration messages to use the
View abstraction, which properly formats output as JSON when the -json flag
is used. Previously, certain messages were output directly using the legacy
Ui abstraction, bypassing JSON formatting.

Changes:
- Added 11 new message codes to init.go MessageRegistry with both human
  and JSON formatted values
- Replaced 11 direct m.Ui.Output() calls in meta_backend.go with View
  abstraction calls
- Fixed output in backend_C_r_s(), backend_C_r_S_changed(), backend_c_r_S(),
  and stateStore_c_S() functions

All init tests pass successfully.
@vietcgi vietcgi requested a review from a team as a code owner November 19, 2025 18:38
@vietcgi vietcgi closed this Nov 19, 2025
@vietcgi vietcgi reopened this Nov 19, 2025
The following constants were moved to init.go as message registry entries
and are no longer used in meta_backend.go:
- outputBackendMigrateChange
- outputBackendMigrateLocal
- outputStateStoreMigrateLocal
- outputBackendReconfigure
- successBackendUnset
- successBackendSet
@crw crw added the bug label Nov 20, 2025
@crw
Copy link
Contributor

crw commented Nov 20, 2025

Thanks for this submission, I will bring it to triage.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not all messages are in JSON format when running terraform init -json

2 participants