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:
parent
df104e9b15
commit
e62801bb58
4
cli.go
4
cli.go
@ -21,9 +21,9 @@ func gatherResources(s *state) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(s.outputs()) > 0 {
|
if len(s.outputs()) > 0 {
|
||||||
groups["all"] = make(map[string]string, 0)
|
groups["all"] = make(map[string]interface{}, 0)
|
||||||
for _, out := range s.outputs() {
|
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
|
return groups
|
||||||
|
@ -8,10 +8,10 @@ type Output struct {
|
|||||||
|
|
||||||
// The keyName and value of the output
|
// The keyName and value of the output
|
||||||
keyName string
|
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?
|
// TODO: Warn instead of silently ignore error?
|
||||||
if len(keyName) == 0 {
|
if len(keyName) == 0 {
|
||||||
|
@ -35,10 +35,10 @@ func (s *state) outputs() []*Output {
|
|||||||
|
|
||||||
for _, m := range s.Modules {
|
for _, m := range s.Modules {
|
||||||
for k, v := range m.Outputs {
|
for k, v := range m.Outputs {
|
||||||
var o *Output;
|
var o *Output
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
o, _ = NewOutput(k, v["value"].(string))
|
o, _ = NewOutput(k, v["value"])
|
||||||
case string:
|
case string:
|
||||||
o, _ = NewOutput(k, v)
|
o, _ = NewOutput(k, v)
|
||||||
default:
|
default:
|
||||||
|
@ -24,7 +24,17 @@ const exampleStateFile = `
|
|||||||
"sensitive": false,
|
"sensitive": false,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "mydc"
|
"value": "mydc"
|
||||||
}
|
},
|
||||||
|
"ids": {
|
||||||
|
"type": "list",
|
||||||
|
"value": [1, 2, 3, 4]
|
||||||
|
},
|
||||||
|
"map": {
|
||||||
|
"type": "map",
|
||||||
|
"value": {
|
||||||
|
"key": "value"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"resources": {
|
"resources": {
|
||||||
"aws_instance.one.0": {
|
"aws_instance.one.0": {
|
||||||
@ -129,7 +139,7 @@ const exampleStateFile = `
|
|||||||
|
|
||||||
const expectedListOutput = `
|
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"],
|
"one": ["10.0.0.1", "10.0.1.1"],
|
||||||
"two": ["50.0.0.1"],
|
"two": ["50.0.0.1"],
|
||||||
"three": ["192.168.0.3"],
|
"three": ["192.168.0.3"],
|
||||||
|
Loading…
Reference in New Issue
Block a user