Skip to content

Conversation

@SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Nov 17, 2025

Related Issue

N/A

Description

In hashicorp/terraform#34886 init commands were given some support for JSON output using the -json flag. Log messages from the init command are a mixture of types "log" and "init_output".

This PR adds some tests showing the current behaviour of how JSON logs from init are parsed. Currently terraform-json doesn't recognise the init_output type of log, so those logs are parsed as an unknown message type.

Also, this PR's test was made using output generated from Terraform using the code from PR hashicorp/terraform#37818. This demonstrates that parsing JSON logs is unaffected by that change, but just to be sure I added a test that generates timestamps in both formats and shows that both are parsed fine (though there are different levels of precision, expectedly).

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

N/A

@SarahFrench SarahFrench requested review from a team as code owners November 17, 2025 18:33
@SarahFrench
Copy link
Member Author

I might add an additional test that generates timestamps directly and shows no difference between the two formats in this PR hashicorp/terraform#37818

@SarahFrench SarahFrench changed the title test: Add tests for parsing logs from init commands test: Add tests for parsing logs from init commands, add github.com/hashicorp/go-hclog dependency to support this Nov 17, 2025
mildwonkey
mildwonkey previously approved these changes Nov 18, 2025
radeksimko
radeksimko previously approved these changes Nov 18, 2025
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very reasonable assuming it stays test-time dependency only - which I'm assuming is the intention. Correct me if I'm wrong.


Avoiding the runtime dependency on this library is important because tfjson has so far been a very light-weight library that maintained minimal impact on consumers.

Increasing the runtime dependency surface increases the chances of all kind of unnecessary noise in security scanners and maintenance efforts everywhere and ultimately the library should not need it at runtime because it produces logs but it's not meant to consume them.

@SarahFrench
Copy link
Member Author

This is very reasonable assuming it stays test-time dependency only - which I'm assuming is the intention. Correct me if I'm wrong.

Avoiding the runtime dependency on this library is important because tfjson has so far been a very light-weight library that maintained minimal impact on consumers.

Increasing the runtime dependency surface increases the chances of all kind of unnecessary noise in security scanners and maintenance efforts everywhere and ultimately the library should not need it at runtime because it produces logs but it's not meant to consume them.

Yeah, good point. I'll replace the use of the dependency with some string vars that show what the time looks like formatted in both ways, and a code comment to make it clear what's happening.

@SarahFrench SarahFrench dismissed stale reviews from radeksimko and mildwonkey via bac6efc November 19, 2025 13:13
@SarahFrench SarahFrench changed the title test: Add tests for parsing logs from init commands, add github.com/hashicorp/go-hclog dependency to support this test: Add tests for parsing logs from init commands, tests for parsing of RFC3339 timestamps with different levels of precision Nov 19, 2025
@SarahFrench SarahFrench merged commit eb52e87 into main Nov 21, 2025
14 checks passed
@SarahFrench SarahFrench deleted the sarah/add-tests-init-logs branch November 21, 2025 19:17
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.

3 participants