Skip to content

Commit

Permalink
enha: added variable to define arm64 Lambda function (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kfc-manager committed Apr 1, 2024
1 parent 4709d5d commit 79762a1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ This module provides a Lambda function which logs to CloudWatch. If no image URI

## Inputs

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

### `vpc_config`

Expand Down Expand Up @@ -67,9 +68,11 @@ This module provides a Lambda function which logs to CloudWatch. If no image URI
module "function" {
source = "github.com/custom-terraform-aws-modules/function"
identifier = "example-function-dev"
memory_size = 128
timeout = 3
identifier = "example-function-dev"
architecture = "x86_64"
memory_size = 128
timeout = 3
policies = [
"arn:aws:iam::aws:policy/aws-service-role/AccessAnalyzerServiceRolePolicy",
"arn:aws:iam::aws:policy/AdministratorAccess-Amplify"
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ resource "aws_lambda_function" "main" {
image_uri = var.image == null ? "${aws_ecr_repository.main[0].repository_url}:latest" : try(var.image["uri"], null)
memory_size = var.memory_size
timeout = var.timeout
architectures = [var.architecture]

environment {
variables = var.env_variables
Expand Down
20 changes: 20 additions & 0 deletions tests/lambda.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ run "valid_identifier" {
}
}

run "invalid_architecture" {
command = plan

variables {
identifier = "abc"
architecture = "test_64"
}

expect_failures = [var.architecture]
}

run "valid_architecture" {
command = plan

variables {
identifier = "abc"
architecture = "arm64"
}
}

run "invalid_vpc_subnets" {
command = plan

Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ variable "image" {
default = null
}

variable "architecture" {
description = "Instruction set architecture for the Lambda function. Valid values are: 'x86_64' and 'arm64'."
type = string
default = "x86_64"
validation {
condition = var.architecture == "x86_64" || var.architecture == "arm64"
error_message = "Architecture must be either 'x86_64' or 'arm64'"
}
}

variable "memory_size" {
description = "Amount of memory in MB the Lambda function can use at runtime."
type = number
Expand Down

0 comments on commit 79762a1

Please sign in to comment.