Skip to content

Commit 79762a1

Browse files
committed
enha: added variable to define arm64 Lambda function (#7)
1 parent 4709d5d commit 79762a1

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

README.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ This module provides a Lambda function which logs to CloudWatch. If no image URI
2121

2222
## Inputs
2323

24-
| Name | Description | Type | Default | Required |
25-
| ------------- | ---------------------------------------------------------------------------- | -------------- | ------- | :------: |
26-
| identifier | Unique identifier to differentiate global resources. | `string` | n/a | yes |
27-
| policies | List of IAM policy ARNs for the Lambda's IAM role. | `list(string)` | [] | no |
28-
| vpc_config | Object to define the subnets and security groups for the Lambda function. | `object` | null | no |
29-
| log_config | Object to define logging configuration of the Lambda function to CloudWatch. | `object` | null | no |
30-
| image | Object of the image which will be pulled by the Lambda function to execute. | `object` | null | no |
31-
| memory_size | Amount of memory in MB the Lambda function can use at runtime. | `number` | 128 | no |
32-
| timeout | Amount of time the Lambda function has to run in seconds. | `number` | 3 | no |
33-
| env_variables | A map of environment variables for the Lambda function at runtime. | `map(string)` | {} | no |
34-
| tags | A map of tags to add to all resources. | `map(string)` | {} | no |
24+
| Name | Description | Type | Default | Required |
25+
| ------------- | --------------------------------------------------------------------------------------------- | -------------- | -------- | :------: |
26+
| identifier | Unique identifier to differentiate global resources. | `string` | n/a | yes |
27+
| policies | List of IAM policy ARNs for the Lambda's IAM role. | `list(string)` | [] | no |
28+
| vpc_config | Object to define the subnets and security groups for the Lambda function. | `object` | null | no |
29+
| log_config | Object to define logging configuration of the Lambda function to CloudWatch. | `object` | null | no |
30+
| image | Object of the image which will be pulled by the Lambda function to execute. | `object` | null | no |
31+
| architecture | Instruction set architecture for the Lambda function. Valid values are: 'x86_64' and 'arm64'. | `string` | "x86_64" | no |
32+
| memory_size | Amount of memory in MB the Lambda function can use at runtime. | `number` | 128 | no |
33+
| timeout | Amount of time the Lambda function has to run in seconds. | `number` | 3 | no |
34+
| env_variables | A map of environment variables for the Lambda function at runtime. | `map(string)` | {} | no |
35+
| tags | A map of tags to add to all resources. | `map(string)` | {} | no |
3536

3637
### `vpc_config`
3738

@@ -67,9 +68,11 @@ This module provides a Lambda function which logs to CloudWatch. If no image URI
6768
module "function" {
6869
source = "github.com/custom-terraform-aws-modules/function"
6970
70-
identifier = "example-function-dev"
71-
memory_size = 128
72-
timeout = 3
71+
identifier = "example-function-dev"
72+
architecture = "x86_64"
73+
memory_size = 128
74+
timeout = 3
75+
7376
policies = [
7477
"arn:aws:iam::aws:policy/aws-service-role/AccessAnalyzerServiceRolePolicy",
7578
"arn:aws:iam::aws:policy/AdministratorAccess-Amplify"

main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ resource "aws_lambda_function" "main" {
119119
image_uri = var.image == null ? "${aws_ecr_repository.main[0].repository_url}:latest" : try(var.image["uri"], null)
120120
memory_size = var.memory_size
121121
timeout = var.timeout
122+
architectures = [var.architecture]
122123

123124
environment {
124125
variables = var.env_variables

tests/lambda.tftest.hcl

+20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ run "valid_identifier" {
2525
}
2626
}
2727

28+
run "invalid_architecture" {
29+
command = plan
30+
31+
variables {
32+
identifier = "abc"
33+
architecture = "test_64"
34+
}
35+
36+
expect_failures = [var.architecture]
37+
}
38+
39+
run "valid_architecture" {
40+
command = plan
41+
42+
variables {
43+
identifier = "abc"
44+
architecture = "arm64"
45+
}
46+
}
47+
2848
run "invalid_vpc_subnets" {
2949
command = plan
3050

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ variable "image" {
5757
default = null
5858
}
5959

60+
variable "architecture" {
61+
description = "Instruction set architecture for the Lambda function. Valid values are: 'x86_64' and 'arm64'."
62+
type = string
63+
default = "x86_64"
64+
validation {
65+
condition = var.architecture == "x86_64" || var.architecture == "arm64"
66+
error_message = "Architecture must be either 'x86_64' or 'arm64'"
67+
}
68+
}
69+
6070
variable "memory_size" {
6171
description = "Amount of memory in MB the Lambda function can use at runtime."
6272
type = number

0 commit comments

Comments
 (0)