mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Test for local variables in provider block
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
This commit is contained in:
parent
3d635da47f
commit
c692d072b3
@ -170,6 +170,10 @@ func TestTest(t *testing.T) {
|
||||
expected: "1 passed, 0 failed.",
|
||||
code: 0,
|
||||
},
|
||||
"local_variables_in_provider_block": {
|
||||
expected: "1 passed, 0 failed.",
|
||||
code: 0,
|
||||
},
|
||||
}
|
||||
for name, tc := range tcs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
8
internal/command/testdata/test/local_variables_in_provider_block/main.tf
vendored
Normal file
8
internal/command/testdata/test/local_variables_in_provider_block/main.tf
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
variable "input" {
|
||||
type = string
|
||||
default = "bar"
|
||||
}
|
||||
|
||||
resource "test_resource" "foo" {
|
||||
value = var.input
|
||||
}
|
13
internal/command/testdata/test/local_variables_in_provider_block/main.tftest.hcl
vendored
Normal file
13
internal/command/testdata/test/local_variables_in_provider_block/main.tftest.hcl
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
variables {
|
||||
username = "u"
|
||||
password = "p"
|
||||
}
|
||||
|
||||
provider "test" {
|
||||
username = var.username
|
||||
password = var.password
|
||||
}
|
||||
|
||||
run "validate" {}
|
||||
|
||||
|
@ -28,6 +28,8 @@ var (
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"data_prefix": {Type: cty.String, Optional: true},
|
||||
"resource_prefix": {Type: cty.String, Optional: true},
|
||||
"username": {Type: cty.String, Optional: true},
|
||||
"password": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1098,10 +1098,11 @@ func (c *Config) getTransformAddVariablesForTest(evalCtx *hcl.EvalContext) confi
|
||||
newVars := make(map[string]*Variable, len(c.Module.Variables)+len(file.Variables))
|
||||
for k, v := range c.Module.Variables {
|
||||
oldVars[k] = v
|
||||
newVars[k] = v
|
||||
}
|
||||
for variableName, variableExpr := range file.Variables {
|
||||
// Skip if variable already exists in the config.
|
||||
if v, ok := oldVars[variableName]; ok {
|
||||
if v, ok := newVars[variableName]; ok {
|
||||
newVars[variableName] = v
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user