@@ -26,7 +26,22 @@ resource "local_file" "makefile_template" {
2626}
2727
2828# Create zip package from source directory
29+ # data "archive_file" "lambda_zip" {
30+ # type = "zip"
31+ # source_dir = local.source_dir
32+ # output_path = "${path.module}/.terraform/tmp/${module.this.id}.zip"
33+
34+ # depends_on = [
35+ # local_file.bootstrap_template,
36+ # local_file.handler_template,
37+ # local_file.makefile_template
38+ # ]
39+ # }
40+
41+ # Create zip package from source directory (only for Zip package type)
2942data "archive_file" "lambda_zip" {
43+ count = var. package_type == " Zip" ? 1 : 0
44+
3045 type = " zip"
3146 source_dir = local. source_dir
3247 output_path = " ${ path . module } /.terraform/tmp/${ module . this . id } .zip"
@@ -38,6 +53,7 @@ data "archive_file" "lambda_zip" {
3853 ]
3954}
4055
56+
4157# IAM role for Lambda execution
4258resource "aws_iam_role" "lambda_execution" {
4359 name = " ${ module . this . id } -execution"
@@ -72,19 +88,63 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
7288 tags = module. this . tags
7389}
7490
91+ # Lambda function
92+ # resource "aws_lambda_function" "this" {
93+ # function_name = module.this.id
94+ # role = aws_iam_role.lambda_execution.arn
95+
96+ # filename = data.archive_file.lambda_zip.output_path
97+ # source_code_hash = data.archive_file.lambda_zip.output_base64sha256
98+
99+ # handler = var.handler
100+ # runtime = var.runtime
101+ # architectures = [var.architecture]
102+ # memory_size = var.memory_size
103+ # timeout = var.timeout
104+
105+ # dynamic "environment" {
106+ # for_each = length(var.environment_variables) > 0 ? [1] : []
107+ # content {
108+ # variables = var.environment_variables
109+ # }
110+ # }
111+
112+ # depends_on = [
113+ # aws_iam_role_policy_attachment.lambda_basic_execution,
114+ # aws_cloudwatch_log_group.lambda_logs,
115+ # ]
116+
117+ # tags = module.this.tags
118+ # }
119+
75120# Lambda function
76121resource "aws_lambda_function" "this" {
77122 function_name = module. this . id
78123 role = aws_iam_role. lambda_execution . arn
79124
80- filename = data. archive_file . lambda_zip . output_path
81- source_code_hash = data. archive_file . lambda_zip . output_base64sha256
125+ package_type = var. package_type
126+
127+ # Zip package configuration
128+ filename = var. package_type == " Zip" ? data. archive_file . lambda_zip [0 ]. output_path : null
129+ source_code_hash = var. package_type == " Zip" ? data. archive_file . lambda_zip [0 ]. output_base64sha256 : null
130+ handler = var. package_type == " Zip" ? var. handler : null
131+ runtime = var. package_type == " Zip" ? var. runtime : null
132+
133+ # Container image configuration
134+ image_uri = var. package_type == " Image" ? var. image_uri : null
135+
136+ dynamic "image_config" {
137+ for_each = var. package_type == " Image" && var. image_config != null ? [var . image_config ] : []
138+ content {
139+ entry_point = image_config. value . entry_point
140+ command = image_config. value . command
141+ working_directory = image_config. value . working_directory
142+ }
143+ }
82144
83- handler = var. handler
84- runtime = var. runtime
85- architectures = [var . architecture ]
86- memory_size = var. memory_size
87- timeout = var. timeout
145+ architectures = [var . architecture ]
146+ memory_size = var. memory_size
147+ timeout = var. timeout
88148
89149 dynamic "environment" {
90150 for_each = length (var. environment_variables ) > 0 ? [1 ] : []
0 commit comments