@cloudnux/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ data "aws_apigatewayv2_api" "this" {
2
+ api_id = var.api_gateway_id
3
+ }
4
+
5
+ resource "aws_apigatewayv2_route" "this" {
6
+ for_each = var.entrypoints
7
+
8
+ api_id = var.api_gateway_id
9
+ route_key = "${upper(each.value.method)} ${each.value.path}"
10
+
11
+ authorization_type = try(each.value.authorization_type, "NONE")
12
+ authorizer_id = try(each.value.authorizer_id, null)
13
+
14
+ operation_name = each.key
15
+ target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
16
+ }
17
+
18
+ resource "aws_apigatewayv2_integration" "this" {
19
+ for_each = var.entrypoints
20
+
21
+ api_id = var.api_gateway_id
22
+ description = try(each.value.description, null)
23
+
24
+ integration_type = "AWS_PROXY"
25
+ integration_method = "POST"
26
+ integration_uri = var.lambda_arn
27
+ connection_type = "INTERNET"
28
+
29
+ payload_format_version = "2.0"
30
+ timeout_milliseconds = try(each.value.timeout, null)
31
+
32
+ lifecycle {
33
+ create_before_destroy = true
34
+ }
35
+ }
@@ -0,0 +1,22 @@
1
+ variable "entrypoints" {
2
+ type = map(object({
3
+ description = string
4
+ method = string
5
+ path = string
6
+ timeout = optional(number, 29000)
7
+ authorization_type = optional(string, "NONE")
8
+ authorizer_id = optional(string)
9
+ }))
10
+ }
11
+
12
+ variable "lambda_name" {
13
+ type = string
14
+ }
15
+
16
+ variable "lambda_arn" {
17
+ type = string
18
+ }
19
+
20
+ variable "api_gateway_id" {
21
+ type = string
22
+ }
@@ -0,0 +1,47 @@
1
+ data "aws_iam_role" "eventbridge_role" {
2
+ name = "eventbridge_execution_role"
3
+ }
4
+
5
+ resource "aws_scheduler_schedule_group" "this" {
6
+
7
+ name = var.component
8
+
9
+ lifecycle {
10
+ create_before_destroy = true
11
+ }
12
+ }
13
+
14
+
15
+ resource "aws_scheduler_schedule" "this" {
16
+ for_each = var.schedules
17
+
18
+ name = each.value.name
19
+ description = try(each.value.description, null)
20
+ group_name = aws_scheduler_schedule_group.this.name
21
+
22
+ schedule_expression = each.value.pattern
23
+ schedule_expression_timezone = try(each.value.timezone, "UTC")
24
+
25
+ state = try(each.value.state, "ENABLED")
26
+
27
+ flexible_time_window {
28
+ maximum_window_in_minutes = lookup(each.value, "maximum_window_in_minutes", null)
29
+ mode = lookup(each.value, "use_flexible_time_window", false) ? "FLEXIBLE" : "OFF"
30
+ }
31
+
32
+ target {
33
+ arn = var.target_arn
34
+ role_arn = data.aws_iam_role.eventbridge_role.arn
35
+
36
+ dynamic "retry_policy" {
37
+ for_each = lookup(each.value, "retry_policy", null) != null ? [
38
+ each.value.retry_policy
39
+ ] : []
40
+
41
+ content {
42
+ maximum_event_age_in_seconds = retry_policy.value.maximum_event_age_in_seconds
43
+ maximum_retry_attempts = retry_policy.value.maximum_retry_attempts
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,21 @@
1
+ variable "schedules" {
2
+ description = "A map of objects with EventBridge Schedule definitions."
3
+ type = map(object({
4
+ name = string
5
+ pattern = string
6
+ description = optional(string)
7
+ timezone = optional(string, "Europe/Stockholm")
8
+ state = optional(string, "ENABLED")
9
+ use_flexible_time_window = optional(bool, false)
10
+ maximum_window_in_minutes = optional(number)
11
+ }))
12
+ }
13
+ variable "component" {
14
+ description = "The name of the component."
15
+ type = string
16
+ }
17
+
18
+ variable "target_arn" {
19
+ description = "The ARN of the Lambda function."
20
+ type = string
21
+ }
@@ -0,0 +1,38 @@
1
+ # SQS Trigger Module - main.tf
2
+
3
+ data "aws_sqs_queue" "this" {
4
+ for_each = var.event_sources
5
+ name = each.value.queue_name
6
+ }
7
+
8
+ data "aws_sqs_queue" "dlq" {
9
+ for_each = var.event_sources
10
+ name = "${each.value.queue_name}-dlq"
11
+ }
12
+
13
+ resource "aws_lambda_event_source_mapping" "sqs" {
14
+ for_each = var.event_sources
15
+
16
+ event_source_arn = data.aws_sqs_queue.this[each.key].arn
17
+ function_name = var.lambda_name
18
+ enabled = try(each.value.enabled, true)
19
+
20
+ # SQS specific configurations
21
+ batch_size = try(each.value.batch_size, 10)
22
+ maximum_batching_window_in_seconds = try(each.value.maximum_batching_window_in_seconds, null)
23
+
24
+ lifecycle {
25
+ create_before_destroy = true
26
+ }
27
+ }
28
+
29
+ # # Grant Lambda permission to be invoked by SQS
30
+ # resource "aws_lambda_permission" "allow_sqs" {
31
+ # for_each = var.event_sources
32
+
33
+ # statement_id = "AllowExecutionFromSQS-${each.key}"
34
+ # action = "lambda:InvokeFunction"
35
+ # function_name = var.lambda_name
36
+ # principal = "sqs.amazonaws.com"
37
+ # source_arn = data.aws_sqs_queue.this[each.key].arn
38
+ # }
@@ -0,0 +1,27 @@
1
+ variable "event_sources" {
2
+ description = "Map of SQS event source configurations"
3
+ type = map(object({
4
+ queue_name = string
5
+ enabled = optional(bool, true)
6
+ batch_size = optional(number, 10)
7
+ maximum_batching_window_in_seconds = optional(number)
8
+ function_response_types = optional(list(string))
9
+
10
+ # Scaling configuration
11
+ scaling_config = optional(object({
12
+ maximum_concurrency = number
13
+ }))
14
+ }))
15
+
16
+ validation {
17
+ condition = alltrue([
18
+ for k, v in var.event_sources : v.batch_size >= 1 && v.batch_size <= 10000
19
+ ])
20
+ error_message = "Batch size must be between 1 and 10000."
21
+ }
22
+ }
23
+
24
+ variable "lambda_name" {
25
+ description = "Name of the Lambda function"
26
+ type = string
27
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }