Skip to content

Commit 98dff8c

Browse files
damacusnozaq
andauthored
Adds exclude_files option to archive (#8)
* Adds exclude_files option to archive The undocumented excludes option to acrhive file is extremely helpful when you have test code included in the same directory as the lambda hashicorp/terraform-provider-archive#55 * Fix default values for archive ignore Co-authored-by: nozaq <[email protected]>
1 parent f347c98 commit 98dff8c

File tree

3 files changed

+66
-30
lines changed

3 files changed

+66
-30
lines changed

README.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,51 @@ module "lambda" {
4646
Check [examples](./examples) for non-python examples.
4747

4848
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
49+
## Requirements
50+
51+
No requirements.
52+
53+
## Providers
54+
55+
| Name | Version |
56+
| ------- | ------- |
57+
| archive | n/a |
58+
| aws | n/a |
59+
| null | n/a |
60+
4961
## Inputs
5062

51-
| Name | Description | Type | Default | Required |
52-
|------|-------------|:----:|:-----:|:-----:|
53-
| 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 |
54-
| 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 |
55-
| dead\_letter\_config | Nested block to configure the function's dead letter queue. | object | `"null"` | no |
56-
| description | Description of what your Lambda Function does. | string | `""` | no |
57-
| environment | A map that defines environment variables for the Lambda function. | object | `"null"` | no |
58-
| function\_name | A unique name for your Lambda Function. | string | n/a | yes |
59-
| handler | The function entrypoint in your code. | string | n/a | yes |
60-
| iam\_role\_name\_prefix | The prefix string for the name of IAM role for the lambda function. | string | `""` | no |
61-
| kms\_key\_arn | The ARN for the KMS encryption key. | string | `"null"` | no |
62-
| kms\_key\_id | The ARN of the KMS Key to use when encrypting log data. | string | `"null"` | no |
63-
| layers | List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. | list | `[]` | no |
64-
| memory\_size | Amount of memory in MB your Lambda Function can use at runtime. | string | `"128"` | no |
65-
| output\_path | A path to which the source directory is archived before uploading to AWS. | string | n/a | yes |
66-
| policy\_arns | A list of IAM policy ARNs attached to the lambda function. | list | `[]` | no |
67-
| publish | Whether to publish creation/change as new Lambda Function Version. | string | `"false"` | no |
68-
| 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 |
69-
| retention\_in\_days | Specifies the number of days you want to retain log events in the specified log group. | number | `"null"` | no |
70-
| runtime | The identifier of the function's runtime. | string | n/a | yes |
71-
| source\_dir | A path to the directory which contains source files. | string | n/a | yes |
72-
| tags | A mapping of tags to assign to resources. | map | `{ "Terraform": "true" }` | no |
73-
| timeout | The maximum number of seconds the lambda function to run until timeout. | string | `"3"` | no |
74-
| 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. | object | `"null"` | no |
75-
| vpc\_config | Provide this to allow your function to access your VPC. | string | `"null"` | no |
63+
| Name | Description | Type | Default | Required |
64+
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------ | :------: |
65+
| 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 |
66+
| 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(string)` | `[]` | no |
67+
| dead\_letter\_config | Nested block to configure the function's dead letter queue. | <pre>object({<br> target_arn = string<br> })</pre> | `null` | no |
68+
| description | Description of what your Lambda Function does. | `string` | `""` | no |
69+
| environment | A map that defines environment variables for the Lambda function. | <pre>object({<br> variables = map(string)<br> })</pre> | `null` | no |
70+
| exclude\_files | A list of directories or folders to ignore, e.g.<br>exclude\_files = ["test", "src/\*\*/\*.ts"] | `list(string)` | n/a | yes |
71+
| function\_name | A unique name for your Lambda Function. | `string` | n/a | yes |
72+
| handler | The function entrypoint in your code. | `string` | n/a | yes |
73+
| iam\_role\_name\_prefix | The prefix string for the name of IAM role for the lambda function. | `string` | `""` | no |
74+
| kms\_key\_arn | The ARN for the KMS encryption key. | `string` | `null` | no |
75+
| kms\_key\_id | The ARN of the KMS Key to use when encrypting log data. | `string` | `null` | no |
76+
| layers | List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. | `list(string)` | `[]` | no |
77+
| memory\_size | Amount of memory in MB your Lambda Function can use at runtime. | `number` | `128` | no |
78+
| output\_path | A path to which the source directory is archived before uploading to AWS. | `string` | n/a | yes |
79+
| policy\_arns | A list of IAM policy ARNs attached to the lambda function. | `list(string)` | `[]` | no |
80+
| publish | Whether to publish creation/change as new Lambda Function Version. | `string` | `false` | no |
81+
| 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 |
82+
| retention\_in\_days | Specifies the number of days you want to retain log events in the specified log group. | `number` | `null` | no |
83+
| runtime | The identifier of the function's runtime. | `string` | n/a | yes |
84+
| source\_dir | A path to the directory which contains source files. | `string` | n/a | yes |
85+
| tags | A mapping of tags to assign to resources. | `map` | <pre>{<br> "Terraform": "true"<br>}</pre> | no |
86+
| timeout | The maximum number of seconds the lambda function to run until timeout. | `number` | `3` | no |
87+
| 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 |
88+
| vpc\_config | Provide this to allow your function to access your VPC. | `any` | `null` | no |
7689

7790
## Outputs
7891

79-
| Name | Description |
80-
|------|-------------|
81-
| iam\_role | The IAM Role which the lambda function is attached. |
82-
| lambda\_function | The lambda function. |
83-
92+
| Name | Description |
93+
| ---------------- | --------------------------------------------------- |
94+
| iam\_role | The IAM Role which the lambda function is attached. |
95+
| lambda\_function | The lambda function. |
8496
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

build.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ data "null_data_source" "build_dep" {
2424
data "archive_file" "source" {
2525
type = "zip"
2626
source_dir = data.null_data_source.build_dep.outputs.source_dir
27+
excludes = var.exclude_files
2728
output_path = var.output_path
2829
}

variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ variable "tags" {
1313
#---------------------------------------------------------------------------------------------------
1414
variable "build_command" {
1515
description = "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."
16+
type = string
1617
default = ""
1718
}
1819

@@ -23,22 +24,35 @@ variable "build_triggers" {
2324

2425
variable "source_dir" {
2526
description = "A path to the directory which contains source files."
27+
type = string
2628
}
2729

2830
variable "output_path" {
2931
description = "A path to which the source directory is archived before uploading to AWS."
32+
type = string
33+
}
34+
35+
variable "exclude_files" {
36+
description = <<DESC
37+
A list of directories or folders to ignore, e.g.
38+
exclude_files = ["test", "src/**/*.ts"]
39+
DESC
40+
type = list(string)
41+
default = []
3042
}
3143

3244
#---------------------------------------------------------------------------------------------------
3345
# IAM Role arguments
3446
#---------------------------------------------------------------------------------------------------
3547
variable "iam_role_name_prefix" {
3648
description = "The prefix string for the name of IAM role for the lambda function."
49+
type = string
3750
default = ""
3851
}
3952

4053
variable "policy_arns" {
4154
description = "A list of IAM policy ARNs attached to the lambda function."
55+
type = list(string)
4256
default = []
4357
}
4458

@@ -62,22 +76,27 @@ variable "kms_key_id" {
6276
#---------------------------------------------------------------------------------------------------
6377
variable "function_name" {
6478
description = "A unique name for your Lambda Function."
79+
type = string
6580
}
6681

6782
variable "runtime" {
83+
type = string
6884
description = "The identifier of the function's runtime."
6985
}
7086

7187
variable "handler" {
88+
type = string
7289
description = "The function entrypoint in your code."
7390
}
7491

7592
variable "memory_size" {
93+
type = number
7694
description = "Amount of memory in MB your Lambda Function can use at runtime."
7795
default = 128
7896
}
7997

8098
variable "timeout" {
99+
type = number
81100
description = "The maximum number of seconds the lambda function to run until timeout."
82101
default = 3
83102
}
@@ -99,22 +118,26 @@ variable "dead_letter_config" {
99118
}
100119

101120
variable "description" {
121+
type = string
102122
description = "Description of what your Lambda Function does."
103123
default = ""
104124
}
105125

106126
variable "layers" {
107127
description = "List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function."
128+
type = list(string)
108129
default = []
109130
}
110131

111132
variable "reserved_concurrent_executions" {
112133
description = "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."
134+
type = string
113135
default = -1
114136
}
115137

116138
variable "publish" {
117139
description = "Whether to publish creation/change as new Lambda Function Version."
140+
type = string
118141
default = false
119142
}
120143

0 commit comments

Comments
 (0)