Skip to content

Commit 1df2a29

Browse files
authored
rebuilding lambda package (#3)
* rebuilding lambda package * updating readme * updating precommit * updating terraform code based on pre-commit findings
1 parent 6f76f59 commit 1df2a29

13 files changed

+222
-132
lines changed

Diff for: .github/workflows/main.yml

-93
This file was deleted.

Diff for: .github/workflows/pre-commit.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: pre-commit
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
- master
9+
10+
env:
11+
PYTHON_VERSION: "3.10"
12+
TERRAFORM_DOCS_VERSION: "v0.16.0"
13+
TFLINT_VERSION: "v0.46.1"
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
pre-commit:
20+
runs-on: ubuntu-22.04
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Install terraform-docs
26+
uses: jaxxstorm/[email protected]
27+
with:
28+
repo: terraform-docs/terraform-docs
29+
tag: ${{ env.TERRAFORM_DOCS_VERSION }}
30+
cache: enable
31+
32+
- name: TFLint cache
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.tflint.d/plugins
36+
key: ${{ runner.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
37+
38+
- name: Install TFLint
39+
uses: terraform-linters/setup-tflint@v2
40+
with:
41+
tflint_version: ${{ env.TFLINT_VERSION }}
42+
43+
- name: Run pre-commit
44+
uses: pre-commit/[email protected]

Diff for: .github/workflows/validate.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Terraform validate
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
- master
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
versionExtract:
15+
name: Extract min/max Terraform versions
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Extract Terraform min/max versions
23+
id: minMax
24+
uses: clowdhaus/terraform-min-max@main
25+
with:
26+
directory: .
27+
outputs:
28+
minVersion: ${{ steps.minMax.outputs.minVersion }}
29+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
30+
31+
terraform-validate:
32+
runs-on: ubuntu-22.04
33+
needs: versionExtract
34+
strategy:
35+
matrix:
36+
tf_ver:
37+
- ${{ needs.versionExtract.outputs.minVersion }}
38+
- ${{ needs.versionExtract.outputs.maxVersion }}
39+
40+
steps:
41+
- uses: actions/checkout@v3
42+
- uses: hashicorp/setup-terraform@v2
43+
with:
44+
terraform_version: ${{ matrix.tf_ver }}
45+
46+
- name: Terraform Init
47+
id: init
48+
run: terraform init
49+
50+
- name: Terraform Validate
51+
id: validate
52+
run: terraform validate

Diff for: .gitignore

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
main
2-
.terraform
1+
### Terraform ###
2+
# Local .terraform directories
3+
**/.terraform/*
4+
.terraform.lock.hcl
5+
6+
.env
7+
8+
# JetBrains
9+
.idea

Diff for: .pre-commit-config.yaml

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.1.0
3+
rev: v4.4.0
44
hooks:
55
- id: trailing-whitespace
66
- id: check-merge-conflict
@@ -9,30 +9,20 @@ repos:
99
- id: detect-private-key
1010
- id: end-of-file-fixer
1111

12-
- repo: https://github.com/gruntwork-io/pre-commit
13-
rev: v0.1.9
14-
hooks:
15-
- id: tflint
16-
- id: terraform-validate
17-
- id: tflint
18-
- id: shellcheck
19-
- id: gofmt
20-
21-
- repo: git://github.com/antonbabenko/pre-commit-terraform
22-
rev: v1.31.0
12+
- repo: https://github.com/antonbabenko/pre-commit-terraform
13+
rev: v1.86.0
2314
hooks:
2415
- id: terraform_fmt
16+
- id: terraform_tflint
17+
- id: terraform_validate
18+
# - id: terraform_checkov
2519
- id: terraform_docs
2620
args:
27-
- '--args=--no-providers --sort-by-required'
28-
29-
- repo: git://github.com/pecigonzalo/pre-commit-terraform-vars
30-
rev: 8e947e99c45314397a8caacebefab44d74227b6b
31-
hooks:
32-
- id: terraform-vars
21+
- '--args=--config=.terraform-docs.yml'
3322

3423
- repo: https://github.com/Yelp/detect-secrets
35-
rev: v0.13.1
24+
rev: v1.4.0
3625
hooks:
3726
- id: detect-secrets
3827
args: ['--baseline', '.secrets.baseline']
28+
exclude: terraform.tfstate

Diff for: .terraform-docs.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
formatter: markdown table
2+
3+
output:
4+
mode: inject
5+
template: |-
6+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7+
{{ .Content }}
8+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9+
10+
sections:
11+
hide:
12+
- providers
13+
sort:
14+
by: required

Diff for: .tflint.hcl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugin "terraform" {
2+
enabled = true
3+
version = "0.1.1"
4+
source = "github.com/terraform-linters/tflint-ruleset-terraform"
5+
preset = "recommended"
6+
}
7+
8+
plugin "aws" {
9+
enabled = true
10+
version = "0.32.0"
11+
source = "github.com/terraform-linters/tflint-ruleset-aws"
12+
}

Diff for: .tool-versions

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
golang 1.21.0
2+
terraform-docs 0.16.0
3+
tflint 0.46.1

Diff for: README.md

+46-11
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,46 @@ A terraform module to deploy a CloudWatch report lambda function and to provide
1616
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1717
## Requirements
1818

19-
No requirements.
19+
| Name | Version |
20+
|------|---------|
21+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
22+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
23+
24+
## Modules
25+
26+
No modules.
27+
28+
## Resources
29+
30+
| Name | Type |
31+
|------|------|
32+
| [aws_cloudwatch_event_rule.trigger](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
33+
| [aws_cloudwatch_event_target.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
34+
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
35+
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
36+
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
37+
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
38+
| [aws_lambda_function.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
39+
| [aws_lambda_permission.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
40+
| [aws_ses_email_identity.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_email_identity) | resource |
41+
| [aws_ses_email_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_email_identity) | resource |
2042

2143
## Inputs
2244

2345
| Name | Description | Type | Default | Required |
2446
|------|-------------|------|---------|:--------:|
25-
| cw\_metric\_dimension | n/a | `any` | n/a | yes |
26-
| cw\_metric\_name | n/a | `any` | n/a | yes |
27-
| cw\_metric\_namespace | n/a | `any` | n/a | yes |
28-
| email\_source\_address | n/a | `any` | n/a | yes |
29-
| email\_target\_address | n/a | `any` | n/a | yes |
30-
| name | n/a | `any` | n/a | yes |
31-
| region | n/a | `any` | n/a | yes |
32-
| lambda\_schedule | n/a | `string` | `"cron(0 0 * * ? *)"` | no |
47+
| <a name="input_cw_metric_dimension"></a> [cw\_metric\_dimension](#input\_cw\_metric\_dimension) | CloudWatch metric dimension | `string` | n/a | yes |
48+
| <a name="input_cw_metric_name"></a> [cw\_metric\_name](#input\_cw\_metric\_name) | CloudWatch metric name | `string` | n/a | yes |
49+
| <a name="input_cw_metric_namespace"></a> [cw\_metric\_namespace](#input\_cw\_metric\_namespace) | CloudWatch metric namespace | `string` | n/a | yes |
50+
| <a name="input_email_source_address"></a> [email\_source\_address](#input\_email\_source\_address) | n/a | `string` | n/a | yes |
51+
| <a name="input_email_target_address"></a> [email\_target\_address](#input\_email\_target\_address) | n/a | `string` | n/a | yes |
52+
| <a name="input_name"></a> [name](#input\_name) | n/a | `string` | n/a | yes |
53+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | n/a | yes |
54+
| <a name="input_lambda_schedule"></a> [lambda\_schedule](#input\_lambda\_schedule) | n/a | `string` | `"cron(0 0 * * ? *)"` | no |
3355

3456
## Outputs
3557

36-
No output.
37-
58+
No outputs.
3859
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3960

4061
## Contributing and reporting issues
@@ -52,6 +73,20 @@ check your code before you will create pull-requests. See
5273
[GitHub Actions documentation](https://docs.github.com/en/actions) for further
5374
details.
5475

76+
### Building lambda package
77+
78+
- use `asdf` to install necessary go version
79+
- compile go code
80+
- zip compiled code and push to the repository
81+
82+
```bash
83+
asdf install
84+
85+
GOARCH=amd64 GOOS=linux go build -o bootstrap main.go
86+
87+
zip lambda.zip bootstrap
88+
89+
```
5590

5691
## License
5792

Diff for: bootstrap

16.8 MB
Binary file not shown.

Diff for: lambda.zip

1.03 KB
Binary file not shown.

Diff for: variables.tf

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
variable "lambda_schedule" {
2+
type = string
23
default = "cron(0 0 * * ? *)"
34
}
4-
variable "region" {}
5-
variable "cw_metric_name" {}
6-
variable "cw_metric_namespace" {}
7-
variable "cw_metric_dimension" {}
8-
variable "name" {}
9-
variable "email_source_address" {}
10-
variable "email_target_address" {}
5+
6+
variable "region" {
7+
type = string
8+
}
9+
variable "cw_metric_name" {
10+
type = string
11+
description = "CloudWatch metric name"
12+
}
13+
variable "cw_metric_namespace" {
14+
type = string
15+
description = "CloudWatch metric namespace"
16+
}
17+
variable "cw_metric_dimension" {
18+
type = string
19+
description = "CloudWatch metric dimension"
20+
}
21+
variable "name" {
22+
type = string
23+
}
24+
variable "email_source_address" {
25+
type = string
26+
}
27+
variable "email_target_address" {
28+
type = string
29+
}

0 commit comments

Comments
 (0)