Skip to content

Terraform provider to validate Amazon EventBridge Cron expressions.

License

Notifications You must be signed in to change notification settings

winebarrel/terraform-provider-cronplan

Repository files navigation

terraform-provider-cronplan

CI terraform docs

Terraform provider to validate Amazon EventBridge Cron expressions.

If the cron expression is incorrect, an error will occur in terraform plan.

Usage

provider "cronplan" {
}

data "cronplan_expr" "every_weekday" {
  # NOTE: Expression is validated with terraform plan.
  expr = "cron(5 0 ? * MON-FRI *)"
  from = "2023-09-30 10:00:00 UTC" # Optional
}

output "every_weekday" {
  value = data.cronplan_expr.every_weekday.schedules
}

check "every_weekday_schedules" {
  assert {
    condition = data.cronplan_expr.every_weekday.schedules == tolist([
      "Mon, 02 Oct 2023 00:05:00",
      "Tue, 03 Oct 2023 00:05:00",
      "Wed, 04 Oct 2023 00:05:00",
      "Thu, 05 Oct 2023 00:05:00",
      "Fri, 06 Oct 2023 00:05:00",
      "Mon, 09 Oct 2023 00:05:00",
      "Tue, 10 Oct 2023 00:05:00",
      "Wed, 11 Oct 2023 00:05:00",
      "Thu, 12 Oct 2023 00:05:00",
      "Fri, 13 Oct 2023 00:05:00",
    ])

    error_message = "Unexpected schedule: \n${join("\n", data.cronplan_expr.every_weekday.schedules)}"
  }
}

Run locally for development

cp cronplan.tf.sample cronplan.tf
make tf-plan

Related Links