From f6a59734ef818c42704e49c38fb3c6f0279e2d1c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 May 2016 12:05:42 -0700 Subject: [PATCH] command: UI for import --- command/hook_ui.go | 28 ++++++++++++++++++++++++++++ command/import.go | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/command/hook_ui.go b/command/hook_ui.go index 206dffe40..3a5357750 100644 --- a/command/hook_ui.go +++ b/command/hook_ui.go @@ -251,6 +251,34 @@ func (h *UiHook) PreRefresh( return terraform.HookActionContinue, nil } +func (h *UiHook) PreImportState( + n *terraform.InstanceInfo) (terraform.HookAction, error) { + h.once.Do(h.init) + + id := n.HumanId() + h.ui.Output(h.Colorize.Color(fmt.Sprintf( + "[reset][bold]%s: Importing from ID %q...", + id, n.Id))) + return terraform.HookActionContinue, nil +} + +func (h *UiHook) PostImportState( + n *terraform.InstanceInfo, + s []*terraform.InstanceState) (terraform.HookAction, error) { + h.once.Do(h.init) + + id := n.HumanId() + h.ui.Output(h.Colorize.Color(fmt.Sprintf( + "[reset][bold][green]%s: Import complete!", id))) + for _, s := range s { + h.ui.Output(h.Colorize.Color(fmt.Sprintf( + "[reset][green] Imported %s (ID: %s)", + s.Ephemeral.Type, s.ID))) + } + + return terraform.HookActionContinue, nil +} + func (h *UiHook) init() { if h.Colorize == nil { panic("colorize not given") diff --git a/command/import.go b/command/import.go index 4954e7efa..015610da5 100644 --- a/command/import.go +++ b/command/import.go @@ -67,6 +67,14 @@ func (c *ImportCommand) Run(args []string) int { return 1 } + c.Ui.Output(c.Colorize().Color(fmt.Sprintf( + "[reset][green]\n" + + "Import success! The resources imported are shown above. These are\n" + + "now in your Terraform state. Import does not currently generate\n" + + "configuration, so you must do this next. If you do not create configuration\n" + + "for the above resources, then the next `terraform plan` will mark\n" + + "them for destruction."))) + return 0 }