terraform: Changing how instances are represented

This commit is contained in:
Armon Dadgar 2014-09-15 17:49:31 -07:00
parent f5fc4933e5
commit 9cbd71b88d
2 changed files with 22 additions and 20 deletions

View File

@ -372,8 +372,7 @@ func (c *Context) computeResourceVariable(
v.FullKey()) v.FullKey())
} }
primary := r.Primary() attr, ok := r.Primary.Attributes[v.Field]
attr, ok := primary.Attributes[v.Field]
if ok { if ok {
return attr, nil return attr, nil
} }
@ -386,7 +385,7 @@ func (c *Context) computeResourceVariable(
if len(parts) > 1 { if len(parts) > 1 {
for i := 1; i < len(parts); i++ { for i := 1; i < len(parts); i++ {
key := fmt.Sprintf("%s.#", strings.Join(parts[:i], ".")) key := fmt.Sprintf("%s.#", strings.Join(parts[:i], "."))
if attr, ok := primary.Attributes[key]; ok { if attr, ok := r.Primary.Attributes[key]; ok {
return attr, nil return attr, nil
} }
} }
@ -440,8 +439,7 @@ func (c *Context) computeResourceMultiVariable(
continue continue
} }
primary := r.Primary() attr, ok := r.Primary.Attributes[v.Field]
attr, ok := primary.Attributes[v.Field]
if !ok { if !ok {
continue continue
} }
@ -546,8 +544,8 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
} }
// If we do not have any connection info, initialize // If we do not have any connection info, initialize
if r.State.ConnInfo == nil { if r.State.Primary.Ephemeral.ConnInfo == nil {
r.State.ConnInfo = make(map[string]string) r.State.Primary.Ephemeral.init()
} }
// Remove any output values from the diff // Remove any output values from the diff

View File

@ -140,20 +140,18 @@ type ResourceState struct {
// worry about it. // worry about it.
Dependencies []string `json:"depends_on,omitempty"` Dependencies []string `json:"depends_on,omitempty"`
// Instances is used to track all of the underlying instances // Primary is the current active instance for this resource.
// have been created as part of this logical resource. In the // It can be replaced but only after a successful creation.
// standard case, there is only a single underlying instance. // This is the instances on which providers will act.
// However, in pathological cases, it is possible for the number Primary *InstanceState `json:"primary"`
// of instances to accumulate. The first instance in the list is
// the "primary" and the others should be removed on subsequent
// apply operations.
Instances []*InstanceState `json:"instances"`
}
// Primary is used to return the primary instance. This is the // Tainted is used to track any underlying instances that
// active instance that should be used for attribute interpolation // have been created but are in a bad or unknown state and
func (r *ResourceState) Primary() *InstanceState { // need to be cleaned up subsequently. In the
return r.Instances[0] // standard case, there is only at most a single instance.
// However, in pathological cases, it is possible for the number
// of instances to accumulate.
Tainted []*InstanceState `json:"tainted,omitempty"`
} }
func (r *ResourceState) deepcopy() *ResourceState { func (r *ResourceState) deepcopy() *ResourceState {
@ -227,6 +225,12 @@ type EphemeralState struct {
ConnInfo map[string]string `json:"-"` ConnInfo map[string]string `json:"-"`
} }
func (e *EphemeralState) init() {
if e.ConnInfo == nil {
e.ConnInfo = make(map[string]string)
}
}
func (e *EphemeralState) deepcopy() *EphemeralState { func (e *EphemeralState) deepcopy() *EphemeralState {
n := &EphemeralState{ n := &EphemeralState{
ConnInfo: make(map[string]string, len(n.ConnInfo)), ConnInfo: make(map[string]string, len(n.ConnInfo)),