Skip to content

Commit 8135fef

Browse files
author
Liam Cervante
authored
terraform test: stop transforming the config under test with new variables (#37152)
1 parent d8d890f commit 8135fef

File tree

3 files changed

+2
-40
lines changed

3 files changed

+2
-40
lines changed

internal/moduletest/graph/apply.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ func (n *NodeTestRun) testApply(ctx *EvalContext, variables terraform.InputValue
7272
return
7373
}
7474

75-
n.AddVariablesToConfig(variables)
76-
7775
if ctx.Verbose() {
7876
schemas, diags := tfCtx.Schemas(config, updated)
7977

internal/moduletest/graph/plan.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func (n *NodeTestRun) testPlan(ctx *EvalContext, variables terraform.InputValues
4040
return
4141
}
4242

43-
n.AddVariablesToConfig(variables)
44-
4543
if ctx.Verbose() {
4644
schemas, diags := tfCtx.Schemas(config, plan.PriorState)
4745

internal/moduletest/graph/variables.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"fmt"
88

99
"github.com/hashicorp/hcl/v2"
10+
"github.com/zclconf/go-cty/cty"
11+
1012
"github.com/hashicorp/terraform/internal/addrs"
11-
"github.com/hashicorp/terraform/internal/configs"
1213
"github.com/hashicorp/terraform/internal/lang/langrefs"
1314
hcltest "github.com/hashicorp/terraform/internal/moduletest/hcl"
1415
"github.com/hashicorp/terraform/internal/terraform"
1516
"github.com/hashicorp/terraform/internal/tfdiags"
16-
"github.com/zclconf/go-cty/cty"
1717
)
1818

1919
// GetVariables builds the terraform.InputValues required for the provided run
@@ -203,37 +203,3 @@ func (n *NodeTestRun) FilterVariablesToModule(values terraform.InputValues) (mod
203203
}
204204
return moduleVars, testOnlyVars, diags
205205
}
206-
207-
// AddVariablesToConfig extends the provided config to ensure it has definitions
208-
// for all specified variables.
209-
//
210-
// This function is essentially the opposite of FilterVariablesToConfig which
211-
// makes the variables match the config rather than the config match the
212-
// variables.
213-
func (n *NodeTestRun) AddVariablesToConfig(variables terraform.InputValues) {
214-
run := n.run
215-
// If we have got variable values from the test file we need to make sure
216-
// they have an equivalent entry in the configuration. We're going to do
217-
// that dynamically here.
218-
219-
// First, take a backup of the existing configuration so we can easily
220-
// restore it later.
221-
currentVars := make(map[string]*configs.Variable)
222-
for name, variable := range run.ModuleConfig.Module.Variables {
223-
currentVars[name] = variable
224-
}
225-
226-
for name, value := range variables {
227-
if _, exists := run.ModuleConfig.Module.Variables[name]; exists {
228-
continue
229-
}
230-
231-
run.ModuleConfig.Module.Variables[name] = &configs.Variable{
232-
Name: name,
233-
Type: value.Value.Type(),
234-
ConstraintType: value.Value.Type(),
235-
DeclRange: value.SourceRange.ToHCL(),
236-
}
237-
}
238-
239-
}

0 commit comments

Comments
 (0)