core: ParseResourceAddressForInstanceDiff function

This is a specialized thin wrapper around parseResourceAddressInternal
that can be used to obtain a ResourceAddress from the keys in
ModuleDiff.Resources.

This is not something we'd ideally expose, but since the internal address
format is already exposed in the ModuleDiff object this ends up being
necessary to process the ModuleDiff from other packages, e.g. for
display in the UI.
This commit is contained in:
Martin Atkins 2017-06-21 18:08:37 -07:00
parent 482c1f1ea5
commit 53c0ff4017
1 changed files with 22 additions and 0 deletions

View File

@ -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.
//