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

Enable to set DeletionPolicy #688

Merged
merged 1 commit into from
Sep 12, 2023
Merged
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
2 changes: 2 additions & 0 deletions ecs_composex/acm/acm_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def __init__(
stack_template = build_template("ACM Certificates created from x-acm")
super().__init__(name, stack_template, module=module, **kwargs)
define_acm_certs(module.new_resources, self)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/alarms/alarms_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def __init__(
)
super().__init__(name, stack_template=template, **kwargs)
create_alarms(template, self, module.new_resources, settings)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/aps/aps_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def __init__(
)
super().__init__(title, stack_template, **kwargs)
set_new_aps(module.new_resources, stack_template, self)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/codeguru_profiler/codeguru_profiler_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def __init__(
if module.new_resources:
stack_template = create_root_template(module.new_resources, module.res_key)
super().__init__(title, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True

Expand Down
1 change: 1 addition & 0 deletions ecs_composex/common/stacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
:param kwargs: kwargs from composex along with the kwargs for the stack
"""
self.name = name
self._deletion_policy: str = "Delete"
self.parent_stack = None
if module_name is None:
self.module_name = path.basename(path.dirname(path.abspath(__file__)))
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/efs/efs_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def __init__(
if module.new_resources:
stack_template = create_efs_stack(settings, module.new_resources)
super().__init__(name, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources:
Expand Down
7 changes: 2 additions & 5 deletions ecs_composex/elasticache/elasticache_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
from troposphere.ssm import Parameter as SSMParameter

from ecs_composex.common.stacks import ComposeXStack
from ecs_composex.compose.x_resources.helpers import (
set_lookup_resources,
set_new_resources,
set_resources,
)
from ecs_composex.compose.x_resources.network_x_resources import NetworkXResource
from ecs_composex.elasticache.elasticache_ecs import create_lookup_mappings
from ecs_composex.elasticache.elasticache_params import (
Expand Down Expand Up @@ -242,6 +237,8 @@ def __init__(
if module.new_resources:
stack_template = create_root_template(module.new_resources)
super().__init__(title, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True

Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/elbv2/elbv2_stack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ def __init__(
resource.sort_alb_ingress(settings, stack_template)

super().__init__(title, stack_template, stack_parameters=lb_input, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
for resource in module.resources_list:
resource.stack = self
3 changes: 3 additions & 0 deletions ecs_composex/events/events_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def __init__(
)
super().__init__(title, stack_template, **kwargs)
create_events_template(self, settings, module.new_resources)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)

else:
self.is_void = True

Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/kinesis/kinesis_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def __init__(
if module.new_resources:
stack_template = create_streams_template(module.new_resources, settings)
super().__init__(title, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
for resource in module.resources_list:
Expand Down
7 changes: 2 additions & 5 deletions ecs_composex/kinesis_firehose/kinesis_firehose_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
from ecs_composex.compose.x_resources.environment_x_resources import (
AwsEnvironmentResource,
)
from ecs_composex.compose.x_resources.helpers import (
set_lookup_resources,
set_new_resources,
set_resources,
)
from ecs_composex.iam.iam_stack import ResourceIamManager
from ecs_composex.kinesis_firehose.kinesis_firehose_params import (
FIREHOSE_ARN,
Expand Down Expand Up @@ -187,6 +182,8 @@ def __init__(
if module.new_resources:
stack_template = create_streams_template(module.new_resources)
super().__init__(title, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
for resource in module.resources_list:
Expand Down
7 changes: 2 additions & 5 deletions ecs_composex/kms/kms_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
from ecs_composex.compose.x_resources.environment_x_resources import (
AwsEnvironmentResource,
)
from ecs_composex.compose.x_resources.helpers import (
set_lookup_resources,
set_new_resources,
set_resources,
)
from ecs_composex.kinesis_firehose.kinesis_firehose_stack import DeliveryStream
from ecs_composex.kms import metadata
from ecs_composex.kms.kms_ecs_cluster import handle_ecs_cluster
Expand Down Expand Up @@ -239,6 +234,8 @@ def __init__(
stack_template = build_template("Root template for KMS")
super().__init__(title, stack_template, **kwargs)
create_kms_template(stack_template, module.new_resources, self)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources:
Expand Down
7 changes: 6 additions & 1 deletion ecs_composex/mods_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
NetworkXResource,
DatabaseXResource,
)

import re
from collections import OrderedDict
from copy import deepcopy
from importlib import import_module
from json import loads

from compose_x_common.compose_x_common import keyisset
from compose_x_common.compose_x_common import keyisset, set_else_none

from ecs_composex.common import NONALPHANUM
from ecs_composex.common.ecs_composex import X_KEY
Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(
if definition:
self.definition = definition
self._original_definition = deepcopy(definition)
self.module_deletion_policy: str = "Delete"

def __del__(self):
if hasattr(self, "_resources") and self._resources:
Expand Down Expand Up @@ -255,6 +257,9 @@ def set_resources(self, settings: ComposeXSettings):
key=lambda item: item[0],
)
)
if keyisset("DeletionPolicy", _resources):
self.module_deletion_policy = _resources["DeletionPolicy"]
del _resources["DeletionPolicy"]
if not self._original_definition:
self._original_definition = {self.res_key: dict(_resources)}
for resource_name, resource_definition in _resources.items():
Expand Down
8 changes: 2 additions & 6 deletions ecs_composex/neptune/neptune_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
from ecs_composex.common.logging import LOG
from ecs_composex.common.stacks import ComposeXStack
from ecs_composex.common.troposphere_tools import build_template
from ecs_composex.compose.x_resources.helpers import (
set_lookup_resources,
set_new_resources,
set_resources,
)
from ecs_composex.compose.x_resources.network_x_resources import DatabaseXResource
from ecs_composex.neptune.neptune_params import (
DB_CLUSTER_RESOURCES_ARN,
Expand All @@ -33,7 +28,6 @@
DB_READ_ENDPOINT,
DB_RESOURCE_ID,
)
from ecs_composex.neptune.neptune_template import create_neptune_template
from ecs_composex.rds.rds_params import DB_CLUSTER_ARN, DB_CLUSTER_NAME, DB_SG
from ecs_composex.rds_resources_settings import (
handle_new_tcp_resource,
Expand Down Expand Up @@ -260,6 +254,8 @@ def __init__(
create_neptune_template(
stack_template, module.new_resources, settings, self
)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True

Expand Down
7 changes: 2 additions & 5 deletions ecs_composex/opensearch/opensearch_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

from ecs_composex.common.stacks import ComposeXStack
from ecs_composex.common.troposphere_tools import build_template
from ecs_composex.compose.x_resources.helpers import (
set_lookup_resources,
set_new_resources,
set_resources,
)
from ecs_composex.compose.x_resources.network_x_resources import DatabaseXResource
from ecs_composex.opensearch.opensearch_aws import create_opensearch_mappings
from ecs_composex.opensearch.opensearch_params import (
Expand Down Expand Up @@ -178,6 +173,8 @@ def __init__(
)
super().__init__(title, stack_template, **kwargs)
create_new_domains(module.new_resources, self)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True

Expand Down
3 changes: 2 additions & 1 deletion ecs_composex/rds/rds_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def __init__(
super().__init__(title, stack_template, **kwargs)
generate_rds_templates(self, stack_template, module.new_resources, settings)
self.parent_stack = settings.root_stack
# self.mark_nested_stacks()
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
if module.lookup_resources and module.mapping_key not in settings.mappings:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/rds/rds_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, name, stack_template, db, rds_stack, **kwargs):
super().__init__(name, stack_template, **kwargs)
self.parent_stack = rds_stack
db.stack = self
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", db.module.module_deletion_policy)


def add_db_stack(root_template, db, settings, rds_stack):
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/route53/route53_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,7 @@ def __init__(
self.is_void = True
stack_template = build_template(module.res_key)
super().__init__(module.mapping_key, stack_template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
for resource in module.resources_list:
resource.stack = self
2 changes: 2 additions & 0 deletions ecs_composex/s3/s3_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def __init__(
super().__init__(module.mapping_key, stack_template, **kwargs)
create_s3_template(module.new_resources, stack_template)
self.parent_stack = settings.root_stack
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
for resource in module.resources_list:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/sns/sns_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ def __init__(
template = build_template(f"{module.res_key} - stack")
import_sns_topics_to_template(module.new_resources, template)
super().__init__(module.mapping_key, stack_template=template, **kwargs)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
for resource in module.resources_list:
resource.stack = self
2 changes: 2 additions & 0 deletions ecs_composex/sqs/sqs_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def __init__(
)
super().__init__(title, stack_template=template, **kwargs)
render_new_queues(settings, module.new_resources, self, template)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
for resource in module.resources_list:
Expand Down
2 changes: 2 additions & 0 deletions ecs_composex/ssm_parameter/ssm_parameter_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def __init__(
template = build_template("Parent template for SSM in ECS Compose-X")
super().__init__(module.mapping_key, stack_template=template, **kwargs)
render_new_parameters(module.new_resources, self)
if not hasattr(self, "DeletionPolicy"):
setattr(self, "DeletionPolicy", module.module_deletion_policy)
else:
self.is_void = True
for resource in module.resources_list:
Expand Down
1 change: 1 addition & 0 deletions use-cases/s3/simple_s3_bucket.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: "3.8"

x-s3:
DeletionPolicy: Retain
bucket-01:
Properties:
BucketName: bucket-01
Expand Down