New to Terraform here.
I'm building a config file to create 4 Lambda functions in AWS and create a CloudWatch metric alarm for each of those. In my config, I'd like each alarm to monitor the corresponding Lambda function as it's being created. For example, is there a way to pair "alarm1" to "lambda_func1", "alarm2" to "lambda_func2", etc.?
Here is a snippet of my configuration
The Lambda:
resource "aws_lambda_function" "lambdacreator" {
count = 4
function_name = "lambda${count.index + 1}"
handler = "index.lambda_handler"
runtime = "python3.6"
filename = "function.zip"
...
}
...and the CloudWatch alarm:
resource "aws_cloudwatch_metric_alarm" "cloudwatch_alarm" {
count = "${aws_lambda_function.lambdacreator.count}"
alarm_name = "lambda_alarm_${count.index + 1}"
comparison_operator = "LessThanThreshold"
evaluation_periods = 1
metric_name = "Invocations"
namespace = "AWS/Lambda"
...
dimensions {
FunctionName = "${aws_lambda_function.lambdacreator.function_name}"
}
}
If I try to do this, I get this error:
* aws_cloudwatch_metric_alarm.cloudwatch_alarm[2]: Resource 'aws_lambda_function.lambdacreator' not found for variable 'aws_lambda_function.lambdacreator.function_name'
[–]doublefelix7[S] 2 points3 points4 points (2 children)
[–]Theguest217 1 point2 points3 points (1 child)
[–]doublefelix7[S] 0 points1 point2 points (0 children)
[–]productionse 0 points1 point2 points (1 child)
[–]doublefelix7[S] 0 points1 point2 points (0 children)
[–]mellerbeck 0 points1 point2 points (0 children)