addrs: implement String for AbsResource and AbsResourceInstance

This commit is contained in:
Martin Atkins 2018-04-23 16:56:16 -07:00
parent a09498a8a3
commit 8ca174b133
1 changed files with 18 additions and 4 deletions

View File

@ -68,6 +68,12 @@ func (r ResourceInstance) Absolute(module ModuleInstance) AbsResourceInstance {
} }
} }
// AbsResource is an absolute address for a resource under a given module path.
type AbsResource struct {
Module ModuleInstance
Resource Resource
}
// Resource returns the address of a particular resource within the receiver. // Resource returns the address of a particular resource within the receiver.
func (m ModuleInstance) Resource(mode ResourceMode, typeName string, name string) AbsResource { func (m ModuleInstance) Resource(mode ResourceMode, typeName string, name string) AbsResource {
return AbsResource{ return AbsResource{
@ -80,10 +86,11 @@ func (m ModuleInstance) Resource(mode ResourceMode, typeName string, name string
} }
} }
// AbsResource is an absolute address for a resource under a given module path. func (r AbsResource) String() string {
type AbsResource struct { if len(r.Module) == 0 {
Module ModuleInstance return r.Resource.String()
Resource Resource }
return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String())
} }
// AbsResourceInstance is an absolute address for a resource instance under a // AbsResourceInstance is an absolute address for a resource instance under a
@ -108,6 +115,13 @@ func (m ModuleInstance) ResourceInstance(mode ResourceMode, typeName string, nam
} }
} }
func (r AbsResourceInstance) String() string {
if len(r.Module) == 0 {
return r.Resource.String()
}
return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String())
}
// ResourceMode defines which lifecycle applies to a given resource. Each // ResourceMode defines which lifecycle applies to a given resource. Each
// resource lifecycle has a slightly different address format. // resource lifecycle has a slightly different address format.
type ResourceMode rune type ResourceMode rune