Skip to content

Commit 5576a24

Browse files
committed
Update docs for added context
1 parent 9640060 commit 5576a24

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ No modules.
4141
| [aws_cloudwatch_log_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
4242
| [aws_cloudwatch_metric_alarm.lambda_errors](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource |
4343
| [aws_iam_role_policy_attachment.lambda_basic_execution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
44+
| [aws_iam_role_policy_attachment.lambda_insights](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
4445
| [aws_iam_role_policy_attachment.lambda_networking](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
4546
| [aws_iam_role_policy_attachment.lambda_xray](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
4647
| [aws_lambda_function.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
47-
| [aws_s3_bucket.lambda_deploy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
4848
| [aws_s3_bucket_object.lambda_deploy_object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object) | resource |
49-
| [aws_s3_bucket_policy.lambda_deploy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
50-
| [aws_s3_bucket_public_access_block.lambda_deploy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
5149
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
52-
| [aws_iam_policy_document.lambda_deploy_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
50+
| [aws_ssm_parameter.deployment_bucket_id](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
5351

5452
## Inputs
5553

5654
| Name | Description | Type | Default | Required |
5755
|------|-------------|------|---------|:--------:|
56+
| <a name="input_deployment_bucket_id"></a> [deployment\_bucket\_id](#input\_deployment\_bucket\_id) | ID of S3 bucket that should store our deployment artifacts. Will use the /account/DEPLOYMENT\_BUCKET\_ID value from SSM unless specified otherwise. | `string` | `null` | no |
5857
| <a name="input_description"></a> [description](#input\_description) | Description of the Lambda Function | `string` | `null` | no |
5958
| <a name="input_environment"></a> [environment](#input\_environment) | Environment variables to be passed to the function | `map(string)` | `{}` | no |
6059
| <a name="input_error_rate_alarm_threshold"></a> [error\_rate\_alarm\_threshold](#input\_error\_rate\_alarm\_threshold) | Error rate (in percent, 1-100) at which to trigger an alarm notification | `number` | `25` | no |
60+
| <a name="input_git_sha"></a> [git\_sha](#input\_git\_sha) | Hash generated by `git hash-object` in source repo and used to determine whether a lambda needs to be updated | `string` | `null` | no |
6161
| <a name="input_handler"></a> [handler](#input\_handler) | Name of the handler function inside the artifact (https://docs.aws.amazon.com/lambda/latest/dg/configuration-console.html) | `string` | n/a | yes |
6262
| <a name="input_layer_arns"></a> [layer\_arns](#input\_layer\_arns) | List of ARNs for layers to use with the function | `list(string)` | `[]` | no |
6363
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | Number of days to keep function logs in Cloudwatch | `number` | `365` | no |

main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
*/
2424

2525
locals {
26-
deploy_artifact_key = "deploy.zip"
27-
source_hash = coalesce(var.git_sha, filebase64sha256(var.path))
28-
role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.role_name}"
26+
deploy_artifact_key = "deploy.zip"
27+
deployment_bucket_id = coalesce(var.deployment_bucket_id, data.aws_ssm_parameter.deployment_bucket_id.value)
28+
source_hash = coalesce(var.git_sha, filebase64sha256(var.path))
29+
role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.role_name}"
2930
}
3031

3132
# Configure default role permissions
@@ -51,7 +52,7 @@ resource "aws_iam_role_policy_attachment" "lambda_insights" {
5152

5253
# S3 object to hold the deployed artifact
5354
resource "aws_s3_bucket_object" "lambda_deploy_object" {
54-
bucket = data.aws_ssm_parameter.deployment_bucket_id.value
55+
bucket = local.deployment_bucket_id
5556
key = "${var.name}/${local.deploy_artifact_key}"
5657
source = var.path
5758
source_hash = md5(local.source_hash)
@@ -74,7 +75,7 @@ resource "aws_lambda_function" "lambda" {
7475
reserved_concurrent_executions = var.reserved_concurrent_executions
7576
role = local.role_arn
7677
runtime = var.runtime
77-
s3_bucket = data.aws_ssm_parameter.deployment_bucket_id.value
78+
s3_bucket = local.deployment_bucket_id
7879
s3_key = aws_s3_bucket_object.lambda_deploy_object.key
7980
s3_object_version = aws_s3_bucket_object.lambda_deploy_object.version_id
8081
tags = var.tags

vars.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "description" {
44
type = string
55
}
66

7+
variable "deployment_bucket_id" {
8+
default = null
9+
description = "ID of S3 bucket that should store our deployment artifacts. Will use the /account/DEPLOYMENT_BUCKET_ID value from SSM unless specified otherwise."
10+
type = string
11+
}
12+
713
variable "environment" {
814
default = {}
915
description = "Environment variables to be passed to the function"
@@ -17,9 +23,9 @@ variable "error_rate_alarm_threshold" {
1723
}
1824

1925
variable "git_sha" {
20-
type = string
21-
description = "Git SHA hash for lambda source code"
2226
default = null
27+
description = "Hash generated by `git hash-object` in source repo and used to determine whether a lambda needs to be updated"
28+
type = string
2329
}
2430

2531
variable "handler" {

0 commit comments

Comments
 (0)