Skip to content

Commit 83487a6

Browse files
authored
refactor: add tflint checks (#15)
* refactor: add tflint checks * style: apply consistent comment style
1 parent 699c9de commit 83487a6

File tree

11 files changed

+165
-68
lines changed

11 files changed

+165
-68
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ on:
77
env:
88
TF_ACTIONS_VERSION: latest
99
jobs:
10-
check-format:
11-
name: Check format
10+
pre-commit-checks:
11+
name: Pre-commit checks
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: hashicorp/setup-terraform@v1
1514
- name: Checkout
1615
uses: actions/checkout@v2
17-
- name: "Terraform Format"
18-
run: terraform fmt -check -recursive
19-
16+
- name: Terraform min/max versions
17+
id: minMax
18+
uses: clowdhaus/[email protected]
19+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
20+
uses: clowdhaus/terraform-composite-actions/[email protected]
21+
with:
22+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
23+
terraform-docs-version: v0.16.0
2024
validate-examples:
2125
name: Validate examples
2226
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.51.0
3+
rev: v1.62.3
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
7+
args:
8+
- --args=--config=.terraform-docs.yml
9+
- id: terraform_tflint
10+
exclude: "test/"
11+
args:
12+
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl

.terraform-docs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
formatter: "markdown table"
2+
3+
sections:
4+
show:
5+
- requirements
6+
- providers
7+
- inputs
8+
- outputs
9+
10+
sort:
11+
enabled: true
12+
by: name
13+
14+
settings:
15+
default: false
16+
lockfile: false

.tflint.hcl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
config {
2+
module = false
3+
force = false
4+
disabled_by_default = false
5+
}
6+
7+
rule "terraform_deprecated_interpolation" {
8+
enabled = true
9+
}
10+
11+
rule "terraform_deprecated_index" {
12+
enabled = true
13+
}
14+
15+
rule "terraform_unused_declarations" {
16+
enabled = true
17+
}
18+
19+
rule "terraform_comment_syntax" {
20+
enabled = true
21+
}
22+
23+
rule "terraform_documented_outputs" {
24+
enabled = true
25+
}
26+
27+
rule "terraform_documented_variables" {
28+
enabled = true
29+
}
30+
31+
rule "terraform_typed_variables" {
32+
enabled = true
33+
}
34+
35+
rule "terraform_module_pinned_source" {
36+
enabled = true
37+
}
38+
39+
rule "terraform_required_version" {
40+
enabled = true
41+
}
42+
43+
rule "terraform_required_providers" {
44+
enabled = true
45+
}
46+
47+
rule "terraform_standard_module_structure" {
48+
enabled = true
49+
}
50+
51+
rule "terraform_workspace_remote" {
52+
enabled = true
53+
}

README.md

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,63 +48,49 @@ Check [examples](./examples) for non-python examples.
4848
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4949
## Requirements
5050

51-
No requirements.
51+
| Name | Version |
52+
|------|---------|
53+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15.0 |
54+
| <a name="requirement_archive"></a> [archive](#requirement\_archive) | >= 2.2.0 |
55+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.50.0 |
56+
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.1.0 |
5257

5358
## Providers
5459

5560
| Name | Version |
5661
|------|---------|
57-
| <a name="provider_archive"></a> [archive](#provider\_archive) | n/a |
58-
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
59-
| <a name="provider_null"></a> [null](#provider\_null) | n/a |
60-
61-
## Modules
62-
63-
No modules.
64-
65-
## Resources
66-
67-
| Name | Type |
68-
|------|------|
69-
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
70-
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
71-
| [aws_iam_role_policy_attachment.basic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
72-
| [aws_iam_role_policy_attachment.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
73-
| [aws_iam_role_policy_attachment.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
74-
| [aws_lambda_function.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
75-
| [null_resource.build](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
76-
| [archive_file.source](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
77-
| [aws_iam_policy_document.assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
62+
| <a name="provider_archive"></a> [archive](#provider\_archive) | >= 2.2.0 |
63+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.50.0 |
64+
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.1.0 |
7865

7966
## Inputs
8067

81-
| Name | Description | Type | Default | Required |
82-
|------|-------------|------|---------|:--------:|
83-
| <a name="input_allowed_services"></a> [allowed\_services](#input\_allowed\_services) | A list of AWS Services that are allowed to access this lambda. | `list(string)` | <pre>[<br> "lambda.amazonaws.com"<br>]</pre> | no |
84-
| <a name="input_build_command"></a> [build\_command](#input\_build\_command) | This is the build command to execute. It can be provided as a relative path to the current working directory or as an absolute path. It is evaluated in a shell, and can use environment variables or Terraform variables. | `string` | `""` | no |
85-
| <a name="input_build_triggers"></a> [build\_triggers](#input\_build\_triggers) | A map of values which should cause the build command to re-run. Values are meant to be interpolated references to variables or attributes of other resources. | `list` | `[]` | no |
86-
| <a name="input_dead_letter_config"></a> [dead\_letter\_config](#input\_dead\_letter\_config) | Nested block to configure the function's dead letter queue. | <pre>object({<br> target_arn = string<br> })</pre> | `null` | no |
87-
| <a name="input_description"></a> [description](#input\_description) | Description of what your Lambda Function does. | `string` | `""` | no |
88-
| <a name="input_environment"></a> [environment](#input\_environment) | A map that defines environment variables for the Lambda function. | <pre>object({<br> variables = map(string)<br> })</pre> | `null` | no |
89-
| <a name="input_exclude_files"></a> [exclude\_files](#input\_exclude\_files) | A list of directories or folders to ignore, e.g.<br>exclude\_files = ["test", "src/**/*.ts"] | `list(string)` | `[]` | no |
90-
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | A unique name for your Lambda Function. | `string` | n/a | yes |
91-
| <a name="input_handler"></a> [handler](#input\_handler) | The function entrypoint in your code. | `string` | n/a | yes |
92-
| <a name="input_iam_role_name_prefix"></a> [iam\_role\_name\_prefix](#input\_iam\_role\_name\_prefix) | The prefix string for the name of IAM role for the lambda function. | `string` | `""` | no |
93-
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN for the KMS encryption key. | `string` | `null` | no |
94-
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data. | `string` | `null` | no |
95-
| <a name="input_layers"></a> [layers](#input\_layers) | List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. | `list(string)` | `[]` | no |
96-
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory in MB your Lambda Function can use at runtime. | `number` | `128` | no |
97-
| <a name="input_output_path"></a> [output\_path](#input\_output\_path) | A path to which the source directory is archived before uploading to AWS. | `string` | n/a | yes |
98-
| <a name="input_policy_arns"></a> [policy\_arns](#input\_policy\_arns) | A list of IAM policy ARNs attached to the lambda function. | `list(string)` | `[]` | no |
99-
| <a name="input_publish"></a> [publish](#input\_publish) | Whether to publish creation/change as new Lambda Function Version. | `string` | `false` | no |
100-
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `string` | `-1` | no |
101-
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. | `number` | `null` | no |
102-
| <a name="input_runtime"></a> [runtime](#input\_runtime) | The identifier of the function's runtime. | `string` | n/a | yes |
103-
| <a name="input_source_dir"></a> [source\_dir](#input\_source\_dir) | A path to the directory which contains source files. | `string` | n/a | yes |
104-
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to resources. | `map` | <pre>{<br> "Terraform": "true"<br>}</pre> | no |
105-
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The maximum number of seconds the lambda function to run until timeout. | `number` | `3` | no |
106-
| <a name="input_tracing_config"></a> [tracing\_config](#input\_tracing\_config) | Can be either PassThrough or Active. If PassThrough, Lambda will only trace the request from an upstream service if it contains a tracing header with "sampled=1". If Active, Lambda will respect any tracing header it receives from an upstream service. If no tracing header is received, Lambda will call X-Ray for a tracing decision. | <pre>object({<br> mode = string<br> })</pre> | `null` | no |
107-
| <a name="input_vpc_config"></a> [vpc\_config](#input\_vpc\_config) | Provide this to allow your function to access your VPC. | `any` | `null` | no |
68+
| Name | Description | Type | Required |
69+
|------|-------------|------|:--------:|
70+
| <a name="input_allowed_services"></a> [allowed\_services](#input\_allowed\_services) | A list of AWS Services that are allowed to access this lambda. | `list(string)` | no |
71+
| <a name="input_build_command"></a> [build\_command](#input\_build\_command) | This is the build command to execute. It can be provided as a relative path to the current working directory or as an absolute path. It is evaluated in a shell, and can use environment variables or Terraform variables. | `string` | no |
72+
| <a name="input_build_triggers"></a> [build\_triggers](#input\_build\_triggers) | A map of values which should cause the build command to re-run. Values are meant to be interpolated references to variables or attributes of other resources. | `map(string)` | no |
73+
| <a name="input_dead_letter_config"></a> [dead\_letter\_config](#input\_dead\_letter\_config) | Nested block to configure the function's dead letter queue. | <pre>object({<br> target_arn = string<br> })</pre> | no |
74+
| <a name="input_description"></a> [description](#input\_description) | Description of what your Lambda Function does. | `string` | no |
75+
| <a name="input_environment"></a> [environment](#input\_environment) | A map that defines environment variables for the Lambda function. | <pre>object({<br> variables = map(string)<br> })</pre> | no |
76+
| <a name="input_exclude_files"></a> [exclude\_files](#input\_exclude\_files) | A list of directories or folders to ignore, e.g.<br>exclude\_files = ["test", "src/**/*.ts"] | `list(string)` | no |
77+
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | A unique name for your Lambda Function. | `string` | yes |
78+
| <a name="input_handler"></a> [handler](#input\_handler) | The function entrypoint in your code. | `string` | yes |
79+
| <a name="input_iam_role_name_prefix"></a> [iam\_role\_name\_prefix](#input\_iam\_role\_name\_prefix) | The prefix string for the name of IAM role for the lambda function. | `string` | no |
80+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data. | `string` | no |
81+
| <a name="input_layers"></a> [layers](#input\_layers) | List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. | `list(string)` | no |
82+
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory in MB your Lambda Function can use at runtime. | `number` | no |
83+
| <a name="input_output_path"></a> [output\_path](#input\_output\_path) | A path to which the source directory is archived before uploading to AWS. | `string` | yes |
84+
| <a name="input_policy_arns"></a> [policy\_arns](#input\_policy\_arns) | A list of IAM policy ARNs attached to the lambda function. | `list(string)` | no |
85+
| <a name="input_publish"></a> [publish](#input\_publish) | Whether to publish creation/change as new Lambda Function Version. | `bool` | no |
86+
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `number` | no |
87+
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. | `number` | no |
88+
| <a name="input_runtime"></a> [runtime](#input\_runtime) | The identifier of the function's runtime. | `string` | yes |
89+
| <a name="input_source_dir"></a> [source\_dir](#input\_source\_dir) | A path to the directory which contains source files. | `string` | yes |
90+
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to resources. | `map(string)` | no |
91+
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The maximum number of seconds the lambda function to run until timeout. | `number` | no |
92+
| <a name="input_tracing_config"></a> [tracing\_config](#input\_tracing\_config) | Can be either PassThrough or Active. If PassThrough, Lambda will only trace the request from an upstream service if it contains a tracing header with "sampled=1". If Active, Lambda will respect any tracing header it receives from an upstream service. If no tracing header is received, Lambda will call X-Ray for a tracing decision. | <pre>object({<br> mode = string<br> })</pre> | no |
93+
| <a name="input_vpc_config"></a> [vpc\_config](#input\_vpc\_config) | Provide this to allow your function to access your VPC. | <pre>object({<br> security_group_ids = list(string)<br> subnet_ids = list(string)<br> })</pre> | no |
10894

10995
## Outputs
11096

examples/simple-nodejs/outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

examples/simple-nodejs/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
variable "region" {
22
description = "The AWS region in which global resources are set up."
3+
type = string
34
default = "us-east-1"
45
}
56

examples/simple-py/outputs.tf

Whitespace-only changes.

examples/simple-py/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
variable "region" {
22
description = "The AWS region in which global resources are set up."
3+
type = string
34
default = "us-east-1"
45
}
56

main.tf

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1+
terraform {
2+
required_version = ">= 0.15.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.50.0"
8+
}
9+
null = {
10+
source = "hashicorp/null"
11+
version = ">= 3.1.0"
12+
}
13+
archive = {
14+
source = "hashicorp/archive"
15+
version = ">= 2.2.0"
16+
}
17+
}
18+
}
19+
120
#---------------------------------------------------------------------------------------------------
221
# IAM role for Lambda function
322
#---------------------------------------------------------------------------------------------------
23+
424
resource "aws_iam_role" "this" {
525
name_prefix = var.iam_role_name_prefix
626
assume_role_policy = data.aws_iam_policy_document.assume.json
7-
tags = var.tags
27+
28+
tags = var.tags
829
}
930

1031
data "aws_iam_policy_document" "assume" {
@@ -24,7 +45,8 @@ resource "aws_iam_role_policy_attachment" "basic" {
2445
}
2546

2647
resource "aws_iam_role_policy_attachment" "vpc" {
27-
count = var.vpc_config == null ? 0 : 1
48+
count = var.vpc_config == null ? 0 : 1
49+
2850
role = aws_iam_role.this.name
2951
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
3052
}
@@ -39,6 +61,7 @@ resource "aws_iam_role_policy_attachment" "lambda" {
3961
#---------------------------------------------------------------------------------------------------
4062
# CloudWatch Log group
4163
#---------------------------------------------------------------------------------------------------
64+
4265
resource "aws_cloudwatch_log_group" "this" {
4366
name = "/aws/lambda/${var.function_name}"
4467
retention_in_days = var.retention_in_days

0 commit comments

Comments
 (0)