in samcli/lib/iac/cfn/cfn_iac.py [0:0]
def _build_stack(self, path: str, is_nested: bool = False, name: Optional[str] = None) -> Stack:
asset: Asset
assets: List[Asset] = []
if os.path.islink(path):
path = os.path.realpath(path)
base_dir = self._base_dir or os.path.dirname(path)
stack = Stack(is_nested=is_nested, name=name, assets=assets, origin_dir=os.path.dirname(path))
template_dict = get_template_data(path)
options = self._context.command_options_map
resolved_stack = SamBaseProvider.get_resolved_template_dict(
template_dict,
SamLocalStackProvider.merge_parameter_overrides(
options.get(PARAMETER_OVERRIDES), options.get(GLOBAL_PARAMETER_OVERRIDES)
),
normalize_resource_metadata=False,
)
for key, value in resolved_stack.items():
stack[key] = value
resources_section = stack.get("Resources", DictSection())
for resource in resources_section.section_items:
resource_id = resource.item_id
resource_type = resource.get("Type", None)
properties = resource.get("Properties", {})
package_type = properties.get("PackageType", ZIP)
resource_assets: List[Asset] = []
if resource_type in NESTED_STACKS_RESOURCES:
nested_stack = self._extract_nested_stack(path, resource_id, properties, resource_type)
resource.nested_stack = nested_stack
if resource_type in RESOURCES_WITH_LOCAL_PATHS:
for path_prop_name in RESOURCES_WITH_LOCAL_PATHS[resource_type]:
asset_path = jmespath.search(path_prop_name, properties)
if is_local_path(asset_path) and package_type == ZIP:
reference_path = base_dir if resource_type in BASE_DIR_RESOURCES else os.path.dirname(path)
asset_path = get_local_path(asset_path, reference_path)
asset = S3Asset(source_path=asset_path, source_property=path_prop_name)
resource_assets.append(asset)
stack.assets.append(asset)
if resource_type in RESOURCES_WITH_IMAGE_COMPONENT:
for path_prop_name in RESOURCES_WITH_IMAGE_COMPONENT[resource_type]:
asset_path = jmespath.search(path_prop_name, properties)
if asset_path and package_type == IMAGE:
asset = ImageAsset(source_local_image=asset_path, source_property=path_prop_name)
resource_assets.append(asset)
stack.assets.append(asset)
resource.assets = resource_assets
metadata_section = stack.get("Metadata", DictSection())
for metadata in metadata_section.section_items:
if not isinstance(metadata, DictSectionItem):
continue
metadata_type = metadata.item_id
metadata_body = metadata.body
metadata_assets: List[Asset] = []
if metadata_type in METADATA_WITH_LOCAL_PATHS:
for path_prop_name in METADATA_WITH_LOCAL_PATHS[metadata_type]:
asset_path = jmespath.search(path_prop_name, metadata_body)
asset = S3Asset(source_path=asset_path, source_property=path_prop_name)
metadata_assets.append(asset)
stack.assets.append(asset)
metadata.assets = metadata_assets
stack.extra_details[TEMPLATE_PATH_KEY] = path
return stack