Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
18c2ec0
(remove): upload code from s3 function
xshot9011 Jun 9, 2022
5668f78
(fix): ref to non-declare resource
xshot9011 Jun 9, 2022
662ad35
(add): new idea to manage terraform
xshot9011 Jun 9, 2022
fd408e6
(update): source code to new algo
xshot9011 Jun 9, 2022
60757af
(fix): lambda edge variable overflow
xshot9011 Jun 9, 2022
250195a
(update): document
xshot9011 Jun 9, 2022
f77485e
(update): README.md
xshot9011 Jun 9, 2022
c9a7d86
(remove): comment path
xshot9011 Jun 9, 2022
a73dbcd
(update): change additional policies to map instead of list deu to un…
xshot9011 Jun 10, 2022
42bb07d
(update): s3 version to v1.0.4
xshot9011 Jun 15, 2022
2febdb7
(add): local tag to ssm parameter store
xshot9011 Jun 20, 2022
4f2677a
(add): tracing mode enable
xshot9011 Jun 23, 2022
286fa8c
(add): change log
xshot9011 Jun 23, 2022
7ddd43a
(fix): set default tracing mode if received from upstream
xshot9011 Jul 1, 2022
bb300a9
(fix): conflict
xshot9011 Jul 11, 2022
e8131ab
(update): order of variables
xshot9011 Jul 13, 2022
059a212
(update): CHANGELOG
xshot9011 Jul 20, 2022
9efd4c6
(update): README
xshot9011 Jul 21, 2022
d1b0243
chore: add community friendly templates
bemillenium Jul 22, 2022
fd11beb
(update): CHANGELOG
xshot9011 Jul 22, 2022
921a7ef
(update): .gitignore
xshot9011 Jul 22, 2022
44cb932
(update): variable name and README
xshot9011 Jul 22, 2022
5c81f77
(update): variable name and README
xshot9011 Jul 22, 2022
a7fd6ec
(update): README
xshot9011 Jul 22, 2022
8ed0d43
(update): variables naming
xshot9011 Jul 22, 2022
dd15b75
(add): complete example
xshot9011 Jul 22, 2022
3908b42
(update): repo name
xshot9011 Jul 22, 2022
d91ec54
(update): example for simple usage
xshot9011 Jul 22, 2022
df5fe91
(update): example simple
xshot9011 Jul 22, 2022
84cd638
(update): example simple
xshot9011 Jul 22, 2022
1d44e7b
(update): lambda complete usage
xshot9011 Jul 22, 2022
85530bf
(update): lambda complete usage
xshot9011 Jul 22, 2022
62d96f7
(fix): conflict
xshot9011 Jul 22, 2022
2e258ef
(update): README and CHANGELOG
xshot9011 Jul 22, 2022
2bce922
(update): README and CHANGELOG
xshot9011 Jul 22, 2022
e376ef4
(update): exmaple format and versioning format
xshot9011 Jul 22, 2022
ae614b7
(update): README.md for example
xshot9011 Jul 22, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ crash.*.log
# to change depending on the environment.
#
*.tfvars
!terraform.*example*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
args:
- "--args=--only=terraform_deprecated_interpolation"
- "--args=--only=terraform_deprecated_index"
# - "--args=--only=terraform_unused_declarations"
- "--args=--only=terraform_unused_declarations"
- "--args=--only=terraform_comment_syntax"
- "--args=--only=terraform_documented_outputs"
- "--args=--only=terraform_documented_variables"
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Change Log

All notable changes to this module will be documented in this file.

## [1.1.0] - 2022-07-22

### Changed

- Remove upload code from s3
- S3 source code is used for versioning
- Change `additional_lambda_role_policy_arn` to map from list

### Added

- Enable Tracing

## [v1.0.2] - 2022-07-01

### Added

- Add default log retention 90 days, KMS encryption support

### Fixed

- Fix kms security issue by @xshot9011 in #9

