diff --git a/terraform/resource_address.go b/terraform/resource_address.go index c6752d796..8badca805 100644 --- a/terraform/resource_address.go +++ b/terraform/resource_address.go @@ -248,6 +248,28 @@ func ParseResourceAddress(s string) (*ResourceAddress, error) { }, nil } +// ParseResourceAddressForInstanceDiff creates a ResourceAddress for a +// resource name as described in a module diff. +// +// For historical reasons a different addressing format is used in this +// context. The internal format should not be shown in the UI and instead +// this function should be used to translate to a ResourceAddress and +// then, where appropriate, use the String method to produce a canonical +// resource address string for display in the UI. +// +// The given path slice must be empty (or nil) for the root module, and +// otherwise consist of a sequence of module names traversing down into +// the module tree. If a non-nil path is provided, the caller must not +// modify its underlying array after passing it to this function. +func ParseResourceAddressForInstanceDiff(path []string, key string) (*ResourceAddress, error) { + addr, err := parseResourceAddressInternal(key) + if err != nil { + return nil, err + } + addr.Path = path + return addr, nil +} + // Contains returns true if and only if the given node is contained within // the receiver. //