def destroy(plugin_id: str, context: "Context", team_context: "TeamContext", parameters: Dict[str, Any]) -> None: _logger.debug("Destroying Custom CloudFormation plugin resources for team %s", team_context.name) _logger.debug("Team Env name: %s | Team name: %s", context.name, team_context.name) env_name = context.name acct: str = context.account_id deploy_id: str = cast(str, context.toolkit.deploy_id) plugin_id = plugin_id.replace("_", "-") stack_name = f"orbit-{context.name}-{team_context.name}-{plugin_id}-custom-demo-resources" _logger.debug(f"stack_name={stack_name}") bucket_names: Dict[str, Any] = { "lake-bucket": f"orbit-{env_name}-demo-lake-{acct}-{deploy_id}", "secured-lake-bucket": f"orbit-{env_name}-secured-demo-lake-{acct}-{deploy_id}", } _logger.debug(f"bucket_names={bucket_names}") # CDK skips bucket deletion. if cfn.does_stack_exist(stack_name=stack_name): try: _logger.debug("Deleting lake-bucket") s3.delete_bucket(bucket=bucket_names["lake-bucket"]) except Exception as ex: _logger.debug("Skipping Team Lake Bucket deletion. Cause: %s", ex) try: _logger.debug("Deleting secured-lake-bucket") s3.delete_bucket(bucket=bucket_names["secured-lake-bucket"]) except Exception as ex: _logger.debug("Skipping Team Secured Lake Bucket deletion. Cause: %s", ex) _logger.debug("Destroying custom resources using post hook") cfn.destroy_stack(stack_name=stack_name) _logger.debug("Destroyed")
def destroy_toolkit(env_name: str, top_level: str = "orbit") -> None: try: s3.delete_bucket_by_prefix(prefix=f"{top_level}-{env_name}-toolkit-{utils.get_account_id()}-") except Exception as ex: _logger.debug("Skipping Toolkit bucket deletion. Cause: %s", ex) toolkit_stack_name: str = f"{top_level}-{env_name}-toolkit" if cfn.does_stack_exist(stack_name=toolkit_stack_name): cfn.destroy_stack(stack_name=toolkit_stack_name) ssm.cleanup_env(env_name=env_name, top_level=top_level)
def destroy_remaining_resources(env_name: str, top_level: str = "orbit") -> None: ecr.cleanup_remaining_repos(env_name=env_name) s3.delete_bucket_by_prefix( prefix=f"{top_level}-{env_name}-cdk-toolkit-{utils.get_account_id()}-") env_cdk_toolkit: str = f"{top_level}-{env_name}-cdk-toolkit" if cfn.does_stack_exist(stack_name=env_cdk_toolkit): cfn.destroy_stack(stack_name=env_cdk_toolkit) destroy_toolkit(env_name=env_name)
def _destroy_toolkit( env_name: str, top_level: str = "orbit", cdk_toolkit_bucket: Optional[str] = None, ) -> None: try: if cdk_toolkit_bucket: s3.delete_bucket(bucket=cdk_toolkit_bucket) except Exception as ex: _logger.debug("Skipping CDK Toolkit bucket deletion. Cause: %s", ex) toolkit_stack_name: str = f"{top_level}-{env_name}-toolkit" if cfn.does_stack_exist(stack_name=toolkit_stack_name): cfn.destroy_stack(stack_name=toolkit_stack_name) ssm.cleanup_env(env_name=env_name, top_level=top_level)
def destroy(context: T) -> None: if not (isinstance(context, Context) or isinstance(context, FoundationContext)): raise ValueError("Unknown 'context' Type") _logger.debug("Destroying %s CDK Toolkit...", context.cdk_toolkit.stack_name) if context.cdk_toolkit.s3_bucket: if cfn.does_stack_exist(stack_name=context.cdk_toolkit.stack_name): try: s3.delete_bucket(bucket=context.cdk_toolkit.s3_bucket) except Exception as ex: _logger.debug("Skipping Toolkit bucket deletion. Cause: %s", ex) cfn.destroy_stack(stack_name=context.cdk_toolkit.stack_name)
def destroy_remaining_resources(env_name: str, top_level: str = "orbit") -> None: env_cdk_toolkit: str = f"{top_level}-{env_name}-cdk-toolkit" if cfn.does_stack_exist(stack_name=env_cdk_toolkit): cfn.destroy_stack(stack_name=env_cdk_toolkit) _destroy_toolkit(env_name=env_name)