Skip to content

Commit 69a853b

Browse files
committed
Write generated import config to ConfigDirectory
With `step.ImportStateReadOnlyConfig` opt-out flag
1 parent 99d87eb commit 69a853b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

helper/resource/testing_new_import_state.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
116116
TestStepConfigRequest: testStepConfigRequest,
117117
}.Exec())
118118

119-
if testStepConfig == nil {
119+
switch {
120+
case testStepConfig == nil:
120121
logging.HelperResourceTrace(ctx, "Using prior TestStep Config for import")
121122
importConfig := cfgRaw
122123

@@ -133,6 +134,24 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
133134
if testStepConfig == nil {
134135
t.Fatal("Cannot import state with no specified config")
135136
}
137+
138+
case step.ImportStateReadOnlyConfig:
139+
break
140+
141+
case step.ConfigDirectory != nil:
142+
// TODO: extract / DRY
143+
144+
importConfig := ""
145+
if kind.plannable() && kind.resourceIdentity() {
146+
importConfig = appendImportBlockWithIdentity(importConfig, resourceName, priorIdentityValues)
147+
} else if kind.plannable() {
148+
importConfig = appendImportBlock(importConfig, resourceName, importId)
149+
}
150+
testStepConfig = testStepConfig.AppendGeneratedConfig(ctx, importConfig)
151+
152+
case step.ConfigFile != nil:
153+
// TODO: ship it
154+
136155
}
137156

138157
var workingDir *plugintest.WorkingDir

0 commit comments

Comments
 (0)