## [v1.0.1] - 2022-06-08

### Added

- Add resource base policy for lambda

## [v1.0.0] - 2022-05-17

### Added

- Since Lambdas are uploaded via zip files, we generate a zip file from the path specified.
- Upload the zip file containing the build artifacts to S3.
- Allow access to this lambda function from AWS.
- Allow lambda to generate logs.
- Construct a role that AWS services can adopt in order to invoke our function.
- This policy also has the capability to write logs to CloudWatch.
- Create the secret SSM parameters that can be retrieved and decoded by the lambda function.
- Create an IAM policy document granting the ability to read and retrieve SSM parameter values.
- Develop a policy based on the SSM policy paper
- Custom policies to attach to this role
140 changes: 39 additions & 101 deletions README.md

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

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

## Providers

No providers.

## Modules

| Name | Source | Version |
|--------------------------------------------------------|--------|---------|
| <a name="module_lambda"></a> [lambda](#module\_lambda) | ../../ | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|-----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|------------|---------|:--------:|
| <a name="input_custom_tags"></a> [custom\_tags](#input\_custom\_tags) | Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys | `map(any)` | `{}` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment Variable used as a prefix | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Name of the ECS cluster and s3 also redis to create | `string` | n/a | yes |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix name of customer to be displayed in AWS console and resource | `string` | n/a | yes |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
76 changes: 76 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module "lambda" {
source = "../../"

prefix = var.prefix
environment = var.environment
name = var.name

is_edge = false # Defautl is `false`, If you want to publish to the edge don't forget to override aws's provider to virgina

# If is_edge is `false`, ignore this config
is_create_lambda_bucket = true # Default is `false`; plz use false, if not 1 lambda: 1 bucket
bucket_name = "" # If `is_create_lambda_bucket` is `false`; specified this, default is `""`

# Source code
source_code_dir = "./src"
file_globs = ["index.js"]
compressed_local_file_dir = "./outputs"

# Lambda Env
runtime = "nodejs12.x"
handler = "index.handler"

# Lambda Specification
timeout = 3
memory_size = 128
reserved_concurrent_executions = -1

# Optional to connect Lambda to VPC
vpc_config = {
security_group_ids = ["sg-028f637312eea735e"]
subnet_ids_to_associate = ["subnet-0b853f8c85796d72d", "subnet-07c068b4b51262793", "subnet-0362f68c559ef7716"]
}
dead_letter_target_arn = "arn:aws:sns:ap-southeast-1:557291035693:demo" # To send failed processing to target, Default is `""`

# IAM
is_create_lambda_role = true # Default is `true`
lambda_role_arn = "" # If `is_create_lambda_role` is `false`
# The policies that you want to attach to IAM Role created by only this module # If `is_create_lambda_role` is `false`
additional_lambda_role_policy_arns = {
allow_lambda_to_read_s3 = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}

# Resource policy
lambda_permission_configurations = {
lambda_on_my_account = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035112:lk36vflbha/*/*/"
}
lambda_on_my_another_account_wrong = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:224563527112:q6pwa6wgr6/*/*/"
source_account = "557291035112"
}
lambda_on_my_another_account_correct = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035112:wpj4t3scmb/*/*/"
}
}

# Logging
is_create_cloudwatch_log_group = true # Default is `true`
cloudwatch_log_retention_in_days = 90 # Default is `90`

# Env
ssm_params = {}
plaintext_params = {
region = "ap-southeast-1"
cluster_name = "oozou-dev-test-schedule-cluster"
nodegroup_name = "oozou-dev-test-schedule-custom-nodegroup"
min = 1,
max = 1,
desired = 1
}

tags = var.custom_tags
}
Empty file added examples/complete/outputs.tf
Empty file.
18 changes: 18 additions & 0 deletions examples/complete/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var http = require('http')

