Skip to content

Commit f6fb8f4

Browse files
committed
Merge pull request #4 from gruntwork-io/get-output
Add a command to fetch a terraform output
2 parents 10bfae2 + f310102 commit f6fb8f4

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

output.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package terratest
2+
3+
import (
4+
"github.com/gruntwork-io/terratest/terraform"
5+
"github.com/gruntwork-io/terratest/log"
6+
)
7+
8+
func Output(ao *ApplyOptions, key string) (string, error) {
9+
logger := log.NewLogger(ao.TestName)
10+
return terraform.Output(ao.TemplatePath, key, logger)
11+
}

terraform/output.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package terraform
2+
3+
import (
4+
"log"
5+
"github.com/gruntwork-io/terratest/shell"
6+
"strings"
7+
)
8+
9+
func Output(templatePath string, key string, logger *log.Logger) (string, error) {
10+
logger.Println("Getting Terraform output for key", key, "in folder", templatePath)
11+
output, err := shell.RunCommandAndGetOutput(shell.Command { Command: "terraform", Args: []string{"output", "-no-color", key}, WorkingDir: templatePath }, logger)
12+
if err != nil {
13+
return "", err
14+
} else {
15+
return strings.TrimSpace(output), nil
16+
}
17+
}

0 commit comments

Comments
 (0)