Skip to content

CFn: remove get_resource_type #12546

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

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ProgressEvent,
ResourceProviderExecutor,
ResourceProviderPayload,
get_resource_type,
standardise_resource_type,
)
from localstack.services.cloudformation.service_models import (
DependencyNotYetSatisfied,
Expand Down Expand Up @@ -364,7 +364,7 @@ def _resolve_refs_recursively(
)
resource = resources.get(resource_logical_id)

resource_type = get_resource_type(resource)
resource_type = standardise_resource_type(resource["Type"])
resolved_getatt = get_attr_from_model_instance(
resource,
attribute_name,
Expand Down Expand Up @@ -812,7 +812,7 @@ def _replace(match):
resolved = get_attr_from_model_instance(
resources[logical_resource_id],
attr_name,
get_resource_type(resources[logical_resource_id]),
standardise_resource_type(resources[logical_resource_id]["Type"]),
logical_resource_id,
)
if resolved is None:
Expand Down Expand Up @@ -1295,7 +1295,9 @@ def apply_change(self, change: ChangeConfig, stack: Stack) -> None:
action, logical_resource_id=resource_id
)

resource_provider = executor.try_load_resource_provider(get_resource_type(resource))
resource_provider = executor.try_load_resource_provider(
standardise_resource_type(resource["Type"])
)
if resource_provider is not None:
# add in-progress event
resource_status = f"{get_action_name_for_resource_change(action)}_IN_PROGRESS"
Expand Down Expand Up @@ -1407,7 +1409,7 @@ def delete_stack(self):
resource["Properties"] = resource.get(
"Properties", clone_safe(resource)
) # TODO: why is there a fallback?
resource["ResourceType"] = get_resource_type(resource)
resource["ResourceType"] = standardise_resource_type(resource["Type"])

ordered_resource_ids = list(
order_resources(
Expand Down Expand Up @@ -1438,7 +1440,9 @@ def delete_stack(self):
len(resources),
resource["ResourceType"],
)
resource_provider = executor.try_load_resource_provider(get_resource_type(resource))
resource_provider = executor.try_load_resource_provider(
standardise_resource_type(resource["Type"])
)
if resource_provider is not None:
event = executor.deploy_loop(
resource_provider, resource, resource_provider_payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,13 @@ def list(self, request: ResourceRequest[Properties]) -> ProgressEvent[Properties
raise NotImplementedError


# legacy helpers
def get_resource_type(resource: dict) -> str:
"""this is currently overwritten in PRO to add support for custom resources"""
if isinstance(resource, str):
raise ValueError(f"Invalid argument: {resource}")
try:
resource_type: str = resource["Type"]

if resource_type.startswith("Custom::"):
return "AWS::CloudFormation::CustomResource"
return resource_type
except Exception:
LOG.warning(
"Failed to retrieve resource type %s",
resource.get("Type"),
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
def standardise_resource_type(resource_type: str) -> str:
"""
Custom resources can either start with Custom:: or AWS::CloudFormation::CustomResource.
"""
if resource_type.startswith("Custom::"):
return "AWS::CloudFormation::CustomResource"
return resource_type


def invoke_function(
Expand Down Expand Up @@ -444,7 +434,7 @@ def deploy_loop(
max_iterations = max(ceil(max_timeout / sleep_time), 2)

for current_iteration in range(max_iterations):
resource_type = get_resource_type({"Type": raw_payload["resourceType"]})
resource_type = standardise_resource_type(raw_payload["resourceType"])
resource["SpecifiedProperties"] = raw_payload["requestData"]["resourceProperties"]

try:
Expand Down
Loading