Merge pull request #26490 from hashicorp/jbardin/import-module-variables
do not evaluate module variables during import
This commit is contained in:
commit
3d884d7e3f
|
@ -732,6 +732,95 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextImport_noConfigModuleImport(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
locals {
|
||||
xs = toset(["foo"])
|
||||
}
|
||||
|
||||
module "a" {
|
||||
for_each = local.xs
|
||||
source = "./a"
|
||||
}
|
||||
|
||||
module "b" {
|
||||
for_each = local.xs
|
||||
source = "./b"
|
||||
y = module.a[each.key].y
|
||||
}
|
||||
`,
|
||||
"a/main.tf": `
|
||||
output "y" {
|
||||
value = "bar"
|
||||
}
|
||||
`,
|
||||
"b/main.tf": `
|
||||
variable "y" {
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "test_resource" "unused" {
|
||||
value = var.y
|
||||
}
|
||||
`,
|
||||
})
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_resource": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "test_resource",
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("test"),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
state, diags := ctx.Import(&ImportOpts{
|
||||
Targets: []*ImportTarget{
|
||||
&ImportTarget{
|
||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||
addrs.ManagedResourceMode, "test_resource", "test", addrs.NoKey,
|
||||
),
|
||||
ID: "test",
|
||||
},
|
||||
},
|
||||
})
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.ErrWithWarnings())
|
||||
}
|
||||
|
||||
ri := state.ResourceInstance(mustResourceInstanceAddr("test_resource.test"))
|
||||
expected := `{"id":"test"}`
|
||||
if string(ri.Current.AttrsJSON) != expected {
|
||||
t.Fatalf("expected %q, got %q\n", expected, ri.Current.AttrsJSON)
|
||||
}
|
||||
}
|
||||
|
||||
const testImportStr = `
|
||||
aws_instance.foo:
|
||||
ID = foo
|
||||
|
|
|
@ -153,7 +153,7 @@ func (n *nodeModuleVariable) Execute(ctx EvalContext, op walkOperation) error {
|
|||
var err error
|
||||
|
||||
switch op {
|
||||
case walkPlan, walkApply, walkDestroy, walkImport:
|
||||
case walkPlan, walkApply, walkDestroy:
|
||||
vals, err = n.EvalModuleCallArgument(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue