1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-22 15:52:01 +01:00

Remove aws_instance. prefix from host names

This commit is contained in:
Adam Mckaig 2015-02-09 15:09:40 -05:00
parent 2d1c7fdfd9
commit d536bd0748
2 changed files with 5 additions and 3 deletions

@ -4,6 +4,7 @@ import (
"io"
"io/ioutil"
"encoding/json"
"strings"
)
type state struct {
@ -36,7 +37,8 @@ func (s *state) instances() map[string]instanceState {
for _, m := range s.Modules {
for k, r := range m.Resources {
if r.Type == "aws_instance" {
inst[k] = r.Primary
name := strings.TrimPrefix(k, "aws_instance.")
inst[name] = r.Primary
}
}
}

@ -111,6 +111,6 @@ func TestInstances(t *testing.T) {
inst := s.instances()
assert.Equal(t, 2, len(inst))
assert.Equal(t, "i-aaaaaaaa", inst["aws_instance.one"].ID)
assert.Equal(t, "i-bbbbbbbb", inst["aws_instance.two"].ID)
assert.Equal(t, "i-aaaaaaaa", inst["one"].ID)
assert.Equal(t, "i-bbbbbbbb", inst["two"].ID)
}