Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolve #1519] Improve error message #1522

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sceptre/diffing/stack_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,20 @@ def _create_deployed_stack_config(
try:
description = stack_actions.describe()
except ClientError as err:
# Check for AWS access exceptions
if err.response["Error"]["Code"] == "ForbiddenException":
raise SceptreException(
"ForbiddenException: Confirm your current AWS profile is authenticated",
"and has the necessary access.",
)

# This means the stack has not been deployed yet
if err.response["Error"]["Message"].endswith("does not exist"):
return None

# Unknown error, raise it as-is
raise err

stacks = description["Stacks"]
for stack in stacks:
if stack["StackStatus"] in self.STACK_STATUSES_INDICATING_NOT_DEPLOYED:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_diffing/test_stack_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def setup_method(self, method):
self._stack = None
self._actions = None
self._parameters = None
self._describe_fn = self.describe_stack_success

@property
def parameters_on_stack(self):
Expand Down Expand Up @@ -103,6 +104,9 @@ def actions(self) -> Union[StackActions, Mock]:
return self._actions

def describe_stack(self):
return self._describe_fn()

def describe_stack_success(self):
return {
"Stacks": [
{
Expand Down Expand Up @@ -177,6 +181,17 @@ def expected_deployed_config(self):
cloudformation_service_role=self.deployed_cloudformation_service_role,
)

def test__create_deployed_stack_config__wraps_aws_ForbiddenException(self):
def fail_with_ForbiddenException():
raise ClientError(
{"Error": {"Code": "ForbiddenException", "Message": "No access"}},
"describe",
)

self._describe_fn = fail_with_ForbiddenException
with pytest.raises(SceptreException):
self.differ._create_deployed_stack_config(self.actions)

def test_diff__compares_deployed_template_to_generated_template(self):
self.differ.diff(self.actions)

Expand Down