mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: computed input variables work to modules
This commit is contained in:
parent
68b38b4904
commit
e8dfcdbe7b
@ -889,6 +889,11 @@ func (c *walkContext) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc {
|
|||||||
for k, v := range rc.Config {
|
for k, v := range rc.Config {
|
||||||
wc.Variables[k] = v.(string)
|
wc.Variables[k] = v.(string)
|
||||||
}
|
}
|
||||||
|
for k, _ := range rc.Raw {
|
||||||
|
if _, ok := wc.Variables[k]; !ok {
|
||||||
|
wc.Variables[k] = config.UnknownVariableValue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wc.Walk()
|
return wc.Walk()
|
||||||
|
@ -1474,6 +1474,29 @@ func TestContextPlan_moduleInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextPlan_moduleInputComputed(t *testing.T) {
|
||||||
|
m := testModule(t, "plan-module-input-computed")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
ctx := testContext(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, err := ctx.Plan(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(plan.String())
|
||||||
|
expected := strings.TrimSpace(testTerraformPlanModuleInputComputedStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad:\n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextPlan_moduleInputFromVar(t *testing.T) {
|
func TestContextPlan_moduleInputFromVar(t *testing.T) {
|
||||||
m := testModule(t, "plan-module-input-var")
|
m := testModule(t, "plan-module-input-var")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
@ -528,6 +528,23 @@ STATE:
|
|||||||
<no state>
|
<no state>
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testTerraformPlanModuleInputComputedStr = `
|
||||||
|
DIFF:
|
||||||
|
|
||||||
|
CREATE: aws_instance.bar
|
||||||
|
foo: "" => "<computed>"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
|
||||||
|
module.child:
|
||||||
|
CREATE: aws_instance.foo
|
||||||
|
foo: "" => "<computed>"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
|
||||||
|
STATE:
|
||||||
|
|
||||||
|
<no state>
|
||||||
|
`
|
||||||
|
|
||||||
const testTerraformPlanModuleInputVarStr = `
|
const testTerraformPlanModuleInputVarStr = `
|
||||||
DIFF:
|
DIFF:
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
variable "input" {}
|
||||||
|
|
||||||
|
resource "aws_instance" "foo" {
|
||||||
|
foo = "${var.input}"
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
module "child" {
|
||||||
|
input = "${aws_instance.bar.foo}"
|
||||||
|
source = "./child"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
compute = "foo"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user