Skip to content

Conversation

bschaatsbergen
Copy link
Contributor

@bschaatsbergen bschaatsbergen commented Oct 6, 2024

Fixes #442

  • refactor tfexec/init.go to facilitate (split some code into distinct functions) the support the new InitJSON function, similar to ApplyJSON and PlanJSON.
  • Added InitJSON functions.
  • Added cmd and E2E tests.

refactors `tfexec/init.go` by splitting the init functions into distinct functions to facilitate the support of the new InitJSON function.

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
The `InitJSON` and `initJSONCmd` functions append the `-json` argument to instruct the init command to write machine-readable JSON to the supplied `io.Writer`.

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
@bschaatsbergen bschaatsbergen marked this pull request as ready for review October 6, 2024 16:22
@bschaatsbergen bschaatsbergen requested review from a team as code owners October 6, 2024 16:22
…de positional arguments.

Since the optional positional directory argument must follow all flags, as flags precede positional arguments, we append it to the args list only after all flags have been added.

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
dbanck
dbanck previously approved these changes Jan 20, 2025
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and sorry that it took us so long to review!

We're fine with the proposed API, but we expect it to change a bit in the future as we come closer to version 1.0*

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>
bschaatsbergen and others added 2 commits January 20, 2025 12:28
Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>
Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>
@radeksimko
Copy link
Member

We're fine with the proposed API, but we expect it to change a bit in the future as we come closer to version 1.0 *

^ it's likely there will be only one Init() method that by default passes the -json flag. We just need to figure out whether it's common enough ask for people to read the output, i.e. if we should also be unmarshaling it by default and returning some types or stream or something.

We face the same problem with plan and apply structured output to be fair - so we'll need to figure out how to model the API there as well and ideally do it the same way.

@dbanck dbanck merged commit abfb5ba into hashicorp:main Jan 20, 2025
113 checks passed
@bschaatsbergen bschaatsbergen deleted the f/add-initjson branch January 20, 2025 12:32
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.

Support terraform init JSON output (coming soon)
3 participants