Skip to content

Commit

Permalink
Adds exclude_files option to archive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
damacus committed Apr 30, 2020
1 parent 7e2dfed commit 780add0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
72 changes: 42 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,51 @@ module "lambda" {
Check [examples](./examples) for non-python examples.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

| Name | Version |
| ------- | ------- |
| archive | n/a |
| aws | n/a |
| null | n/a |

## Inputs

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

## Outputs

| Name | Description |
|------|-------------|
| iam\_role | The IAM Role which the lambda function is attached. |
| lambda\_function | The lambda function. |

| Name | Description |
| ---------------- | --------------------------------------------------- |
| iam\_role | The IAM Role which the lambda function is attached. |
| lambda\_function | The lambda function. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1 change: 1 addition & 0 deletions build.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ data "null_data_source" "build_dep" {
data "archive_file" "source" {
type = "zip"
source_dir = data.null_data_source.build_dep.outputs.source_dir
excludes = var.exclude_files
output_path = var.output_path
}
23 changes: 23 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,46 @@ variable "tags" {
#---------------------------------------------------------------------------------------------------
variable "build_command" {
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."
type = string
default = ""
}

variable "build_triggers" {
description = "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."
type = list(string)
default = []
}

variable "source_dir" {
description = "A path to the directory which contains source files."
type = string
}

variable "output_path" {
description = "A path to which the source directory is archived before uploading to AWS."
type = string
}

variable "exclude_files" {
description = <<DESC
A list of directories or folders to ignore, e.g.
exclude_files = ["test", "src/**/*.ts"]
DESC
type = list(string)
}

#---------------------------------------------------------------------------------------------------
# IAM Role arguments
#---------------------------------------------------------------------------------------------------
variable "iam_role_name_prefix" {
description = "The prefix string for the name of IAM role for the lambda function."
type = string
default = ""
}

variable "policy_arns" {
description = "A list of IAM policy ARNs attached to the lambda function."
type = list(string)
default = []
}

Expand All @@ -62,22 +76,27 @@ variable "kms_key_id" {
#---------------------------------------------------------------------------------------------------
variable "function_name" {
description = "A unique name for your Lambda Function."
type = string
}

variable "runtime" {
type = string
description = "The identifier of the function's runtime."
}

variable "handler" {
type = string
description = "The function entrypoint in your code."
}

variable "memory_size" {
type = number
description = "Amount of memory in MB your Lambda Function can use at runtime."
default = 128
}

variable "timeout" {
type = number
description = "The maximum number of seconds the lambda function to run until timeout."
default = 3
}
Expand All @@ -99,22 +118,26 @@ variable "dead_letter_config" {
}

variable "description" {
type = string
description = "Description of what your Lambda Function does."
default = ""
}

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

variable "reserved_concurrent_executions" {
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."
type = string
default = -1
}

variable "publish" {
description = "Whether to publish creation/change as new Lambda Function Version."
type = string
default = false
}

Expand Down

0 comments on commit 780add0

Please sign in to comment.