resource "aws_cloudformation_stack" "aws_scheduler" {
  # ATM, we really don't want this in prod or common. If we change our minds, we'll need to verify that
  # the `schedule` tag is set correctly.
  #
  # Until then, this should prevent it, along with a warning in outputs.tf
  count = var.environment == "test" ? 1 : 0

  name = "aws-scheduler"
  on_failure = "ROLLBACK"
  #iam_role_arn = "${lookup(local.workspace_to_full_admin_assumerole,terraform.workspace,"")}"
  capabilities = [ "CAPABILITY_IAM" ]

  parameters = {
    UseCloudWatchMetrics = "Yes"  
    Regions = var.aws_region
    SchedulerFrequency = "15"
    Trace = "Yes"   # Detailed logs in Cloudwatch
    StartedTags = ""
    StoppedTags = ""
    CrossAccountRoles = ""

    # These will probably cause terraform drift so right now not doing them
    #StartedTags = "SchedulerStatus=Started {year}-{month}-{day} {hour}:{minute} {timezone}"
    #StoppedTags = "SchedulerStatus=Stopped {year}-{month}-{day} {hour}:{minute} {timezone}"
  }

  template_body = file("${path.module}/files/instance-scheduler.template.${var.aws_partition}")
}
