Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions that run Terraform commands with -json flag #353

Closed
bendbennett opened this issue Jan 10, 2023 · 1 comment · Fixed by #354
Closed

Add functions that run Terraform commands with -json flag #353

bendbennett opened this issue Jan 10, 2023 · 1 comment · Fixed by #354
Labels
enhancement New feature or request
Milestone

Comments

@bendbennett
Copy link
Contributor

Use Case

There are a number of instances in which it would be useful to execute Terraform commands (e.g., terraform apply) with the -json flag. For instance, in order to be able to robustly identify warnings that have been emitted during the execution of a Terraform command, it would be useful to be able to capture the JSON output from the command and subsequently parse and interrogate it.

Proposal

Add the following functions to terraform exec:

  • ApplyJSON(ctx context.Context, w io.Writer, opts ...ApplyOption) error
  • PlanJSON(ctx context.Context, w io.Writer, opts ...PlanOption) (bool, error)
  • RefreshJSON(ctx context.Context, w io.Writer, opts ...RefreshCmdOption) error
  • DestroyJSON(ctx context.Context, w io.Writer, opts ...DestroyOption) error

Note that Validate(ctx context.Context) (*tfjson.ValidateOutput, error) is already running terraform refresh with the -json flag

@bflad
Copy link
Member

bflad commented Jan 12, 2023

Related: #183

bendbennett added a commit that referenced this issue Jan 16, 2023
@bendbennett bendbennett added this to the v0.18.0 milestone Jan 19, 2023
bendbennett added a commit that referenced this issue Jan 20, 2023
bendbennett added a commit that referenced this issue Jan 20, 2023
bendbennett added a commit that referenced this issue Jan 23, 2023
radeksimko added a commit that referenced this issue Jan 24, 2023
…ions (#354)

* Adding ApplyJSON(), DestroyJSON(), PlanJSON() and RefreshJSON() functions (#353)

* Adding version compatibility check and e2e tests (#353)

* Add CHANGELOG entry (#353)

* Do not override TF version with version from matrix (#353)

* Consolidating runTest() (#353)

* Apply suggestions from code review

Co-authored-by: Radek Simko <radek.simko@gmail.com>

* Refactoring ...JSONCmd() functions to append -json flag as final flag in terraform command (#353)

* Adding comments to indicate that ...JSON() functions are likely to be removed in the future (#353)

Co-authored-by: Radek Simko <radek.simko@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants