Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: don't error on computed value during input walk #2988

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions terraform/context_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,62 @@ aws_instance.foo:
t.Fatalf("expected: \n%s\ngot: \n%s\n", expectedStr, actualStr)
}
}

func TestContext2Input_varPartiallyComputed(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-var-partially-computed")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]string{
"foo": "foovalue",
},
UIInput: input,
State: &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "i-abc123",
Attributes: map[string]string{
"id": "i-abc123",
},
},
},
},
},
&ModuleState{
Path: append(rootModulePath, "child"),
Resources: map[string]*ResourceState{
"aws_instance.mod": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "i-bcd345",
Attributes: map[string]string{
"id": "i-bcd345",
"value": "one,i-abc123",
},
},
},
},
},
},
},
})

if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}

if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
}
16 changes: 14 additions & 2 deletions terraform/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ MISSING:
// 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 || i.Operation == walkPlanDestroy {
//
// For a Destroy, we're also fine with computed values, since our goal is
// only to get destroy nodes for existing resources.
//
// For an input walk, computed values are okay to return because we're only
// looking for missing variables to prompt the user for.
if i.Operation == walkRefresh || i.Operation == walkPlanDestroy || i.Operation == walkInput {
return config.UnknownVariableValue, nil
}

Expand Down Expand Up @@ -446,7 +452,13 @@ func (i *Interpolater) computeResourceMultiVariable(
// 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 || i.Operation == walkPlanDestroy {
//
// For a Destroy, we're also fine with computed values, since our goal is
// only to get destroy nodes for existing resources.
//
// For an input walk, computed values are okay to return because we're only
// looking for missing variables to prompt the user for.
if i.Operation == walkRefresh || i.Operation == walkPlanDestroy || i.Operation == walkInput {
return config.UnknownVariableValue, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "in" {}

resource "aws_instance" "mod" {
value = "${var.in}"
}
7 changes: 7 additions & 0 deletions terraform/test-fixtures/input-var-partially-computed/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_instance" "foo" { }
resource "aws_instance" "bar" { }

module "child" {
source = "./child"
in = "one,${aws_instance.foo.id},${aws_instance.bar.id}"
}