Skip to content

[Bug]: aws_autoscaling_schedule start_time is not recalculated when modifying the resourceΒ #38983

Open
@flostadler

Description

Terraform Core Version

1.5.7

AWS Provider Version

5.63.1

Affected Resource(s)

  • aws_autoscaling_schedule

Expected Behavior

When creating a aws_autoscaling_schedule without start_time, AWS will calculate an appropriate start time based on the recurrence.

On subsequent modifications of the resource, the start_time shouldn't be sent in the API requests in order to trigger the re-computation again.

Actual Behavior

When the schedule is created, the computed start_time is saved to state and subsequent modifications will include this start_time in their API requests.

This can lead to scenarios where the schedule does not fire when expected or the modification fails because AWS whether the start time is in the future.

For example:
When creating a schedule without start_time and the following recurrence 0 10 * * SAT (At 10:00 on Saturdays), the start_time will be set by AWS to the first occurrence of this cron job (e.g. 2024-08-24T10:00:00Z).
If the recurrence is now modified to 0 8 * * SAT (At 08:00 on Saturdays), the start_time stays at 2024-08-24T10:00:00Z. This will have the effect that the schedule skips the first week.

If the recurrence is now updated on a day after 2024-08-24T10:00:00Z, AWS will fail the API request because the start_time is in the past and they do not allow that: ValidationError: Given start time is in the past.

Relevant Error/Panic Output Snippet

n/a

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
    }
  }
}

provider "aws" {
  region = "us-west-2"
}

resource "aws_launch_configuration" "foobar" {
  name = "tfbug-lc"
  image_id = "ami-21f78e11"
  instance_type = "t1.micro"
}

resource "aws_autoscaling_group" "foobar" {
  availability_zones = ["us-west-2a"]
  name = "tfbug-asg"
  max_size = 0
  min_size = 0
  launch_configuration = "${aws_launch_configuration.foobar.name}"
}

variable "recurrence" {
  default = "0 10 * * SAT"
  type = string
}

resource "aws_autoscaling_schedule" "foobar" {
  scheduled_action_name = "tfbug-sched"
  autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
  min_size = 0
  max_size = 0
  desired_capacity = 0
  recurrence = var.recurrence
}

output "start_time" {
  value = aws_autoscaling_schedule.foobar.start_time
}

Steps to Reproduce

  • terraform apply: Observe the start_time output being set to next Saturday at 10:00
  • terraform apply -var="recurrence=0 8 * * SAT": Observe the start_time output still being set to next Saturday 10:00, while in reality it should be 08:00

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/autoscalingIssues and PRs that pertain to the autoscaling service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions