Esempio n. 1
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
}
Esempio n. 2
0
// PreApply is called before a single resource is applied, it adds the new
// state to the ApplyResponse and sends it to the calling gRPC client
func (h *ApplyHook) PreApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	d *terraform.InstanceDiff) (terraform.HookAction, error) {
	h.Lock()
	defer h.Unlock()

	h.resp.States[n.HumanId()] = pb.ResourceState_StateRunning

	// Write the new state over the connected gRPC stream
	if err := h.stream.Send(h.resp); err != nil {
		return terraform.HookActionHalt, err
	}

	return terraform.HookActionContinue, nil
}
Esempio n. 3
0
// PostApply is called after a single resource is applied, it adds the new
// state to the ApplyResponse and sends it to the calling gRPC client
func (h *ApplyHook) PostApply(
	n *terraform.InstanceInfo,
	s *terraform.InstanceState,
	err error) (terraform.HookAction, error) {
	h.Lock()
	defer h.Unlock()

	if err != nil {
		h.resp.States[n.HumanId()] = pb.ResourceState_StateError
	} else {
		h.resp.States[n.HumanId()] = pb.ResourceState_StateSuccess
	}

	// Write the new state over the connected gRPC stream
	if err := h.stream.Send(h.resp); err != nil {
		return terraform.HookActionHalt, err
	}

	return terraform.HookActionContinue, nil
}
Esempio n. 4
0
// PostDiff is triggered after each individual resource is diffed, and adds
// the required action for each resource to the PlanResponse
func (h *PlanHook) PostDiff(
	n *terraform.InstanceInfo,
	d *terraform.InstanceDiff) (terraform.HookAction, error) {
	h.Lock()
	defer h.Unlock()

	switch d.ChangeType() {
	case terraform.DiffCreate:
		h.resp.Actions[n.HumanId()] = pb.ResourceAction_ActionCreate
	case terraform.DiffUpdate:
		h.resp.Actions[n.HumanId()] = pb.ResourceAction_ActionUpdate
	case terraform.DiffDestroy:
		h.resp.Actions[n.HumanId()] = pb.ResourceAction_ActionDestroy
	case terraform.DiffDestroyCreate:
		h.resp.Actions[n.HumanId()] = pb.ResourceAction_ActionRecreate
	default:
		h.resp.Actions[n.HumanId()] = pb.ResourceAction_ActionNone
	}

	return terraform.HookActionContinue, nil
}
Esempio n. 5
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
}