diff --git a/parser.go b/parser.go index 0af33fd..617d167 100644 --- a/parser.go +++ b/parser.go @@ -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 } } } diff --git a/parser_test.go b/parser_test.go index 6a23eca..0387020 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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) }