importResources method
Future<AutomationImportResult>
importResources({
- String? message,
- List<
AutomationImportResource> ? resources, - Map<
String, String> ? nameTable, - bool? protect,
- bool generateCode = true,
- String? converter,
- List<
String> ? converterArgs, - bool check = true,
- bool includeSummary = true,
- bool showSummarySecrets = false,
- bool captureEvents = false,
- AutomationEngineEventHandler? onEvent,
- List<
String> extraArgs = const <String>[],
Imports resources into this stack and returns a typed operation result.
Implementation
Future<AutomationImportResult> importResources({
String? message,
List<AutomationImportResource>? resources,
Map<String, String>? nameTable,
bool? protect,
bool generateCode = true,
String? converter,
List<String>? converterArgs,
bool check = true,
bool includeSummary = true,
bool showSummarySecrets = false,
bool captureEvents = false,
AutomationEngineEventHandler? onEvent,
List<String> extraArgs = const <String>[],
}) async {
final args = <String>['import', '--stack', name, '--yes', '--skip-preview'];
if (message != null && message.trim().isNotEmpty) {
args.addAll(<String>['--message', message]);
}
args.addAll(extraArgs);
Directory? tempDir;
String generatedCode = '';
try {
tempDir = await Directory.systemTemp.createTemp('pulumi-import-');
final generatedCodePath = p.join(tempDir.path, 'generated_code.txt');
if (resources != null) {
final importFilePath = p.join(tempDir.path, 'import.json');
final payload = <String, dynamic>{
'resources': resources
.map((resource) => resource.toJson())
.toList(growable: false),
};
if (nameTable != null) {
payload['nameTable'] = nameTable;
}
await File(importFilePath).writeAsString(jsonEncode(payload));
args.addAll(<String>['--file', importFilePath]);
}
if (protect != null) {
args.add('--protect=${protect ? 'true' : 'false'}');
}
if (generateCode) {
args.add('--out=$generatedCodePath');
} else {
args.add('--generate-code=false');
}
if (converter != null && converter.trim().isNotEmpty) {
args.addAll(<String>['--from', converter]);
if (converterArgs != null && converterArgs.isNotEmpty) {
args.add('--');
args.addAll(converterArgs);
}
}
final (result, events) = await _runStackCommand(
args,
check: check,
captureEvents: captureEvents,
onEvent: onEvent,
);
if (generateCode && result.succeeded) {
final generatedCodeFile = File(generatedCodePath);
if (await generatedCodeFile.exists()) {
generatedCode = await generatedCodeFile.readAsString();
}
}
AutomationUpdateSummary? summary;
if (includeSummary && result.succeeded) {
final effectiveShowSummarySecrets = workspace.remote
? false
: showSummarySecrets;
summary = workspace.remote
? await _awaitTerminalRemoteSummary(
showSecrets: effectiveShowSummarySecrets,
)
: await infoSummary(showSecrets: effectiveShowSummarySecrets);
}
return AutomationImportResult(
commandResult: result,
events: events,
generatedCode: generatedCode,
summary: summary,
);
} finally {
if (tempDir != null && await tempDir.exists()) {
await tempDir.delete(recursive: true);
}
}
}