0

I've created a canary via terraform. I'm now attempting to update the canary script via terraform. I input my script directly into the canary. I've included a null resource with a trigger that always recreates my zip file. My canary script/ lambda layer doesn't update. I'm wondering how I trigger an update to use a new script version? So far the only thing I've found to work is a terraform destroy/apply.

I'm aware of the cli update-canary command and s3 options. I'd ideally like to continue inputing my script directly into the canary.

resource "null_resource" "script-zip" {
  provisioner "local-exec" {
    command     = <<EOT
      zip -r ./recordedScript.zip nodejs/node_modules/
    EOT
    working_dir = path.module
  }
  triggers = {
    always_run = "${timestamp()}"
  }
}

resource "aws_synthetics_canary" "canary" {
  name                 = var.synthetic-name
  artifact_s3_location = "s3://${aws_s3_bucket.synthetics-bucket.id}"
  execution_role_arn   = aws_iam_role.synthetics_role.arn
  handler              = var.handler
  zip_file             = "${path.module}/recordedScript.zip"
  runtime_version      = var.runtime-version
  start_canary         = var.start-canary
  depends_on = [
    resource.null_resource.script-zip
  ]

1 Answers1

0

It seems the aws_synthetics_canary resource doesnt look at the hash of the zip file created. I was able to get around this by giving the zip file a unique name each create.

locals {
  NOW = "${timestamp()}"
}

resource "null_resource" "script-zip" {
  provisioner "local-exec" {
    command     = <<EOT
      zip -r ./${local.NOW}-recordedScript.zip nodejs/node_modules/
    EOT
    working_dir = path.module
  }
  triggers = {
    always_run = "${timestamp()}"
  }
}


resource "aws_synthetics_canary" "canary" {
  name                 = var.synthetic-name
  artifact_s3_location = "s3://${aws_s3_bucket.synthetics-bucket.id}"
  execution_role_arn   = aws_iam_role.synthetics_role.arn
  handler              = var.handler
  zip_file             = "${path.module}/${local.NOW}-recordedScript.zip"
  runtime_version      = var.runtime-version
  start_canary         = var.start-canary

  depends_on = [
    resource.null_resource.script-zip
  ]


  schedule {
    expression = var.schedule
  }

  run_config {
    environment_variables = var.env-vars
    timeout_in_seconds    = var.timeout
  }
}