in samcli/hook_packages/terraform/hooks/prepare/property_builder.py [0:0]
def _build_code_property(tf_properties: dict, resource: TFResource) -> Any:
"""
Builds the Code property of a CloudFormation AWS Lambda Function out of the
properties of the equivalent terraform resource
Parameters
----------
tf_properties: dict
Properties of the terraform AWS Lambda function resource
resource: TFResource
Configuration terraform resource
Returns
-------
dict
The built Code property of a CloudFormation AWS Lambda Function resource
"""
filename = tf_properties.get("filename")
if filename:
return filename
code = {}
tf_cfn_prop_names = [
("s3_bucket", "S3Bucket"),
("s3_key", "S3Key"),
("image_uri", "ImageUri"),
("s3_object_version", "S3ObjectVersion"),
]
for tf_prop_name, cfn_prop_name in tf_cfn_prop_names:
tf_prop_value = tf_properties.get(tf_prop_name)
if tf_prop_value is not None:
code[cfn_prop_name] = tf_prop_value
package_type = tf_properties.get("package_type", ZIP)
# Get the S3 Bucket details from configuration in case if the customer is creating the S3 bucket in the tf project
if package_type == ZIP and ("S3Bucket" not in code or "S3Key" not in code or "S3ObjectVersion" not in code):
s3_bucket_tf_config_value = _resolve_resource_attribute(resource, "s3_bucket")
s3_key_tf_config_value = _resolve_resource_attribute(resource, "s3_key")
s3_object_version_tf_config_value = _resolve_resource_attribute(resource, "s3_object_version")
if "S3Bucket" not in code and s3_bucket_tf_config_value:
code["S3Bucket"] = REMOTE_DUMMY_VALUE
code["S3Bucket_config_value"] = s3_bucket_tf_config_value
if "S3Key" not in code and s3_key_tf_config_value:
code["S3Key"] = REMOTE_DUMMY_VALUE
code["S3Key_config_value"] = s3_key_tf_config_value
if "S3ObjectVersion" not in code and s3_object_version_tf_config_value:
code["S3ObjectVersion"] = REMOTE_DUMMY_VALUE
code["S3ObjectVersion_config_value"] = s3_object_version_tf_config_value
# Get the Image URI details from configuration in case if the customer is creating the ecr repo in the tf project
if package_type == IMAGE and "ImageUri" not in code:
image_uri_tf_config_value = _resolve_resource_attribute(resource, "image_uri")
if image_uri_tf_config_value:
code["ImageUri"] = REMOTE_DUMMY_VALUE
return code