1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-23 00:12:13 +01:00

allow for non-string outputs (#45)

This commit is contained in:
Isao Jonas 2016-09-06 22:05:30 -05:00 committed by Adam Mckaig
parent df104e9b15
commit e62801bb58
4 changed files with 18 additions and 8 deletions

4
cli.go

@ -21,9 +21,9 @@ func gatherResources(s *state) map[string]interface{} {
}
if len(s.outputs()) > 0 {
groups["all"] = make(map[string]string, 0)
groups["all"] = make(map[string]interface{}, 0)
for _, out := range s.outputs() {
groups["all"].(map[string]string)[out.keyName] = out.value
groups["all"].(map[string]interface{})[out.keyName] = out.value
}
}
return groups

@ -8,10 +8,10 @@ type Output struct {
// The keyName and value of the output
keyName string
value string
value interface{}
}
func NewOutput(keyName string, value string) (*Output, error) {
func NewOutput(keyName string, value interface{}) (*Output, error) {
// TODO: Warn instead of silently ignore error?
if len(keyName) == 0 {

@ -35,10 +35,10 @@ func (s *state) outputs() []*Output {
for _, m := range s.Modules {
for k, v := range m.Outputs {
var o *Output;
var o *Output
switch v := v.(type) {
case map[string]interface{}:
o, _ = NewOutput(k, v["value"].(string))
o, _ = NewOutput(k, v["value"])
case string:
o, _ = NewOutput(k, v)
default:

@ -24,6 +24,16 @@ const exampleStateFile = `
"sensitive": false,
"type": "string",
"value": "mydc"
},
"ids": {
"type": "list",
"value": [1, 2, 3, 4]
},
"map": {
"type": "map",
"value": {
"key": "value"
}
}
},
"resources": {
@ -129,7 +139,7 @@ const exampleStateFile = `
const expectedListOutput = `
{
"all": {"datacenter": "mydc", "olddatacenter": "<0.7_format"},
"all": {"datacenter": "mydc", "olddatacenter": "<0.7_format", "ids": [1, 2, 3, 4], "map": {"key": "value"}},
"one": ["10.0.0.1", "10.0.1.1"],
"two": ["50.0.0.1"],
"three": ["192.168.0.3"],