AWS Scheduler creation trhough TF fails due to cron validation error

The TF plan shows the following:

# aws_scheduler_schedule.gh_runners_ubuntu_start["gh_runner_ubuntu"] will be created
  + resource "aws_scheduler_schedule" "gh_runners_ubuntu_start" {
      + arn                          = (known after apply)
      + group_name                   = (known after apply)
      + id                           = (known after apply)
      + name                         = "gh_runners_ubuntu_start-ormos-runner"
      + name_prefix                  = (known after apply)
      + schedule_expression          = "cron(0 23 * * *)"
      + schedule_expression_timezone = "UTC"
      + state                        = "ENABLED"
      + flexible_time_window {
          + mode = "OFF"
        }
      + target {
          + arn      = "arn:aws:scheduler:::aws-sdk:ec2:startInstances"
          + input    = jsonencode(
                {
                  + InstanceIds = [
                      + "i-xxxxxxxxxxxxxxxxx",
                    ]
                }
            )
          + role_arn = "arn:aws:iam::12345678:role/gh_runners_ubuntu_scheduler_role-runner"
        }
    }

Creation fails with:

ValidationException: Invalid Schedule Expression cron(0 23 * * *).

Any ideas?

If you refer to the AWS docs for the schedule expressions, you’ll see it is indeed invalid.

Do note that AWS’es idea of “cron” expressions is not quite the same as Unix cron.

1 Like