Terraform: aws_autoscaling_schedule defaults desired_capacity to zero with no way of specifying an empty value

Created on 17 Mar 2016  ·  17Comments  ·  Source: hashicorp/terraform

Thanks to #4690 we are no longer able to make use of aws_autoscaling_schedule resources. With a config like:

resource "aws_autoscaling_schedule" "asg-scale-up" {
  autoscaling_group_name = "my-asg"
  scheduled_action_name  = "scale-up"
  min_size               = 15
  recurrence             = "0 11 * * mon,tue,wed,thu,fri"
}

We get an error (via Terraform, from the AWS API) that "desired_capacity cannot be less than min_size". But we wish for desired_capacity to be managed by the autoscaling group, not by Terraform, and so we cannot specify a desired capacity. There should be a way to indicate that we do not wish for anything to be specified for desired_capacity.

bug provider-sdk provideaws

Most helpful comment

Hey @daveadams – thanks for opening this. I also opened https://github.com/hashicorp/terraform/issues/5694 to push this along, as we're in a bit of a tough spot here, needing to both omit and allow zero values.

All 17 comments

Hey @daveadams – thanks for opening this. I also opened https://github.com/hashicorp/terraform/issues/5694 to push this along, as we're in a bit of a tough spot here, needing to both omit and allow zero values.

Great. Yeah I figured it had something to do with that.

Can you make -1 equivalent to omit behind the scenes? This could be useful for making other generic modules where I want to reuse the module but not every key. Even better would be to allow a null or nil or some other non-magic number token for specific resource keys that allow it.

@daveadams similar to what ^ said, I'd like to apply changes to the infra without resetting desired capacity to a fixed number (because we autoscale outside terraform). Omitting the value sets it to the min right now (I think?). Is there a way to apply changes without changing the current value for desired capacity?

Same thing here: We just want to change min value by schedule, but the desired (and max) value should be kept. Terraform raises: "Error Creating Autoscaling Scheduled Action: ValidationError: Desired capacity must be less than or equal to max size"

Here's a PR to fix it using the ghost's suggestion. #9941

Setting desired, min and max all to "1" fails with

aws_autoscaling_schedule.add_workers_before_working_time: Error Creating Autoscaling Scheduled Action: ValidationError: Desired capacity must be less than or equal to max size

Any update? I've just created scheduled action and have to specify min_size and max_size while I just want to change desired_capicity :-(

9941 still works for us. I'd love to see it merged!

This is an active blocker for us. Would love to see #9941 get reviewed/merged.

This is also a blocker for us, another bump to #9941 :)

:+1:

Just found this in the docs for those who found this issue:

min_size - (Optional) The minimum size for the Auto Scaling group. Default
Set to -1 if you don't want to change the minimum size at the scheduled time.
max_size - (Optional) The maximum size for the Auto Scaling group. Default
Set to -1 if you don't want to change the maximum size at the scheduled time.
desired_capacity - (Optional) The number of EC2 instances that should be running in the group. > Default 0. Set to -1 if you don't want to change the desired capacity at the scheduled time.

Seems like the desired behavior can be triggered by manually setting them to -1.

@catsby: Is there a reason why the default is 0 and not -1? I would normally expect that not setting optional values means to not change them at the scheduled time rather than setting them to 0.
And what are the actual defaults for min and max? The docs read like they're incomplete.

I implemented the PR that got merged (though somebody else ported it to a new repo). My memory was, at least at that time, Terraform couldn't usefully differentiate between "parameter given as 0" and "parameter left blank".

That is a side-effect of the Go serialization I think, but there are ways to check for empty vs literal zero, and other AWS provider resources handle this sort of situation just fine, also this used to work, long ago...

This issue has been automatically migrated to terraform-providers/terraform-provider-aws#6379 because it looks like an issue with that provider. If you believe this is _not_ an issue with the provider, please reply to terraform-providers/terraform-provider-aws#6379.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings