|
|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
package addrs
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Resource is an address for a resource block within configuration, which
|
|
|
|
|
// contains potentially-multiple resource instances if that configuration
|
|
|
|
|
// block uses "count" or "for_each".
|
|
|
|
|
@ -10,6 +14,17 @@ type Resource struct {
|
|
|
|
|
Name string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r Resource) String() string {
|
|
|
|
|
switch r.Mode {
|
|
|
|
|
case ManagedResourceMode:
|
|
|
|
|
return fmt.Sprintf("%s.%s", r.Type, r.Name)
|
|
|
|
|
case DataResourceMode:
|
|
|
|
|
return fmt.Sprintf("data.%s.%s", r.Type, r.Name)
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Errorf("resource address with invalid mode %s", r.Mode))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Instance produces the address for a specific instance of the receiver
|
|
|
|
|
// that is idenfied by the given key.
|
|
|
|
|
func (r Resource) Instance(key InstanceKey) ResourceInstance {
|
|
|
|
|
@ -37,6 +52,13 @@ type ResourceInstance struct {
|
|
|
|
|
Key InstanceKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r ResourceInstance) String() string {
|
|
|
|
|
if r.Key == NoKey {
|
|
|
|
|
return r.Resource.String()
|
|
|
|
|
}
|
|
|
|
|
return r.Resource.String() + r.Key.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Absolute returns an AbsResourceInstance from the receiver and the given module
|
|
|
|
|
// instance address.
|
|
|
|
|
func (r ResourceInstance) Absolute(module ModuleInstance) AbsResourceInstance {
|
|
|
|
|
|