forked from jetstack/tarmak
-
Notifications
You must be signed in to change notification settings - Fork 2
/
output.go
51 lines (40 loc) · 1.04 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Jetstack Ltd. See LICENSE for details.
package terraform
import (
"bytes"
"fmt"
"encoding/json"
"github.com/jetstack/tarmak/pkg/tarmak/interfaces"
)
type terraformOutputValue struct {
Sensitive bool `json:"sensitive,omitifempty"`
Type string `json:"type,omitifempty"`
Value interface{} `value:"type,omitifempty"`
}
func (t *Terraform) Output(c interfaces.Cluster) (map[string]interface{}, error) {
stdOutBuf := new(bytes.Buffer)
stdErrBuf := new(bytes.Buffer)
if err := t.command(
c,
[]string{
"terraform",
"output",
"-json",
},
nil,
stdOutBuf,
stdErrBuf,
); err != nil {
t.log.Error(stdErrBuf.String())
return nil, fmt.Errorf("error getting terraform output: %s", err)
}
var values map[string]terraformOutputValue
if err := json.Unmarshal(stdOutBuf.Bytes(), &values); err != nil {
return nil, fmt.Errorf("error parsing JSON: %s", err)
}
variables := make(map[string]interface{})
for key, value := range values {
variables[key] = value.Value
}
return variables, nil
}