Skip to content

Commit

Permalink
add create logic
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 26, 2022
1 parent 1311b7f commit ca7ac23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions cloudwatch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@ resource "aws_cloudwatch_log_group" "log" {
# aws events put-targets --rule ec2_lambda_ddns_rule --targets Id=id123456789012,Arn=<enter-your-lambda-function-arn-here>

resource "aws_cloudwatch_event_rule" "ec2_rule" {
count = var.create ? 1 : 0
name = local.name
description = "Capture EC2 Events to hande dynamic Route53 registration"
event_pattern = jsonencode(local.cloudwatch_event_pattern)
}

resource "aws_cloudwatch_event_target" "ec2_target" {
count = var.create ? 1 : 0
target_id = local.name
arn = aws_lambda_function.lambda.arn
rule = aws_cloudwatch_event_rule.ec2_rule.name
arn = var.create ? aws_lambda_function.lambda[0].arn : null
rule = var.crate ? aws_cloudwatch_event_rule.ec2_rule[0].name : null
}

resource "aws_lambda_permission" "allow_cloudwatch" {
count = var.create ? 1 : 0
statement_id = local.name
# statement_id = 45
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda.function_name
function_name = var.create ? aws_lambda_function.lambda[0].function_name : null
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.ec2_rule.arn
qualifier = aws_lambda_alias.lambda.name
source_arn = var.create ? aws_cloudwatch_event_rule.ec2_rule[0].arn : null
qualifier = var.create ? aws_lambda_alias.lambda[0].name : null
}
2 changes: 1 addition & 1 deletion version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "0.0.9"
_module_version = "0.0.10"
}

0 comments on commit ca7ac23

Please sign in to comment.