Skip to content

Commit 8017f04

Browse files
authored
chore: support layer (#18)
* chore: test new provider version * feat: add suppoty lambda layers * chore: add example * fix: precommit * fix: precommit * fix: add default kms (#19) * chore: version constrain for archive * chore: update tagging style * chore: update Doc
1 parent 98ee1fc commit 8017f04

16 files changed

+340
-92
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

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

5+
## [v1.2.0] - 2023-09-12
6+
7+
### Added
8+
9+
- Data general source `data.aws_caller_identity.this`, `data.aws_region.this`
10+
- Encryption to cloudwatch log group (external kms, built-in kms)
11+
- Data `data.aws_iam_policy_document.cloudwatch_log_group_kms_policy`
12+
- Module `module.cloudwatch_log_group_kms (v1.0.0)`
13+
- Variable `var.is_create_default_kms`, `var.cloudwatch_log_group_kms_key_arn`
14+
- Add support lambda layer
15+
- Variable `var.layer_arns`
16+
17+
### Changed
18+
19+
- Constrain version for archive provider to `>= 2.0.0` from `2.2.0`
20+
- Add default tagging with module name
21+
522
## [v1.1.4] - 2022-12-15
623

724
### Added

README.md

Lines changed: 72 additions & 66 deletions
Large diffs are not rendered by default.

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Your can also report the vulnerabilities by emailing to Oozou DevOps team at:
2020
2121
```
2222

23-
We will acknowledge your email within 72 hours on workday, and will send a more details response within 5 days. After the initial email start, we will investigate the security issue snd fix it as soon as possible.
23+
We will acknowledge your email within 72 hours on workday, and will send a more details response within 5 days. After the initial email start, we will investigate the security issue snd fix it as soon as possible.

examples/access_key_rotate/main.tf

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
name = format("%s-%s-%s", "oozou", "test", "app")
2+
name = format("%s-%s-%s", "oozou", "test", "app")
33
}
44

55
data "aws_caller_identity" "this" {}
@@ -31,7 +31,7 @@ module "sns" {
3131

3232
prefix = "oozou"
3333
environment = "test"
34-
name = format("%s-accesskey-rotate", "app")
34+
name = format("%s-accesskey-rotate", "app")
3535
display_name = "Alerting Center"
3636

3737
sns_permission_configuration = {
@@ -71,14 +71,14 @@ resource "aws_iam_policy" "sns_publish_policy" {
7171
Action = [
7272
"sns:Publish",
7373
]
74-
Effect = "Allow"
75-
"Resource": module.sns.sns_topic_arn
74+
Effect = "Allow"
75+
"Resource" : module.sns.sns_topic_arn
7676
},
7777
]
7878
})
7979
}
8080

81-
resource "aws_iam_policy" "iam_updateKey_policy" {
81+
resource "aws_iam_policy" "iam_updatekey_policy" {
8282
name = format("%s-iam-updatekey-access", local.name)
8383
path = "/"
8484

@@ -92,8 +92,8 @@ resource "aws_iam_policy" "iam_updateKey_policy" {
9292
"iam:ListAccessKeys",
9393
"iam:DeleteAccessKey",
9494
]
95-
Effect = "Allow"
96-
"Resource": aws_iam_user.s3_presigned_user.arn
95+
Effect = "Allow"
96+
"Resource" : aws_iam_user.s3_presigned_user.arn
9797
},
9898
]
9999
})
@@ -108,11 +108,11 @@ resource "aws_iam_policy" "secretsmanager_updatesecret_policy" {
108108
Statement = [
109109
{
110110
Action = [
111-
"secretsmanager:GetSecretValue",
112-
"secretsmanager:PutSecretValue"
111+
"secretsmanager:GetSecretValue",
112+
"secretsmanager:PutSecretValue"
113113
]
114-
Effect = "Allow"
115-
"Resource": aws_secretsmanager_secret.accesskey.arn
114+
Effect = "Allow"
115+
"Resource" : aws_secretsmanager_secret.accesskey.arn
116116
},
117117
]
118118
})
@@ -136,22 +136,22 @@ module "lambda_accesskey_rotate" {
136136
runtime = "python3.9"
137137
handler = "access_key_rotate.handler"
138138
environment_variables = {
139-
iam_username = aws_iam_user.s3_presigned_user.name
140-
secret_name = aws_secretsmanager_secret.accesskey.name
141-
sns_topic_arn = module.sns.sns_topic_arn
139+
iam_username = aws_iam_user.s3_presigned_user.name
140+
secret_name = aws_secretsmanager_secret.accesskey.name
141+
sns_topic_arn = module.sns.sns_topic_arn
142142
}
143143

144144
# IAM
145145
additional_lambda_role_policy_arns = [
146146
aws_iam_policy.sns_publish_policy.arn,
147147
aws_iam_policy.secretsmanager_updatesecret_policy.arn,
148-
aws_iam_policy.iam_updateKey_policy.arn
148+
aws_iam_policy.iam_updatekey_policy.arn
149149
]
150150

151151
# Resource policy
152152
lambda_permission_configurations = {
153153
allow_trigger_from_eventbridge = {
154-
principal = "secretsmanager.amazonaws.com"
154+
principal = "secretsmanager.amazonaws.com"
155155
}
156156
}
157157

@@ -183,16 +183,16 @@ module "secret_kms_key" {
183183
}
184184

185185
resource "aws_secretsmanager_secret" "accesskey" {
186-
name = format("%s/accesskey", local.name)
187-
description = "access key secret with rotation"
188-
kms_key_id = module.secret_kms_key.key_arn
186+
name = format("%s/accesskey", local.name)
187+
description = "access key secret with rotation"
188+
kms_key_id = module.secret_kms_key.key_arn
189189
recovery_window_in_days = 0
190190

191191
}
192192

193193
resource "aws_secretsmanager_secret_rotation" "accesskey" {
194194
secret_id = aws_secretsmanager_secret.accesskey.id
195-
rotation_lambda_arn = module.lambda_accesskey_rotate.function_arn
195+
rotation_lambda_arn = module.lambda_accesskey_rotate.function_arn
196196
rotation_rules {
197197
automatically_after_days = 7
198198
}
@@ -212,4 +212,3 @@ resource "aws_iam_user" "s3_presigned_user" {
212212

213213
tags = merge({}, { "Name" = "s3_presigned_user" })
214214
}
215-

examples/lambda_layer/.editorconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
# Uses editorconfig to maintain consistent coding styles
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
insert_final_newline = true
12+
max_line_length = 80
13+
trim_trailing_whitespace = true
14+
15+
[*.{tf,tfvars}]
16+
indent_size = 2
17+
indent_style = space
18+
19+
[*.{py}]
20+
indent_size = 4
21+
indent_style = space
22+
23+
[*.md]
24+
max_line_length = 0
25+
trim_trailing_whitespace = false
26+
27+
# Tab indentation (no size specified)
28+
[Makefile]
29+
tab_width = 2
30+
indent_style = tab
31+
32+
[COMMIT_EDITMSG]
33+
max_line_length = 0

examples/lambda_layer/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Requirements
3+
4+
| Name | Version |
5+
|---------------------------------------------------------------------------|----------|
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 |
8+
9+
## Providers
10+
11+
No providers.
12+
13+
## Modules
14+
15+
| Name | Source | Version |
16+
|--------------------------------------------------------|--------|---------|
17+
| <a name="module_lambda"></a> [lambda](#module\_lambda) | ../../ | n/a |
18+
19+
## Resources
20+
21+
No resources.
22+
23+
## Inputs
24+
25+
| Name | Description | Type | Default | Required |
26+
|-----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|------------|---------|:--------:|
27+
| <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 |
28+
| <a name="input_environment"></a> [environment](#input\_environment) | Environment Variable used as a prefix | `string` | n/a | yes |
29+
| <a name="input_name"></a> [name](#input\_name) | Name of the ECS cluster and s3 also redis to create | `string` | n/a | yes |
30+
| <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 |
31+
32+
## Outputs
33+
34+
No outputs.
35+
<!-- END_TF_DOCS -->

examples/lambda_layer/main.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
locals {
2+
name = format("%s-%s-%s", var.prefix, var.environment, var.name)
3+
}
4+
5+
resource "aws_lambda_layer_version" "lambda_layer" {
6+
filename = "./src/requests.zip"
7+
layer_name = format("%s-requests-layer", local.name)
8+
9+
compatible_runtimes = ["python3.8"]
10+
}
11+
12+
module "lambda" {
13+
source = "../../"
14+
15+
prefix = var.prefix
16+
environment = var.environment
17+
name = var.name
18+
19+
# Source code
20+
source_code_dir = "./src"
21+
file_globs = ["main.py"]
22+
compressed_local_file_dir = "./outputs"
23+
24+
# Lambda Env
25+
runtime = "python3.8"
26+
handler = "main.lambda_handler"
27+
28+
# Lambda Specification
29+
timeout = 3
30+
memory_size = 128
31+
reserved_concurrent_executions = -1
32+
layer_arns = [aws_lambda_layer_version.lambda_layer.arn]
33+
additional_lambda_role_policy_arns = ["arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"]
34+
35+
# Resource policy
36+
lambda_permission_configurations = {
37+
# lambda_on_my_account = {
38+
# principal = "apigateway.amazonaws.com"
39+
# source_arn = "arn:aws:execute-api:ap-southeast-1:557291035112:lk36vflbha/*/*/"
40+
# }
41+
}
42+
43+
tags = var.custom_tags
44+
}

examples/lambda_layer/outputs.tf

Whitespace-only changes.

examples/lambda_layer/src/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
import io
3+
import sys
4+
import csv
5+
import requests
6+
7+
8+
def lambda_handler(event, context):
9+
response = requests.get("https://www.google.com")
10+
return response.json()
877 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prefix = "example"
2+
environment = "devops"
3+
name = "cms"
4+
custom_tags = {
5+
"Remark" = "terraform-aws-lambda-example"
6+
}

examples/lambda_layer/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* -------------------------------------------------------------------------- */
2+
/* Generics */
3+
/* -------------------------------------------------------------------------- */
4+
variable "prefix" {
5+
description = "The prefix name of customer to be displayed in AWS console and resource"
6+
type = string
7+
}
8+
9+
variable "environment" {
10+
description = "Environment Variable used as a prefix"
11+
type = string
12+
}
13+
14+
variable "name" {
15+
description = "Name of the ECS cluster and s3 also redis to create"
16+
type = string
17+
}
18+
19+
variable "custom_tags" {
20+
description = "Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys"
21+
type = map(any)
22+
default = {}
23+
}

examples/lambda_layer/version.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.0.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)