Skip to content

Commit

Permalink
Merge pull request #2477 from hashicorp/b-module-computed-var
Browse files Browse the repository at this point in the history
terraform: module computed vars with splat vars don't error
  • Loading branch information
mitchellh committed Jun 25, 2015
2 parents 73f9d2b + 54b9616 commit c861f43
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,23 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
}
}

func TestContext2Refresh_moduleComputedVar(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-module-computed-var")
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})

// This was failing (see GH-2188) at some point, so this test just
// verifies that the failure goes away.
if _, err := ctx.Refresh(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestContext2Refresh_delete(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-basic")
Expand Down
8 changes: 8 additions & 0 deletions terraform/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ func (i *Interpolater) computeResourceMultiVariable(
}

if len(values) == 0 {
// If the operation is refresh, it isn't an error for a value to
// be unknown. Instead, we return that the value is computed so
// that the graph can continue to refresh other nodes. It doesn't
// matter because the config isn't interpolated anyways.
if i.Operation == walkRefresh {
return config.UnknownVariableValue, nil
}

return "", fmt.Errorf(
"Resource '%s' does not have attribute '%s' "+
"for variable '%s'",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "value" {}

output "value" {
value = "${var.value}"
}
8 changes: 8 additions & 0 deletions terraform/test-fixtures/refresh-module-computed-var/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "child" {
source = "./child"
value = "${join(" ", aws_instance.test.*.id)}"
}

resource "aws_instance" "test" {
value = "yes"
}

0 comments on commit c861f43

Please sign in to comment.