【发布时间】:2019-06-03 05:00:19
【问题描述】:
我正在尝试通过 terraform 创建 AWS Clouwatch 事件规则
variable "schedule_expression" {
default = "cron(5 * * * ? *)"
description = "the aws cloudwatch event rule scheule expression that specifies when the scheduler runs. Default is 5 minuts past the hour. for debugging use 'rate(5 minutes)'. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html"
}
我想指定变量而不是 5
variable "AutoStopSchedule" {
default = "5"
}
variable "schedule_expression" {
default = "cron(${var.AutoStopSchedule} * * * ? *)"
description = "the aws cloudwatch event rule scheule expression that specifies when the scheduler runs. Default is 5 minuts past the hour. for debugging use 'rate(5 minutes)'. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html"
}
但得到:
Error: variable "schedule_expression": default may not contain interpolations
main.tf
# Cloudwatch event rule
resource "aws_cloudwatch_event_rule" "check-scheduler-event" {
name = "check-scheduler-event"
description = "check-scheduler-event"
schedule_expression = "${var.schedule_expression}"
depends_on = ["aws_lambda_function.demo_lambda"]
}
我想根据 AutoStopSchedule 变量创建 schedule_expression,怎么做?
尝试以下:
resource "aws_cloudwatch_event_rule" "check-scheduler-event" {
name = "check-scheduler-event"
description = "check-scheduler-event"
#schedule_expression = "cron(15 * * * ? *)"
schedule_expression = "${var.AutoStopSchedule == "5" ? cron(5 * * * ? *) : cron(15 * * * ? *)}"
depends_on = ["aws_lambda_function.demo_lambda"]
}
获取expected expression but found "*"
【问题讨论】:
标签: interpolation terraform amazon-cloudwatch