Skip to content

Commit

Permalink
Add metadata functions -json command
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Feb 8, 2023
1 parent d6bea08 commit c410148
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tfexec/metadata_functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tfexec

import (
"context"
"fmt"
"os/exec"

tfjson "github.com/hashicorp/terraform-json"
)

// MetadataFunctions represents the terraform metadata functions -json subcommand.
func (tf *Terraform) MetadataFunctions(ctx context.Context) (*tfjson.MetadataFunctions, error) {
err := tf.compatible(ctx, tf1_4_0, nil)
if err != nil {
return nil, fmt.Errorf("terraform metadata functions was added in 1.4.0: %w", err)
}

functionsCmd := tf.metadataFunctionsCmd(ctx)

var ret tfjson.MetadataFunctions
err = tf.runTerraformCmdJSON(ctx, functionsCmd, &ret)
if err != nil {
return nil, err
}

err = ret.Validate()
if err != nil {
return nil, err
}

return &ret, nil
}

func (tf *Terraform) metadataFunctionsCmd(ctx context.Context, args ...string) *exec.Cmd {
allArgs := []string{"metadata", "functions", "-json"}
allArgs = append(allArgs, args...)

return tf.buildTerraformCmd(ctx, nil, allArgs...)
}
1 change: 1 addition & 0 deletions tfexec/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
tf0_15_2 = version.Must(version.NewVersion("0.15.2"))
tf0_15_3 = version.Must(version.NewVersion("0.15.3"))
tf1_1_0 = version.Must(version.NewVersion("1.1.0"))
tf1_4_0 = version.Must(version.NewVersion("1.4.0"))
)

// Version returns structured output from the terraform version command including both the Terraform CLI version
Expand Down

0 comments on commit c410148

Please sign in to comment.