8000 improve logic around failing resource action a bit · localstack/localstack@c2243b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2243b0

Browse files
improve logic around failing resource action a bit
1 parent 9ea1814 commit c2243b0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

localstack/services/cloudformation/engine/template_deployer.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from localstack.services.cloudformation.resource_provider import (
2424
Credentials,
25+
OperationStatus,
2526
ResourceProviderExecutor,
2627
ResourceProviderPayload,
2728
get_resource_type,
@@ -1358,13 +1359,31 @@ def apply_change(self, change: ChangeConfig, stack: Stack) -> None:
13581359

13591360
progress_event = executor.deploy_loop(resource_provider_payload) # noqa
13601361

1362+
# TODO: clean up the surrounding loop (do_apply_changes_in_loop) so that the responsibilities are clearer
1363+
stack_action = get_action_name_for_resource_change(action)
1364+
match progress_event.status:
1365+
case OperationStatus.FAILED:
1366+
stack.set_resource_status(resource_id, f"{stack_action}_FAILED")
1367+
# TODO: remove exception raising here?
1368+
# TODO: fix request token
1369+
raise Exception(
1370+
f'Resource handler returned message: "{progress_event.message}" (RequestToken: 10c10335-276a-33d3-5c07-018b684c3d26, HandlerErrorCode: InvalidRequest){progress_event.error_code}'
1371+
)
1372+
case OperationStatus.SUCCESS:
1373+
stack.set_resource_status(resource_id, f"{stack_action}_COMPLETE")
1374+
case OperationStatus.PENDING:
1375+
# this isn't really a state we use at the moment
1376+
raise Exception(
1377+
f"Usage of currently unsupported operation status detected: {OperationStatus.PENDING}"
1378+
)
1379+
case OperationStatus.IN_PROGRESS:
1380+
raise Exception("Resource deployment loop should not finish in this state")
1381+
case unknown_status:
1382+
raise Exception(f"Unknown operation status: {unknown_status}")
1383+
13611384
# TODO: this is probably already done in executor, try removing this
13621385
resource["Properties"] = progress_event.resource_model
13631386

1364-
# update resource status and physical resource id
1365-
stack_action = get_action_name_for_resource_change(action)
1366-
stack.set_resource_status(resource_id, f"{stack_action}_COMPLETE")
1367-
13681387
def create_resource_provider_executor(self) -> ResourceProviderExecutor:
13691388
return ResourceProviderExecutor(
13701389
stack_name=self.stack.stack_name,

localstack/services/cloudformation/resource_provider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ def deploy_loop(
640640

641641
event = self.execute_action(resource_provider, payload)
642642

643+
if event.status == OperationStatus.FAILED:
644+
return event
645+
643646
if event.status == OperationStatus.SUCCESS:
644647

645648
if not isinstance(resource_provider, LegacyResourceProvider):

0 commit comments

Comments
 (0)
0