Skip to content

Commit

Permalink
fix(1519) - improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dboitnot committed Oct 3, 2024
1 parent 12eb4d6 commit 03ac717
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions sceptre/diffing/stack_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,19 @@ 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."
)

# 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
21 changes: 18 additions & 3 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 Expand Up @@ -443,9 +458,9 @@ def test_diff__generated_template_has_no_echo_parameter__masks_value(self):
self.local_no_echo_parameters.append("hide_me")

expected_generated_config = self.expected_generated_config
expected_generated_config.parameters["hide_me"] = (
StackDiffer.NO_ECHO_REPLACEMENT
)
expected_generated_config.parameters[
"hide_me"
] = StackDiffer.NO_ECHO_REPLACEMENT

self.differ.diff(self.actions)

Expand Down

0 comments on commit 03ac717

Please sign in to comment.