Skip to content

Commit

Permalink
Merge pull request #678 from cloudtools/in-progress
Browse files Browse the repository at this point in the history
Add `in_progress` option to stack config.
  • Loading branch information
ejholmes committed Dec 5, 2018
2 parents 37cd351 + 7df4e5c commit fadf97d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ A stack has the following keys:
that will be applied when the CloudFormation stack is created and updated.
You can use stack policies to prevent CloudFormation from making updates to
protected resources (e.g. databases). See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html
**in_progress_behavior**:
(optional): If provided, specifies the behavior for when a stack is in
`CREATE_IN_PROGRESS` or `UPDATE_IN_PROGRESS`. By default, stacker will raise
an exception if the stack is in an `IN_PROGRESS` state. You can set this
option to `wait` and stacker will wait for the previous update to complete
before attempting to update the stack.

Stacks Example
~~~~~~~~~~~~~~
Expand Down
7 changes: 6 additions & 1 deletion stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
CompleteStatus,
FailedStatus,
SkippedStatus,
PENDING,
WAITING,
SUBMITTED,
INTERRUPTED
)
Expand Down Expand Up @@ -256,7 +258,7 @@ def _launch_stack(self, stack, **kwargs):
"""
old_status = kwargs.get("status")
wait_time = STACK_POLL_TIME if old_status == SUBMITTED else 0
wait_time = 0 if old_status is PENDING else STACK_POLL_TIME
if self.cancel.wait(wait_time):
return INTERRUPTED

Expand Down Expand Up @@ -340,6 +342,9 @@ def _launch_stack(self, stack, **kwargs):
return SubmittedStatus("creating new stack")

try:
wait = stack.in_progress_behavior == "wait"
if wait and provider.is_stack_in_progress(provider_stack):
return WAITING
if provider.prepare_stack_for_update(provider_stack, tags):
existing_params = provider_stack.get('Parameters', [])
provider.update_stack(
Expand Down
3 changes: 2 additions & 1 deletion stacker/actions/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..status import (
CompleteStatus,
SubmittedStatus,
PENDING,
SUBMITTED,
INTERRUPTED
)
Expand Down Expand Up @@ -45,7 +46,7 @@ def _generate_plan(self, tail=False):

def _destroy_stack(self, stack, **kwargs):
old_status = kwargs.get("status")
wait_time = STACK_POLL_TIME if old_status == SUBMITTED else 0
wait_time = 0 if old_status is PENDING else STACK_POLL_TIME
if self.cancel.wait(wait_time):
return INTERRUPTED

Expand Down
2 changes: 2 additions & 0 deletions stacker/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ class Stack(Model):

stack_policy_path = StringType(serialize_when_none=False)

in_progress_behavior = StringType(serialize_when_none=False)

def validate_class_path(self, data, value):
if value and data["template_path"]:
raise ValidationError(
Expand Down
1 change: 1 addition & 0 deletions stacker/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, definition, context, variables=None, mappings=None,
self.protected = protected
self.context = context
self.outputs = None
self.in_progress_behavior = definition.in_progress_behavior

def __repr__(self):
return self.fqn
Expand Down
1 change: 1 addition & 0 deletions stacker/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class StackDoesNotExist(SkippedStatus):


PENDING = PendingStatus()
WAITING = PendingStatus(reason="waiting")
SUBMITTED = SubmittedStatus()
COMPLETE = CompleteStatus()
SKIPPED = SkippedStatus()
Expand Down

0 comments on commit fadf97d

Please sign in to comment.