-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from hashicorp/f-cancel
Ctrl-C
- Loading branch information
Showing
10 changed files
with
428 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resource "test_instance" "foo" { | ||
ami = "bar" | ||
} | ||
|
||
resource "test_instance" "bar" { | ||
ami = "${test_instance.foo.ami}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package terraform | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// stopHook is a private Hook implementation that Terraform uses to | ||
// signal when to stop or cancel actions. | ||
type stopHook struct { | ||
sync.Mutex | ||
|
||
// This should be incremented for every thing that can be stopped. | ||
// When this is zero, a stopper can assume that everything is properly | ||
// stopped. | ||
count int | ||
|
||
// This channel should be closed when it is time to stop | ||
ch chan struct{} | ||
|
||
serial int | ||
stoppedCh chan<- struct{} | ||
} | ||
|
||
func (h *stopHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) PostApply(string, *ResourceState) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) PreDiff(string, *ResourceState) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) PostDiff(string, *ResourceDiff) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) PreRefresh(string, *ResourceState) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) PostRefresh(string, *ResourceState) (HookAction, error) { | ||
return h.hook() | ||
} | ||
|
||
func (h *stopHook) hook() (HookAction, error) { | ||
select { | ||
case <-h.ch: | ||
h.stoppedCh <- struct{}{} | ||
return HookActionHalt, nil | ||
default: | ||
return HookActionContinue, nil | ||
} | ||
} | ||
|
||
// reset should be called within the lock context | ||
func (h *stopHook) reset() { | ||
h.ch = make(chan struct{}) | ||
h.count = 0 | ||
h.serial += 1 | ||
h.stoppedCh = nil | ||
} | ||
|
||
func (h *stopHook) ref() int { | ||
h.Lock() | ||
defer h.Unlock() | ||
h.count++ | ||
return h.serial | ||
} | ||
|
||
func (h *stopHook) unref(s int) { | ||
h.Lock() | ||
defer h.Unlock() | ||
if h.serial == s { | ||
h.count-- | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package terraform | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestStopHook_impl(t *testing.T) { | ||
var _ Hook = new(stopHook) | ||
} |
Oops, something went wrong.