Skip to content

Commit

Permalink
core: treat refs to unknown set resource attrs as unknown during plan
Browse files Browse the repository at this point in the history
References to computed list-ish attributes (set, list, map) were being
improperly resolved as an empty list `[]` during the plan phase (when
the value of the reference is not yet known) instead of as an
UnknownValue.

A "diffs didn't match" failure in an AWS DirectoryServices test led to
this discovery (and this commit fixes the failing test):

https://travis-ci.org/hashicorp/terraform/jobs/104812951

Refs #2157 which has the original work to support computed list
attributes at all. This is just a simple tweak to that work.

/cc @radeksimko
  • Loading branch information
phinze committed Jan 26, 2016
1 parent da4e775 commit 88252f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions terraform/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ func (i *Interpolater) interpolateListAttribute(
log.Printf("[DEBUG] Interpolating computed list attribute %s (%s)",
resourceID, attr)

if attr == config.UnknownVariableValue {
return attr, nil
}

var members []string
numberedListMember := regexp.MustCompile("^" + resourceID + "\\.[0-9]+$")
for id, value := range attributes {
Expand Down
36 changes: 36 additions & 0 deletions terraform/interpolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,42 @@ func TestInterpolator_resourceMultiAttributesWithResourceCount(t *testing.T) {
})
}

func TestInterpolator_resourceMultiAttributesComputed(t *testing.T) {
lock := new(sync.RWMutex)
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_route53_zone.yada": &ResourceState{
Type: "aws_route53_zone",
Primary: &InstanceState{
ID: "AAABBBCCCDDDEEE",
Attributes: map[string]string{
"name_servers.#": config.UnknownVariableValue,
},
},
},
},
},
},
}
i := &Interpolater{
Module: testModule(t, "interpolate-multi-vars"),
StateLock: lock,
State: state,
}

scope := &InterpolationScope{
Path: rootModulePath,
}

testInterpolate(t, i, scope, "aws_route53_zone.yada.name_servers", ast.Variable{
Value: config.UnknownVariableValue,
Type: ast.TypeString,
})
}

func getInterpolaterFixture(t *testing.T) *Interpolater {
lock := new(sync.RWMutex)
state := &State{
Expand Down

0 comments on commit 88252f4

Please sign in to comment.