exports.handler = (event, context, callback) => {
const options = {
hostname: event.Host,
port: event.Port
}

const response = {};

http.get(options, (res) => {
response.httpStatus = res.statusCode
callback(null, response)
}).on('error', (err) => {
callback(null, err.message);
})

};
6 changes: 6 additions & 0 deletions examples/complete/terraform.example.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prefix = "example"
environment = "devops"
name = "cms"
custom_tags = {
"Remark" = "terraform-aws-lambda-example"
}
23 changes: 23 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* -------------------------------------------------------------------------- */
/* Generics */
/* -------------------------------------------------------------------------- */
variable "prefix" {
description = "The prefix name of customer to be displayed in AWS console and resource"
type = string
}

variable "environment" {
description = "Environment Variable used as a prefix"
type = string
}

variable "name" {
description = "Name of the ECS cluster and s3 also redis to create"
type = string
}

variable "custom_tags" {
description = "Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys"
type = map(any)
default = {}
}
10 changes: 10 additions & 0 deletions examples/complete/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0.0"
}
}
}
35 changes: 35 additions & 0 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

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

## Providers

No providers.

## Modules

| Name | Source | Version |
|--------------------------------------------------------|--------|---------|
| <a name="module_lambda"></a> [lambda](#module\_lambda) | ../../ | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|-----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|------------|---------|:--------:|
| <a name="input_custom_tags"></a> [custom\_tags](#input\_custom\_tags) | Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys | `map(any)` | `{}` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment Variable used as a prefix | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Name of the ECS cluster and s3 also redis to create | `string` | n/a | yes |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix name of customer to be displayed in AWS console and resource | `string` | n/a | yes |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
45 changes: 45 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module "lambda" {
source = "../../"

prefix = var.prefix
environment = var.environment
name = var.name

source_code_dir = "./src"
file_globs = ["index.js"]
compressed_local_file_dir = "./outputs"

runtime = "nodejs12.x"
handler = "index.handler"

additional_lambda_role_policy_arns = {
allow_lambda_to_read_s3 = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
lambda_permission_configurations = {
lambda_on_my_account = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035112:lk36vflbha/*/*/"
}
lambda_on_my_another_account_wrong = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:224563527112:q6pwa6wgr6/*/*/"
source_account = "557291035112"
}
lambda_on_my_another_account_correct = {
pricipal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035112:wpj4t3scmb/*/*/"
}
}

ssm_params = {}
plaintext_params = {
region = "ap-southeast-1"
cluster_name = "oozou-dev-test-schedule-cluster"
nodegroup_name = "oozou-dev-test-schedule-custom-nodegroup"
min = 1,
max = 1,
desired = 1
}

tags = var.custom_tags
}
Empty file added examples/simple/outputs.tf
Empty file.
18 changes: 18 additions & 0 deletions examples/simple/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var http = require('http')

exports.handler = (event, context, callback) => {
const options = {
hostname: event.Host,
port: event.Port
}

const response = {};

http.get(options, (res) => {
response.httpStatus = res.statusCode
callback(null, response)
}).on('error', (err) => {
callback(null, err.message);
})

};
6 changes: 6 additions & 0 deletions examples/simple/terraform.example.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prefix = "example"
environment = "devops"
name = "cms"
custom_tags = {
"Remark" = "terraform-aws-lambda-example"
}
23 changes: 23 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* -------------------------------------------------------------------------- */
/* Generics */
/* -------------------------------------------------------------------------- */
variable "prefix" {
description = "The prefix name of customer to be displayed in AWS console and resource"
type = string
}

variable "environment" {
description = "Environment Variable used as a prefix"
type = string
}

variable "name" {
description = "Name of the ECS cluster and s3 also redis to create"
type = string
}

variable "custom_tags" {
description = "Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys"
type = map(any)
default = {}
}
10 changes: 10 additions & 0 deletions examples/simple/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0.0"
}
}
}
Loading