mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
test with bad interpolation during Input
The interpolation going into a module variable here will be valid after Refresh, but Refresh doesn't happen for the Input phase.
This commit is contained in:
parent
97bb7cb65c
commit
1664d4e228
@ -719,3 +719,57 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// In this case, a module variable can't be resolved from a data source until
|
||||
// it's refreshed, but it can't be refreshed during Input.
|
||||
func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) {
|
||||
input := new(MockUIInput)
|
||||
p := testProvider("null")
|
||||
m := testModule(t, "input-module-data-vars")
|
||||
|
||||
p.ReadDataDiffFn = testDataDiffFn
|
||||
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"data.null_data_source.bar": &ResourceState{
|
||||
Type: "null_data_source",
|
||||
Primary: &InstanceState{
|
||||
ID: "-",
|
||||
Attributes: map[string]string{
|
||||
"foo.#": "1",
|
||||
"foo.0": "a",
|
||||
// foo.1 exists in the data source, but needs to be refreshed.
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"null": testProviderFuncFixed(p),
|
||||
},
|
||||
),
|
||||
State: state,
|
||||
UIInput: input,
|
||||
})
|
||||
|
||||
if err := ctx.Input(InputModeStd); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// ensure that plan works after Refresh
|
||||
if _, err := ctx.Refresh(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
variable "in" {}
|
||||
|
||||
output "out" {
|
||||
value = "${var.in}"
|
||||
}
|
8
terraform/test-fixtures/input-module-data-vars/main.tf
Normal file
8
terraform/test-fixtures/input-module-data-vars/main.tf
Normal file
@ -0,0 +1,8 @@
|
||||
data "null_data_source" "bar" {
|
||||
foo = ["a", "b"]
|
||||
}
|
||||
|
||||
module "child" {
|
||||
source = "./child"
|
||||
in = "${data.null_data_source.bar.foo[1]}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user