command: UI for import

This commit is contained in:
Mitchell Hashimoto 2016-05-04 12:05:42 -07:00
parent 126eb23864
commit f6a59734ef
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 36 additions and 0 deletions

View File

@ -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")

View File

@ -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
}