Merge pull request #33238 from hashicorp/radditude/import-plan-plumbing

plannable import: correct plumbing when using a plan output file
This commit is contained in:
CJ Horton 2023-05-23 10:36:19 -07:00 committed by GitHub
commit 258bdbe89f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -427,6 +427,13 @@ func changeFromTfplan(rawChange *planproto.Change) (*plans.ChangeSrc, error) {
}
}
if rawChange.Importing != nil {
ret.Importing = &plans.ImportingSrc{
ID: rawChange.Importing.Id,
}
}
ret.GeneratedConfig = rawChange.GeneratedConfig
sensitive := cty.NewValueMarks(marks.Sensitive)
beforeValMarks, err := pathValueMarksFromTfplan(rawChange.BeforeSensitivePaths, sensitive)
if err != nil {
@ -759,6 +766,14 @@ func changeToTfplan(change *plans.ChangeSrc) (*planproto.Change, error) {
ret.BeforeSensitivePaths = beforeSensitivePaths
ret.AfterSensitivePaths = afterSensitivePaths
if change.Importing != nil {
ret.Importing = &planproto.Importing{
Id: change.Importing.ID,
}
}
ret.GeneratedConfig = change.GeneratedConfig
switch change.Action {
case plans.NoOp:
ret.Action = planproto.Action_NOOP

View File

@ -122,6 +122,33 @@ func TestTFPlanRoundTrip(t *testing.T) {
}), objTy),
},
},
{
Addr: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_thing",
Name: "importing",
}.Instance(addrs.IntKey(1)).Absolute(addrs.RootModuleInstance),
PrevRunAddr: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_thing",
Name: "importing",
}.Instance(addrs.IntKey(1)).Absolute(addrs.RootModuleInstance),
ProviderAddr: addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"),
Module: addrs.RootModule,
},
ChangeSrc: plans.ChangeSrc{
Action: plans.NoOp,
Before: mustNewDynamicValue(cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("testing"),
}), objTy),
After: mustNewDynamicValue(cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("testing"),
}), objTy),
Importing: &plans.ImportingSrc{ID: "testing"},
GeneratedConfig: "resource \\\"test_thing\\\" \\\"importing\\\" {}",
},
},
},
},
DriftedResources: []*plans.ResourceInstanceChangeSrc{