Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed code a bit and README
  • Loading branch information
antonbabenko committed Aug 20, 2021
commit abaee1f0b362c24e0a76053ba9a87c44df6d256e
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ module "lambda_function_existing_package_local" {
}
```

### Lambda Function where package deployments are maintained separately to infrastructure
### Lambda Function or Lambda Layer with the deployable artifact maintained separately from the infrastructure

If using this method you need to be aware of the following:
If you want to manage function code and infrastructure resources (such as IAM permissions, policies, events, etc) in separate flows (e.g., different repositories, teams, CI/CD pipelines).

1. A 'dummy' package will need to be included with your terraform code/module. This is deployed to the function when the lambda component is initialised.
1. You will need to redeploy the real function code after the terraform apply every time the lambda function resource is recreated / force replaced; the 'dummy' package is deployed every time the lambda resource is created.
Disable source code tracking to turn off deployments (and rollbacks) using the module by setting `ignore_source_code_hash = true` and deploy a _dummy function_.

When the infrastructure and the dummy function is deployed, you can use external tool to update the source code of the function (eg, using [AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html)) and keep using this module via Terraform to manage the infrastructure.

Be aware that changes in `local_existing_package` value may trigger deployment via Terraform.

```hcl
module "lambda_function_externally_managed_package" {
Expand All @@ -122,8 +125,9 @@ module "lambda_function_externally_managed_package" {
handler = "index.lambda_handler"
runtime = "python3.8"

create_package = false
local_existing_package = "./lambda_functions/dummy_lambda.zip"
create_package = false
local_existing_package = "./lambda_functions/code.zip"

ignore_source_code_hash = true
}
```
Expand Down
2 changes: 2 additions & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | ../../ | |
| <a name="module_lambda_function_existing_package_local"></a> [lambda\_function\_existing\_package\_local](#module\_lambda\_function\_existing\_package\_local) | ../../ | |
| <a name="module_lambda_function_for_each"></a> [lambda\_function\_for\_each](#module\_lambda\_function\_for\_each) | ../../ | |
| <a name="module_lambda_function_with_package_deploying_externally"></a> [lambda\_function\_with\_package\_deploying\_externally](#module\_lambda\_function\_with\_package\_deploying\_externally) | ../../ | |
| <a name="module_lambda_layer_local"></a> [lambda\_layer\_local](#module\_lambda\_layer\_local) | ../../ | |
| <a name="module_lambda_layer_s3"></a> [lambda\_layer\_s3](#module\_lambda\_layer\_s3) | ../../ | |
| <a name="module_lambda_layer_with_package_deploying_externally"></a> [lambda\_layer\_with\_package\_deploying\_externally](#module\_lambda\_layer\_with\_package\_deploying\_externally) | ../../ | |
| <a name="module_lambda_with_mixed_trusted_entities"></a> [lambda\_with\_mixed\_trusted\_entities](#module\_lambda\_with\_mixed\_trusted\_entities) | ../../ | |
| <a name="module_lambda_with_provisioned_concurrency"></a> [lambda\_with\_provisioned\_concurrency](#module\_lambda\_with\_provisioned\_concurrency) | ../../ | |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | |
Expand Down
38 changes: 38 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ module "lambda_layer_local" {
source_path = "${path.module}/../fixtures/python3.8-app1"
}

####################################################
# Lambda Layer with package deploying externally
# (e.g., using separate CI/CD pipeline)
####################################################

module "lambda_layer_with_package_deploying_externally" {
source = "../../"

create_layer = true

layer_name = "${random_pet.this.id}-layer-local"
description = "My amazing lambda layer (deployed from local)"
compatible_runtimes = ["python3.8"]

create_package = false
local_existing_package = "../fixtures/python3.8-zip/existing_package.zip"

ignore_source_code_hash = true
}

###############################
# Lambda Layer (storing on S3)
###############################
Expand Down Expand Up @@ -277,6 +297,24 @@ module "lambda_function_for_each" {
local_existing_package = "${path.module}/../fixtures/python3.8-zip/existing_package.zip"
}

####################################################
# Lambda Function with package deploying externally
# (e.g., using separate CI/CD pipeline)
####################################################

module "lambda_function_with_package_deploying_externally" {
source = "../../"

function_name = "${random_pet.this.id}-lambda-with-package-deploying-externally"
handler = "index.lambda_handler"
runtime = "python3.8"

create_package = false
local_existing_package = "../fixtures/python3.8-zip/existing_package.zip"

ignore_source_code_hash = true
}

###########
# Disabled
###########
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ resource "aws_lambda_layer_version" "this" {
compatible_runtimes = length(var.compatible_runtimes) > 0 ? var.compatible_runtimes : [var.runtime]

filename = local.filename
source_code_hash = (local.filename == null ? false : fileexists(local.filename)) && !local.was_missing ? filebase64sha256(local.filename) : null
source_code_hash = var.ignore_source_code_hash ? null : (local.filename == null ? false : fileexists(local.filename)) && !local.was_missing ? filebase64sha256(local.filename) : null

s3_bucket = local.s3_bucket
s3_key = local.s3_key
Expand Down