Search code examples
amazon-web-servicesterraformaws-ssm

aws:sleep in AWS SSM


I want to apply an SSM Association to multiple instances, where each instance runs a PowerShell script. I've defined the SSM document resource in Terraform as shown below:

resource "aws_ssm_document" "ssm_document" {
  name            = "SSM-Association"
  document_type   = "Command"
  document_format = "JSON"

  content = jsonencode({
    schemaVersion = "2.2",
    description   = "Document to run a command on Windows instances",
    parameters    = {},
    mainSteps     = [
      {
        action       = "aws:runPowerShellScript",
        name         = "runPowerShellScript",
        inputs       = {
          runCommand = split("\n", trimspace(local.commands))
        },
        precondition = {
          StringEquals = [
            "platformType",
            "Windows"
          ]
        }
      },
      {
        action = "aws:sleep",
        name   = "sleepForOneMinute",
        inputs = {
          Duration = "PT1M"
        }
      }
    ]
  })
}

SSM association resource:

resource "aws_ssm_association" "association" {
  name = aws_ssm_document.ssm_document.name

  targets {
    key    = "InstanceIds"
    values = data.aws_instances.all.ids
  }

  max_concurrency = "1" 
  max_errors      = "0"

I want the association to execute and then pause for 60 seconds before moving on to the next instance. To achieve this, I added the action aws:sleep. However, when I run terraform apply, I encounter an error that says, "Unknown plugin name: aws:sleep."

│ Error: updating SSM Document (SSM-Association): updating SSM document: InvalidDocumentContent: Unknown plugin name: aws:sleep
│ 
│   with aws_ssm_document.ssm_document,
│   on main.tf line 27, in resource "aws_ssm_document" "ssm_document":
│   27: resource "aws_ssm_document" "ssm_document" {

Is this the correct way to use the aws:sleep action if I want my SSM Association to pause for 60 seconds between each instance?


Solution

  • If you check AWS docs for Command, you will find that aws:sleep is not supported.

    aws:sleep is only usable in automation documents, not in command documents.