Merge pull request #2988 from hashicorp/b-input-var-partially-computed
core: don't error on computed value during input walk
This commit is contained in:
commit
c39fdd2917
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -378,7 +378,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
|
||||
}
|
||||
|
||||
|
@ -469,7 +475,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
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
variable "in" {}
|
||||
|
||||
resource "aws_instance" "mod" {
|
||||
value = "${var.in}"
|
||||
}
|
|
@ -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}"
|
||||
}
|
Loading…
Reference in New Issue