From f475b3b9312d481e43f8ee62b461448a5e2baffa Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 10 May 2018 15:30:52 -0700 Subject: [PATCH] core: Fix DiffTransformer node addresses In this codepath we're still using the old "internal" ResourceAddress parser to parse resource addresses from the diff, but the string being parsed does not include a module path and so the result is interpreted as a resource in the root module. We need to rewrite this to be in the correct module path as part of converting to the new address representation, in order to get a correct absolute address. --- terraform/transform_diff.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/terraform/transform_diff.go b/terraform/transform_diff.go index 8d73fbaa5..cfcc87751 100644 --- a/terraform/transform_diff.go +++ b/terraform/transform_diff.go @@ -42,7 +42,14 @@ func (t *DiffTransformer) Transform(g *Graph) error { panic(fmt.Sprintf( "Error parsing internal name, this is a bug: %q", name)) } + + // legacyAddr is relative even though the legacy ResourceAddress is + // usually absolute, so we need to do some trickery here to get + // a new-style absolute address in the right module. + // FIXME: Clean this up once the "Diff" types are updated to use + // our new address types. addr := legacyAddr.AbsResourceInstanceAddr() + addr = addr.Resource.Absolute(normalizeModulePath(m.Path)) // If we're destroying, add the destroy node if inst.Destroy || inst.GetDestroyDeposed() {