-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
metadata functions -json
command
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters