mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: Input should only be called on providers once
/cc @sethvargo Prior to this commit, we'd only persist the result of calling Input if any input was given (len(result) > 0). The result was that every module would also repeat asking for input even if there was no input to be asked for. This commit makes it so that if no input was received, we still set a sentinel so that modules don't re-ask.
This commit is contained in:
parent
09ea85a7c6
commit
40ee70d5c9
@ -2463,6 +2463,33 @@ func TestContext2Input_provider(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Input_providerOnce(t *testing.T) {
|
||||
m := testModule(t, "input-provider-once")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
count := 0
|
||||
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
|
||||
count++
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err := ctx.Input(InputModeStd); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Fatalf("should only be called once: %d", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Input_providerId(t *testing.T) {
|
||||
input := new(MockUIInput)
|
||||
m := testModule(t, "input-provider")
|
||||
|
@ -99,9 +99,12 @@ func (n *EvalInputProvider) Eval(ctx EvalContext) (interface{}, error) {
|
||||
"Error configuring %s: %s", n.Name, err)
|
||||
}
|
||||
|
||||
// Set the input that we received so that child modules don't attempt
|
||||
// to ask for input again.
|
||||
if config != nil && len(config.Config) > 0 {
|
||||
// Set the configuration
|
||||
ctx.SetProviderInput(n.Name, config.Config)
|
||||
} else {
|
||||
ctx.SetProviderInput(n.Name, map[string]interface{}{})
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
@ -0,0 +1,2 @@
|
||||
provider "aws" {}
|
||||
resource "aws_instance" "bar" {}
|
5
terraform/test-fixtures/input-provider-once/main.tf
Normal file
5
terraform/test-fixtures/input-provider-once/main.tf
Normal file
@ -0,0 +1,5 @@
|
||||
resource "aws_instance" "foo" {}
|
||||
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
Loading…
Reference in New Issue
Block a user