Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eedf435
Initial commit
yhakbar Jul 7, 2022
b048645
Update README for new release: 0.0.2
yhakbar Jul 7, 2022
64313ed
Fixing minification script
yhakbar Jul 8, 2022
86acad7
Accounting for differently named repo for the template
yhakbar Jul 8, 2022
9003141
Merge pull request #1 from pbs/bugfix/fixing_minification_script
yhakbar Jul 8, 2022
828048d
Update README for new release: 0.0.3
yhakbar Jul 8, 2022
c428c69
Upgrading golang dependencies
yhakbar Jul 8, 2022
4976f78
Merge pull request #2 from pbs/chore/upgrading_golang_deps
yhakbar Jul 8, 2022
68c1f94
Update README for new release: 0.0.4
yhakbar Jul 8, 2022
7ad27e9
Updating .tool-versions
yhakbar Aug 12, 2022
31fb4ba
Updating AWS tflint plugin
yhakbar Aug 12, 2022
66a06b7
Updating golang modules
yhakbar Aug 12, 2022
59d956c
Upgrading .terraform.lock.hcl
yhakbar Aug 12, 2022
370acf1
Bash script formatting
yhakbar Aug 12, 2022
82564c2
Merge pull request #3 from pbs/chore/misc_updates
yhakbar Aug 15, 2022
e22ef07
Update README for new release: 0.0.5
yhakbar Aug 15, 2022
7d8d354
Resolving perpetual tag diff bug
yhakbar Oct 14, 2022
bbd591f
Fixing description for name parameter
yhakbar Oct 16, 2022
ec2537f
Upgrading dependencies
yhakbar Oct 18, 2022
71225cf
Merge pull request #4 from pbs/bugfix/resolving_perpetual_diff_bug
yhakbar Oct 18, 2022
88d589a
Update README for new release: 0.0.6
yhakbar Oct 18, 2022
fb1091c
Merge pull request #5 from pbs/chore/upgrading_dependencies
yhakbar Oct 18, 2022
6c543e0
Update README for new release: 0.0.7
yhakbar Oct 18, 2022
a492a1c
Doing some documentation updates
yhakbar Jan 3, 2023
ebd62ca
Update README for new release: 0.0.8
yhakbar Jan 3, 2023
6e95b9d
Bump github.com/hashicorp/go-getter from 1.6.2 to 1.7.0 in /tests
dependabot[bot] Feb 17, 2023
b6afc2c
Merge pull request #6 from pbs/dependabot/go_modules/tests/github.com…
yhakbar Feb 17, 2023
77bb0fb
Update README for new release: 0.0.9
yhakbar Feb 17, 2023
ccf8ab5
Upgrading .tool-versions
yhakbar Apr 12, 2023
978b9db
Upgrading golang dependencies
yhakbar Apr 12, 2023
486885c
Upgrading .terraform.lock.hcl files
yhakbar Apr 12, 2023
852e488
Upgrading .tflint.hcl file
yhakbar Apr 12, 2023
c7e3f8f
Updating GitHub Actions
yhakbar Apr 12, 2023
d7168f3
Merging in main, then running `go mod tidy`
yhakbar Apr 12, 2023
be3663d
Updating go.mod with a `go 1.20` entry
yhakbar Apr 12, 2023
31ea5ec
Merge pull request #7 from pbs/chore/updating_dependencies
yhakbar Apr 12, 2023
516fe6b
Update README for new release: 0.0.10
yhakbar Apr 12, 2023
abaa97d
Merge remote-tracking branch 'template/main' into initial_setup
yhakbar Apr 12, 2023
edd51fc
Initial setup complete
yhakbar Apr 13, 2023
5755da6
Updating README with useful info
yhakbar Apr 13, 2023
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
41 changes: 24 additions & 17 deletions README-HEADER.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PBS TF MOD_TITLE
# PBS TF lambda event source mapping module

## Installation

Expand All @@ -7,7 +7,7 @@
Use this URL for the source of the module. See the usage examples below for more details.

