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
Next Next commit
Ignore changes (#1)
* add ignore_changes_package (source code hash) var

* update CHANGELOG
  • Loading branch information
anoshi authored Jul 15, 2021
commit ca27838b076b78eaaa9dd2132e8c0155fd2c9ad3
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]


- feat: Add `ignore_changes_package` variable to allow the lambda function resource to be managed by terraform but have the function code managed externally

<a name="v2.7.0"></a>
## [v2.7.0] - 2021-07-08
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ module "lambda_function_existing_package_local" {
}
```

### Lambda Function where package deployments are maintained separately to infrastructure

If using this method you need to be aware of the following:

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.

```hcl
module "lambda_function_externally_managed_package" {
source = "terraform-aws-modules/lambda/aws"

function_name = "my-lambda-externally-managed-package"
description = "My lambda function code is deployed separately"
handler = "index.lambda_handler"
runtime = "python3.8"

create_package = false
local_existing_package = "../dummy_package.zip"
ignore_changes_package = true
}
```

### Lambda Function with existing package (prebuilt) stored in S3 bucket

Note that this module does not copy prebuilt packages into S3 bucket. This module can only store packages it builds locally and in S3 bucket.
Expand Down Expand Up @@ -664,6 +686,7 @@ No modules.
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | A unique name for your Lambda Function | `string` | `""` | no |
| <a name="input_handler"></a> [handler](#input\_handler) | Lambda Function entrypoint in your code | `string` | `""` | no |
| <a name="input_hash_extra"></a> [hash\_extra](#input\_hash\_extra) | The string to add into hashing function. Useful when building same source path for different functions. | `string` | `""` | no |
| <a name="input_ignore_changes_package"></a> [ignore\_changes\_package](#input\_ignore\_changes\_package) | Set to true to ignore changes to the function's source code package/hash. Useful when infrastructure and code deployments are managed by separate pipelines | `bool` | `false` | no |
| <a name="input_image_config_command"></a> [image\_config\_command](#input\_image\_config\_command) | The CMD for the docker image | `list(string)` | `[]` | no |
| <a name="input_image_config_entry_point"></a> [image\_config\_entry\_point](#input\_image\_config\_entry\_point) | The ENTRYPOINT for the docker image | `list(string)` | `[]` | no |
| <a name="input_image_config_working_directory"></a> [image\_config\_working\_directory](#input\_image\_config\_working\_directory) | The working directory for the docker image | `string` | `null` | no |
Expand Down
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ resource "aws_lambda_function" "this" {
}
}

dynamic "lifecycle" {
for_each = var.ignore_changes_package ? [true] : []
content {
ignore_changes = [source_code_hash]
}
}

tags = var.tags

# Depending on the log group is necessary to allow Terraform to create the log group before AWS can.
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ variable "artifacts_dir" {
default = "builds"
}

variable "ignore_changes_package" {
description = "Set to true to ignore changes to the function's source code package/hash. Useful when infrastructure and code deployments are managed by separate pipelines"
type = bool
default = false
}

variable "local_existing_package" {
description = "The absolute path to an existing zip-file to use"
type = string
Expand Down