Adding trigger between lambda function and Cloudwatch rule?

I am struggling to create a schedule to run a lambda function through terraform…

With the code below

resource "aws_lambda_function" "cleansing_coding_lambda" {
    ...
}

resource "aws_cloudwatch_event_rule" "cleansing_coding_rule" {
  name        = "cleansing-coding-rule"
  schedule_expression = "cron(5 * * * ? *)" # every hour, 5 mns passed the hour
}

resource "aws_cloudwatch_event_target" "cleansing_coding_target" {
  rule      = aws_cloudwatch_event_rule.cleansing_coding_rule.name
  arn       = aws_lambda_function.cleansing_coding_lambda.arn
}

I can see that the Amazon Eventbridge rule is created.
Its schedule is set
Its target is configured to the lambda function bfe-dp-dev-triggerMatillionCleansingCoding which is correct.

However, when I look at the lambda function bfe-dp-dev-triggerMatillionCleansingCoding, it does not appear to be linked to a “EventBridge (CloudWatch Events)”.

I still need to manually add a “trigger” to “Eventbridge (CloudWatch Events)” where I do retrieve my rule “cleansing-coding-rule”.

Am I missing a step/trick in terraform?

Thanks

Have a look at the example here:

You are missing this last lambda permission part:

resource "aws_lambda_function" "check_foo" {
    filename = "check_foo.zip"
    function_name = "checkFoo"
    role = "arn:aws:iam::424242:role/something"
    handler = "index.handler"
}

resource "aws_cloudwatch_event_rule" "every_five_minutes" {
    name = "every-five-minutes"
    description = "Fires every five minutes"
    schedule_expression = "rate(5 minutes)"
}

resource "aws_cloudwatch_event_target" "check_foo_every_five_minutes" {
    rule = "${aws_cloudwatch_event_rule.every_five_minutes.name}"
    target_id = "check_foo"
    arn = "${aws_lambda_function.check_foo.arn}"
}

resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_foo" {
    statement_id = "AllowExecutionFromCloudWatch"
    action = "lambda:InvokeFunction"
    function_name = "${aws_lambda_function.check_foo.function_name}"
    principal = "events.amazonaws.com"
    source_arn = "${aws_cloudwatch_event_rule.every_five_minutes.arn}"
}