```hcl
github.com/pbs/terraform-aws-MOD_NAME?ref=x.y.z
github.com/pbs/terraform-aws-lambda-event-source-mapping-module?ref=x.y.z
```

### Alternative Installation Methods
Expand All @@ -16,31 +16,38 @@ More information can be found on these install methods and more in [the document

## Usage

<!-- TODO -->
This should be a basic description of what this module does.
Fill this out before completing usage of this template.
<!-- TODO -->
Creates a Lambda event source mapping.

Integrate this module like so:

```hcl
module "MOD_SHORTNAME" {
source = "github.com/pbs/terraform-aws-MOD_NAME?ref=x.y.z"
module "lambda_event_source_mapping" {
source = "github.com/pbs/terraform-aws-lambda-event-source-mapping-module?ref=x.y.z"

<!-- TODO -->
Show some examples of valid values for required parameters.
<!-- TODO -->

# Tagging Parameters
organization = var.organization
environment = var.environment
product = var.product
repo = var.repo
function_name = module.lambda.arn
event_source_arn = module.queue.arn

# Optional Parameters
}
```

For example, this would be how to use this module to create a Lambda event source mapping for a Lambda function that is triggered by an SQS queue:

```hcl
module "lambda_event_source_mapping" {
source = "../.."

function_name = module.lambda.arn
event_source_arn = module.queue.arn

batch_size = 1

scaling_config = {
maximum_concurrency = 10
}
}
```

## Adding This Version of the Module

If this repo is added as a subtree, then the version of the module should be close to the version shown here:
Expand Down
113 changes: 96 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,103 @@
# TF Module Template
# PBS TF lambda event source mapping module

Version: `0.0.10`
## Installation

This is the standard template for Terraform modules. This contains some useful scaffolding to create modules that are:
### Using the Repo Source

1. Well documented
2. Tested
3. Shareable
Use this URL for the source of the module. See the usage examples below for more details.

Repos created off of this template will follow the naming convention `terraform-aws-MOD_NAME-module`, replacing MOD_NAME with the name of your module.
```hcl
github.com/pbs/terraform-aws-lambda-event-source-mapping-module?ref=x.y.z
```

## TODO
### Alternative Installation Methods

After creating a repo from this template, your responsibilities are as follows:
More information can be found on these install methods and more in [the documentation here](./docs/general/install).

- [ ] Run the [wizard.sh](/scripts/wizard.sh) script (`./scripts/wizard.sh`) to populate the boilerplate placeholders with their appropriate values. This includes the proper name of the module and a standardized slug. These values are automatically populated from the name of the repository, but can be adjusted at your discretion.
- [ ] Update [main.tf](/main.tf), [outputs.tf](/outputs.tf), [required.tf](/required.tf) and [optional.tf](/optional.tf) with the configuration for your module (delete files you don't need).
- [ ] Double check that the [terraform.tf](/terraform.tf) and [.tool-versions](/.tool-versions) files have the appropriate versions for resources you are going to use. For major updates, consider updating this template!
- [ ] Create some [examples](/examples) of your module being used. Remember that the examples there will be used for tests that run in real AWS accounts!
- [ ] Create some [tests](/tests) to validate the proper configuration of your module. See instructions [here](/docs/general/dev).
- [ ] Update [README-HEADER.md](/README-HEADER.md) based on the properties of your module. This file will replace the README.md on commit if you follow the instructions [here](/docs/general/dev).
- [ ] Add the git hooks listed under ## Hooks [here](/docs/general/dev). These scripts run as part of the CI, but your development experience will be smoother if you have them running locally as well.
- [ ] Add this template as a remote (`git remote add template git@github.com:pbs/terraform-aws-template-v2.git`). This can be used to allow you to merge back any changes you like from the template into your module.
## Usage

Creates a Lambda event source mapping.

Integrate this module like so:

```hcl
module "lambda_event_source_mapping" {
source = "github.com/pbs/terraform-aws-lambda-event-source-mapping-module?ref=x.y.z"

function_name = module.lambda.arn
event_source_arn = module.queue.arn

# Optional Parameters
}
```

For example, this would be how to use this module to create a Lambda event source mapping for a Lambda function that is triggered by an SQS queue:

```hcl
module "lambda_event_source_mapping" {
source = "../.."

function_name = module.lambda.arn
event_source_arn = module.queue.arn

batch_size = 1

scaling_config = {
maximum_concurrency = 10
}
}
```

## Adding This Version of the Module

If this repo is added as a subtree, then the version of the module should be close to the version shown here:

`x.y.z`

Note, however that subtrees can be altered as desired within repositories.

Further documentation on usage can be found [here](./docs).

Below is automatically generated documentation on this Terraform module using [terraform-docs][terraform-docs]

---

[terraform-docs]: https://github.com/terraform-docs/terraform-docs

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.62.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_lambda_event_source_mapping.mapping](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | The name or the ARN of the Lambda function that will be subscribing to events. | `string` | n/a | yes |
| <a name="input_batch_size"></a> [batch\_size](#input\_batch\_size) | The largest number of records that Lambda will retrieve from your event source at the time of invocation. Defaults to 100 for DynamoDB, Kinesis, MQ and MSK, 10 for SQS. | `number` | `null` | no |
| <a name="input_event_source_arn"></a> [event\_source\_arn](#input\_event\_source\_arn) | The event source ARN - this is required for Kinesis stream, DynamoDB stream, SQS queue, MQ broker or MSK cluster. It is incompatible with a Self Managed Kafka source. | `string` | `null` | no |
| <a name="input_scaling_config"></a> [scaling\_config](#input\_scaling\_config) | Scaling configuration of the event source. Only available for SQS queues. Detailed below. | <pre>object({<br> maximum_concurrency = optional(number)<br> })</pre> | `null` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_uuid"></a> [uuid](#output\_uuid) | The UUID of the created event source mapping |
16 changes: 8 additions & 8 deletions docs/general/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ All the techniques for installing modules are based around the ways that Terrafo
Assuming you don't have manual modifications that you need to make to serve the purposes of an application, the most convenient method of integrating modules might be by using the repo source of this module like so:

```hcl
module "MOD_SHORTNAME" {
source = "github.com/pbs/terraform-MOD_NAME?ref=x.y.z"
module "lambda-event-source-mapping" {
source = "github.com/pbs/terraform-lambda-event-source-mapping-module?ref=x.y.z"
}
```

Expand All @@ -29,9 +29,9 @@ Note that the provider being used might also have availability or security impli
You can install the minified module directly in your repo manually like so:

```bash
mkdir -p 'terraform/modules/MOD_SHORTNAME'
gh -R 'pbs/terraform-MOD_NAME' release download -p 'release.tar.gz' x.y.z
tar -xvf release.tar.gz -C 'terraform/modules/MOD_SHORTNAME'
mkdir -p 'terraform/modules/lambda-event-source-mapping'
gh -R 'pbs/terraform-lambda-event-source-mapping-module' release download -p 'release.tar.gz' x.y.z
tar -xvf release.tar.gz -C 'terraform/modules/lambda-event-source-mapping'
rm -f release.tar.gz
```

Expand All @@ -46,14 +46,14 @@ Please [read this][atlassian-subtree] for information about Git Subtrees, as tha
The simplest use case would work like so:

```bash
git remote add -f MOD_SHORTNAME git@github.com:pbs/terraform-MOD_NAME.git
git subtree add --prefix terraform/modules/MOD_SHORTNAME MOD_SHORTNAME main --squash
git remote add -f lambda-event-source-mapping git@github.com:pbs/terraform-lambda-event-source-mapping-module.git
git subtree add --prefix terraform/modules/lambda-event-source-mapping lambda-event-source-mapping main --squash
```

If necessary, pin the repo version, rather than adding `main` as your subtree:

```bash
git subtree add --prefix terraform/modules/MOD_SHORTNAME MOD_SHORTNAME $REF --squash
git subtree add --prefix terraform/modules/lambda-event-source-mapping lambda-event-source-mapping $REF --squash
```

Where `$REF` is a commit SHA, tag, or branch name.
Expand Down
2 changes: 1 addition & 1 deletion docs/module/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# MOD_TITLE
# lambda event source mapping module

This directory will be used for any documentation that is unique to this module.
2 changes: 2 additions & 0 deletions examples/basic/artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
61 changes: 59 additions & 2 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,65 @@
module "MOD_SHORTNAME" {
source = "../.."
module "lambda" {
source = "github.com/pbs/terraform-aws-lambda-module?ref=1.3.2"

handler = "main.lambda_handler"
filename = "./artifacts/deploy.zip"
runtime = "python3.9"

policy_json = jsonencode({
Statement = [
{
Action = "logs:CreateLogGroup"
Effect = "Allow"
Resource = "arn:aws:logs:us-east-1:*:*"
},
{
Action = [
"logs:PutLogEvents",
"logs:CreateLogStream",
]
Effect = "Allow"
Resource = [
"arn:aws:logs:us-east-1:*:log-group:/aws/lambda/${var.product}*:*",
"arn:aws:logs:us-east-1:*:log-group:/aws/lambda-insights:*",
]
},
{
Action = [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
]
Effect = "Allow"
Resource = module.queue.arn
}
]
Version = "2012-10-17"
})

organization = var.organization
environment = var.environment
product = var.product
repo = var.repo
}

module "queue" {
source = "github.com/pbs/terraform-aws-sqs-module?ref=0.0.1"

organization = var.organization
environment = var.environment
product = var.product
repo = var.repo
}

module "lambda_event_source_mapping" {
source = "../.."

function_name = module.lambda.arn
event_source_arn = module.queue.arn

batch_size = 1

scaling_config = {
maximum_concurrency = 10
}
}
6 changes: 3 additions & 3 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "hello_world" {
description = "Hello World"
value = module.MOD_SHORTNAME.hello_world
output "uuid" {
description = "The UUID of the created event source mapping"
value = module.lambda_event_source_mapping.uuid
}
2 changes: 1 addition & 1 deletion examples/basic/sample-backend.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# terraform {
# backend "s3" {
# bucket = "my-bucket-tfstate"
# key = "example-terraform-aws-MOD_SHORTNAME-basic"
# key = "example-terraform-aws-lambda-event-source-mapping-basic"
# profile = "my-profile"
# region = "us-east-1"
# dynamodb_table = "terraform-lock"
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def lambda_handler():
return "OK"
4 changes: 2 additions & 2 deletions examples/basic/tags.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ variable "environment" {
variable "product" {
description = "Tag used to group resources according to application"

default = "example-tf-MOD_SHORTNAME-basic"
default = "example-tf-lambda-esm-basic"

validation {
condition = can(regex("[a-z\\-]+", var.product))
Expand All @@ -24,7 +24,7 @@ variable "product" {
variable "repo" {
description = "Tag used to point to the repo using this module"

default = "https://github.com/pbs/terraform-MOD_NAME.git"
default = "https://github.com/pbs/terraform-lambda-event-source-mapping-module.git"

validation {
condition = can(regex("(?:git|ssh|https?|git@[-\\w.]+):(\\/\\/)?(.*?)(\\.git)(\\/?|\\#[-\\d\\w._]+?)$", var.repo))
Expand Down
19 changes: 0 additions & 19 deletions locals.tf

This file was deleted.

13 changes: 12 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Resources go here!
resource "aws_lambda_event_source_mapping" "mapping" {
event_source_arn = var.event_source_arn
function_name = var.function_name
batch_size = var.batch_size

dynamic "scaling_config" {
for_each = var.scaling_config == null ? [] : [var.scaling_config]
content {
maximum_concurrency = scaling_config.value.maximum_concurrency
}
}
}
Loading