mirror of
https://github.com/adammck/terraform-inventory
synced 2024-11-22 20:01:58 +01:00
New outputs
format in tfstate (#43)
* New `output` format in tfstate * Make `outputs` parser compatible with <0.7 terraform
This commit is contained in:
parent
9493db0fbd
commit
df104e9b15
13
parser.go
13
parser.go
@ -35,7 +35,16 @@ func (s *state) outputs() []*Output {
|
||||
|
||||
for _, m := range s.Modules {
|
||||
for k, v := range m.Outputs {
|
||||
o, _ := NewOutput(k, v)
|
||||
var o *Output;
|
||||
switch v := v.(type) {
|
||||
case map[string]interface{}:
|
||||
o, _ = NewOutput(k, v["value"].(string))
|
||||
case string:
|
||||
o, _ = NewOutput(k, v)
|
||||
default:
|
||||
o, _ = NewOutput(k, "<error>")
|
||||
}
|
||||
|
||||
inst = append(inst, o)
|
||||
}
|
||||
}
|
||||
@ -68,7 +77,7 @@ func (s *state) resources() []*Resource {
|
||||
|
||||
type moduleState struct {
|
||||
ResourceStates map[string]resourceState `json:"resources"`
|
||||
Outputs map[string]string `json:"outputs"`
|
||||
Outputs map[string]interface{} `json:"outputs"`
|
||||
}
|
||||
|
||||
// resourceKeys returns a sorted slice of the key names of the resources in this
|
||||
|
@ -18,9 +18,14 @@ const exampleStateFile = `
|
||||
"path": [
|
||||
"root"
|
||||
],
|
||||
"outputs": {
|
||||
"datacenter": "mydc"
|
||||
},
|
||||
"outputs": {
|
||||
"olddatacenter": "<0.7_format",
|
||||
"datacenter": {
|
||||
"sensitive": false,
|
||||
"type": "string",
|
||||
"value": "mydc"
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"aws_instance.one.0": {
|
||||
"type": "aws_instance",
|
||||
@ -124,7 +129,7 @@ const exampleStateFile = `
|
||||
|
||||
const expectedListOutput = `
|
||||
{
|
||||
"all": {"datacenter": "mydc"},
|
||||
"all": {"datacenter": "mydc", "olddatacenter": "<0.7_format"},
|
||||
"one": ["10.0.0.1", "10.0.1.1"],
|
||||
"two": ["50.0.0.1"],
|
||||
"three": ["192.168.0.3"],
|
||||
|
Loading…
Reference in New Issue
Block a user