Skip to content

Commit d36648a

Browse files
author
Allison Wampler
committed
feat: add initial snapshot invoke for lambda
* Disable with `invoke_snapshot_on_start_enabled = false`
1 parent 07a9083 commit d36648a

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

modules/snapshot/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ No modules.
115115
| [aws_cloudwatch_event_target.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
116116
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
117117
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
118+
| [aws_lambda_invocation.snapshot](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_invocation) | resource |
118119
| [aws_lambda_permission.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
119120
| [aws_arn.function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
120121
| [aws_arn.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
@@ -130,6 +131,7 @@ No modules.
130131
| <a name="input_exclude"></a> [exclude](#input\_exclude) | List of actions to exclude from being executed on snapshot request. | `list(string)` | `[]` | no |
131132
| <a name="input_iam_name_prefix"></a> [iam\_name\_prefix](#input\_iam\_name\_prefix) | Prefix used for all created IAM roles and policies | `string` | `""` | no |
132133
| <a name="input_include"></a> [include](#input\_include) | List of actions to include in snapshot request. | `list(string)` | `[]` | no |
134+
| <a name="input_invoke_snapshot_on_start_enabled"></a> [invoke\_snapshot\_on\_start\_enabled](#input\_invoke\_snapshot\_on\_start\_enabled) | Toggle invocation of snapshot from Cloudformation. | `string` | `true` | no |
133135
| <a name="input_lambda"></a> [lambda](#input\_lambda) | Observe Lambda module | <pre>object({<br> lambda_function = object({<br> arn = string<br> role = string<br> })<br> })</pre> | n/a | yes |
134136
| <a name="input_overrides"></a> [overrides](#input\_overrides) | List of configuration overrides. | <pre>list(object({<br> action = string<br> config = map(any)<br> }))</pre> | `[]` | no |
135137
| <a name="input_resources"></a> [resources](#input\_resources) | List of resources to scope policy to. | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |

modules/snapshot/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ resource "aws_lambda_permission" "this" {
6060
function_name = trimprefix(data.aws_arn.function.resource, "function:")
6161
source_arn = aws_cloudwatch_event_rule.trigger.arn
6262
}
63+
64+
resource "aws_lambda_invocation" "snapshot" {
65+
count = var.invoke_snapshot_on_start_enabled ? 1 : 0
66+
# Note: Use function name from the arn to prevent requiring function_name
67+
function_name = trimprefix(data.aws_arn.function.resource, "function:")
68+
69+
input = aws_cloudwatch_event_target.target.input
70+
}
71+

modules/snapshot/variables.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ variable "eventbridge_name_prefix" {
3131

3232
variable "action" {
3333
description = <<-EOF
34-
List of actions allowed by policy and periodically triggered. By default,
35-
this list contains all policies which the lambda can act upon. You should
36-
only override this list if you do not want to execute more actions as they
37-
become available in future lambda upgrades. If you instead wish to extend
38-
this list, or ignore a subset of actions, use \"include\" and \"exclude\".
34+
List of actions allowed by policy and periodically triggered. By default,
35+
this list contains all policies which the lambda can act upon. You should
36+
only override this list if you do not want to execute more actions as they
37+
become available in future lambda upgrades. If you instead wish to extend
38+
this list, or ignore a subset of actions, use \"include\" and \"exclude\".
3939
EOF
4040
type = list(string)
4141
nullable = false
@@ -130,3 +130,10 @@ variable "eventbridge_schedule_expression" {
130130
nullable = false
131131
default = "rate(3 hours)"
132132
}
133+
134+
variable "invoke_snapshot_on_start_enabled" {
135+
description = "Toggle invocation of snapshot from Cloudformation."
136+
type = string
137+
nullable = false
138+
default = true
139+
}

0 commit comments

Comments
 (0)