Skip to content

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

@bendbennett

Description

@bendbennett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions