Creates a scheduled action to pause an AWS Redshift cluster using IAM roles and policies.

Terraform Template

data "aws_iam_policy_document" "assume_role" {

  statement {
    actions = ["sts:AssumeRole"]
    effect = "Allow"

    principals {
      identifiers = ["scheduler.redshift.amazonaws.com"]
      type = "Service"
    }
  }
}

data "aws_iam_policy_document" "example" {

  statement {
    actions = ["redshift:PauseCluster", "redshift:ResumeCluster", "redshift:ResizeCluster"]
    effect = "Allow"
    resources = [*]
  }
}

resource "aws_iam_policy" "example" {
  name = "redshift_scheduled_action"
  policy = data.aws_iam_policy_document.example.json
}

resource "aws_iam_role" "example" {
  assume_role_policy = data.aws_iam_policy_document.assume_role.json
  name = "redshift_scheduled_action"
}

resource "aws_iam_role_policy_attachment" "example" {
  policy_arn = aws_iam_policy.example.arn
  role = aws_iam_role.example.name
}

resource "aws_redshift_scheduled_action" "example" {
  iam_role = aws_iam_role.example.arn
  name = "tf-redshift-scheduled-action"
  schedule = "cron(00 23 * * ? *)"

  target_action {

    pause_cluster {
      cluster_identifier = "tf-redshift001"
    }
  }
}