コード例 #1
0
ファイル: hook_ui.go プロジェクト: Yelp/terraform
func (h *UiHook) PostApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	applyerr error) (terraform.HookAction, error) {
	id := n.HumanId()

	h.l.Lock()
	state := h.resources[id]
	delete(h.resources, id)
	h.l.Unlock()

	var msg string
	switch state.Op {
	case uiResourceModify:
		msg = "Modifications complete"
	case uiResourceDestroy:
		msg = "Destruction complete"
	case uiResourceCreate:
		msg = "Creation complete"
	case uiResourceUnknown:
		return terraform.HookActionContinue, nil
	}

	if applyerr != nil {
		// Errors are collected and printed in ApplyCommand, no need to duplicate
		return terraform.HookActionContinue, nil
	}

	h.ui.Output(h.Colorize.Color(fmt.Sprintf(
		"[reset][bold]%s: %s[reset_bold]",
		id, msg)))

	return terraform.HookActionContinue, nil
}
コード例 #2
0
func (h *CountHook) PostApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	e error) (terraform.HookAction, error) {
	h.Lock()
	defer h.Unlock()

	if h.pending != nil {
		if a, ok := h.pending[n.HumanId()]; ok {
			delete(h.pending, n.HumanId())

			if e == nil {
				switch a {
				case countHookActionAdd:
					h.Added += 1
				case countHookActionChange:
					h.Changed += 1
				case countHookActionRemove:
					h.Removed += 1
				}
			}
		}
	}

	return terraform.HookActionContinue, nil
}
コード例 #3
0
ファイル: ui_hook.go プロジェクト: apparentlymart/padstone
func (h *UIHook) PreApply(instance *terraform.InstanceInfo, istate *terraform.InstanceState, diff *terraform.InstanceDiff) (terraform.HookAction, error) {
	if diff.Destroy || diff.DestroyTainted {
		h.ui.Info(fmt.Sprintf("[%v] Destroying ...", instance.HumanId()))
	} else {
		h.ui.Info(fmt.Sprintf("[%v] Creating...", instance.HumanId()))
	}
	return terraform.HookActionContinue, nil
}
コード例 #4
0
ファイル: hook_ui.go プロジェクト: Yelp/terraform
func (h *UiHook) PreProvision(
	n *terraform.InstanceInfo,
	provId string) (terraform.HookAction, error) {
	id := n.HumanId()
	h.ui.Output(h.Colorize.Color(fmt.Sprintf(
		"[reset][bold]%s: Provisioning with '%s'...[reset_bold]",
		id, provId)))
	return terraform.HookActionContinue, nil
}
コード例 #5
0
ファイル: hook_ui.go プロジェクト: ack/terraform
func (h *UiHook) PreImportState(
	n *terraform.InstanceInfo,
	id string) (terraform.HookAction, error) {
	h.once.Do(h.init)

	h.ui.Output(h.Colorize.Color(fmt.Sprintf(
		"[reset][bold]%s: Importing from ID %q...",
		n.HumanId(), id)))
	return terraform.HookActionContinue, nil
}
コード例 #6
0
ファイル: hook_ui.go プロジェクト: Yelp/terraform
func (h *UiHook) PreRefresh(
	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]%s: Refreshing state... (ID: %s)",
		id, s.ID)))
	return terraform.HookActionContinue, nil
}
コード例 #7
0
ファイル: hook_ui.go プロジェクト: ack/terraform
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
}
コード例 #8
0
ファイル: hook_ui.go プロジェクト: ack/terraform
func (h *UiHook) PreRefresh(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState) (terraform.HookAction, error) {
	h.once.Do(h.init)

	id := n.HumanId()

	var stateIdSuffix string
	// Data resources refresh before they have ids, whereas managed
	// resources are only refreshed when they have ids.
	if s.ID != "" {
		stateIdSuffix = fmt.Sprintf(" (ID: %s)", s.ID)
	}

	h.ui.Output(h.Colorize.Color(fmt.Sprintf(
		"[reset][bold]%s: Refreshing state...%s",
		id, stateIdSuffix)))
	return terraform.HookActionContinue, nil
}
コード例 #9
0
ファイル: hook_ui.go プロジェクト: Yelp/terraform
func (h *UiHook) ProvisionOutput(
	n *terraform.InstanceInfo,
	provId string,
	msg string) {
	id := n.HumanId()
	var buf bytes.Buffer
	buf.WriteString(h.Colorize.Color("[reset]"))

	prefix := fmt.Sprintf("%s (%s): ", id, provId)
	s := bufio.NewScanner(strings.NewReader(msg))
	s.Split(scanLines)
	for s.Scan() {
		line := strings.TrimRightFunc(s.Text(), unicode.IsSpace)
		if line != "" {
			buf.WriteString(fmt.Sprintf("%s%s\n", prefix, line))
		}
	}

	h.ui.Output(strings.TrimSpace(buf.String()))
}
コード例 #10
0
func (h *CountHook) PreApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	d *terraform.InstanceDiff) (terraform.HookAction, error) {
	h.Lock()
	defer h.Unlock()

	if h.pending == nil {
		h.pending = make(map[string]countHookAction)
	}

	action := countHookActionChange
	if d.Destroy {
		action = countHookActionRemove
	} else if s.ID == "" {
		action = countHookActionAdd
	}

	h.pending[n.HumanId()] = action

	return terraform.HookActionContinue, nil
}
コード例 #11
0
ファイル: ui_hook.go プロジェクト: apparentlymart/padstone
func (h *UIHook) PostApply(instance *terraform.InstanceInfo, istate *terraform.InstanceState, err error) (terraform.HookAction, error) {
	if err != nil {
		h.ui.Error(fmt.Sprintf("[%v] Error during apply: %v", instance.HumanId(), err.Error()))
	} else {
		if h.verbose {
			if istate.ID != "" {
				h.ui.Info(fmt.Sprintf("[%v] Successfully created as %v", instance.HumanId(), istate.ID))
			} else {
				h.ui.Info(fmt.Sprintf("[%v] Successfully destroyed", instance.HumanId()))
			}
		}
	}
	return terraform.HookActionContinue, nil
}
コード例 #12
0
ファイル: hook_ui.go プロジェクト: Yelp/terraform
func (h *UiHook) PreApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	d *terraform.InstanceDiff) (terraform.HookAction, error) {
	h.once.Do(h.init)

	id := n.HumanId()

	op := uiResourceModify
	if d.Destroy {
		op = uiResourceDestroy
	} else if s.ID == "" {
		op = uiResourceCreate
	}

	h.l.Lock()
	h.resources[id] = uiResourceState{
		Op:    op,
		Start: time.Now().Round(time.Second),
	}
	h.l.Unlock()

	var operation string
	switch op {
	case uiResourceModify:
		operation = "Modifying..."
	case uiResourceDestroy:
		operation = "Destroying..."
	case uiResourceCreate:
		operation = "Creating..."
	case uiResourceUnknown:
		return terraform.HookActionContinue, nil
	}

	attrBuf := new(bytes.Buffer)

	// Get all the attributes that are changing, and sort them. Also
	// determine the longest key so that we can align them all.
	keyLen := 0
	keys := make([]string, 0, len(d.Attributes))
	for key, _ := range d.Attributes {
		// Skip the ID since we do that specially
		if key == "id" {
			continue
		}

		keys = append(keys, key)
		if len(key) > keyLen {
			keyLen = len(key)
		}
	}
	sort.Strings(keys)

	// Go through and output each attribute
	for _, attrK := range keys {
		attrDiff := d.Attributes[attrK]

		v := attrDiff.New
		if attrDiff.NewComputed {
			v = "<computed>"
		}

		attrBuf.WriteString(fmt.Sprintf(
			"  %s:%s %#v => %#v\n",
			attrK,
			strings.Repeat(" ", keyLen-len(attrK)),
			attrDiff.Old,
			v))
	}

	attrString := strings.TrimSpace(attrBuf.String())
	if attrString != "" {
		attrString = "\n  " + attrString
	}

	h.ui.Output(h.Colorize.Color(fmt.Sprintf(
		"[reset][bold]%s: %s[reset_bold]%s",
		id,
		operation,
		attrString)))

	// Set a timer to show an operation is still happening
	time.AfterFunc(periodicUiTimer, func() { h.stillApplying(id) })

	return terraform.HookActionContinue, nil
}
コード例 #13
0
ファイル: ui_hook.go プロジェクト: apparentlymart/padstone
func (h *UIHook) ProvisionOutput(instance *terraform.InstanceInfo, name string, line string) {
	h.ui.Info(fmt.Sprintf("[%v %v] %v", instance.HumanId(), name, line))
}
コード例 #14
0
ファイル: ui_hook.go プロジェクト: apparentlymart/padstone
func (h *UIHook) PostProvisionResource(instance *terraform.InstanceInfo, istate *terraform.InstanceState) (terraform.HookAction, error) {
	if h.verbose {
		h.ui.Info(fmt.Sprintf("[%v] Successfully provisioned", instance.HumanId()))
	}
	return terraform.HookActionContinue, nil
}
コード例 #15
0
ファイル: ui_hook.go プロジェクト: apparentlymart/padstone
func (h *UIHook) PreProvisionResource(instance *terraform.InstanceInfo, istate *terraform.InstanceState) (terraform.HookAction, error) {
	h.ui.Info(fmt.Sprintf("[%v] Provisioning...", instance.HumanId()))
	return terraform.HookActionContinue, nil
}