pulumi / pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Apache License 2.0
462 stars 155 forks source link

Bug with aws.autoscaling.Schedule [startTime will not be renewed] #2473

Open timlukastlt opened 1 year ago

timlukastlt commented 1 year ago

What happened?

If aws.autoscaling.Schedule is used and no startTime is specifed which is okay because normally it will be calculated automatic: It works!

But if then a change is made, for example in the recurrence argument, an error will come up that says given start time is in the past.

I think that the startTime from the first deployment will not be changed and so it will be in the past.

image-2023-02-22-11-51-38-279

Expected Behavior

Normal Behavior for me would be that the next startTime would be calculated on every change so this error wont come up.

Steps to reproduce

Create aws.autoscaling.Schedule, don´t use a startTime and then update one argument after the calculated startTime which can be seen on aws.

Output of pulumi about

_$ pulumi about CLI
Version 3.29.1 Go Version go1.17.8 Go Compiler gc Plugins NAME VERSION nodejs unknown Host
OS alpine Version 3.15.4 Arch x8664 This project is written in nodejs (/usr/bin/node v16.14.2) Pulumi locates its logs in /tmp by default

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

mikhailshilkov commented 1 year ago

@timlukastlt Thank you for reporting this. Could you please include a code snippet that would allow me to reproduce the problem?

timlukastlt commented 1 year ago

Yes sure

First execute your code with this (Insert your ASG name) :

import { autoscaling } from "@pulumi/aws"

new autoscaling.Schedule("Test", {
    scheduledActionName: "Test",
    minSize: 0,
    maxSize: 27,
    timeZone: "Europe/Berlin",
    desiredCapacity: 27,
    recurrence: "*/5 * * * *",
    autoscalingGroupName: "YOUR ASG NAME",
});

Then the startTime will be attached automatic and you just need to wait till its past the startTime. Then make a change in the Code, for example change the recurrence and then you will get the error that the startTime is in the past, because it will not change the startTime automatic. image

timlukastlt commented 3 months ago

Hey, any updates? @mikhailshilkov

flostadler commented 2 months ago

Hey @timlukastlt, I'm sorry you're running into this! I was able to find the root cause of this, which lies within the upstream provider https://github.com/hashicorp/terraform-provider-aws/issues/38983. I'll check if there's something we can do on our side to work around this issue.

Until this is fixed you could start specifying the startTime as a workaround. The following nodejs example shows how you can retrieve the next execution of a cron expression and use that for determining the right start time. It uses the cron-parser library for that (npm install cron-parser).

import * as aws from "@pulumi/aws";
import * as parser from 'cron-parser';

const recurrence = "0 10 * * SAT"
const startTime = parser.parseExpression(recurrence, { tz: "UTC" }).next().toISOString().split('.')[0] + "Z";
const autoScalingSchedule = new aws.autoscaling.Schedule("test", {
    scheduledActionName: "start-time-sched",
    autoscalingGroupName: autoScalingGroup.name,
    minSize: 0,
    maxSize: 0,
    desiredCapacity: 0,
    startTime: startTime,
    recurrence: recurrence, // Replace with actual recurrence value
});
timlukastlt commented 2 months ago

Hey,

thank your for your workaround and for opening a ticket for Terraform. Your workaround works!

Thank you :)