From f06c9e421f4bae152a3bd3e21844bcdfc1d27bec Mon Sep 17 00:00:00 2001 From: dlpzx Date: Wed, 3 Jul 2024 13:13:04 +0200 Subject: [PATCH] Add check in delete environment for create_failed stacks --- .../services/environment_service.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/dataall/core/environment/services/environment_service.py b/backend/dataall/core/environment/services/environment_service.py index 615f83cbe..d8a1f5f94 100644 --- a/backend/dataall/core/environment/services/environment_service.py +++ b/backend/dataall/core/environment/services/environment_service.py @@ -868,13 +868,19 @@ def delete_environment(uri): f'related objects before proceeding', ) else: - PolicyManager( - role_name=environment.EnvironmentDefaultIAMRoleName, - environmentUri=environment.environmentUri, - account=environment.AwsAccountId, - region=environment.region, - resource_prefix=environment.resourcePrefix, - ).delete_all_policies() + if StackRepository.find_stack_by_target_uri(session, environment.environmentUri) not in [ + StackStatus.ROLLBACK_COMPLETE.value, + StackStatus.ROLLBACK_IN_PROGRESS.value, + StackStatus.CREATE_FAILED.value, + StackStatus.DELETE_COMPLETE.value, + ]: + PolicyManager( + role_name=environment.EnvironmentDefaultIAMRoleName, + environmentUri=environment.environmentUri, + account=environment.AwsAccountId, + region=environment.region, + resource_prefix=environment.resourcePrefix, + ).delete_all_policies() KeyValueTagRepository.delete_key_value_tags(session, environment.environmentUri, 'environment') EnvironmentResourceManager.delete_env(session, environment)