Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_autoscaling_schedule - cannot set zero to max/min/desired #4690

Closed
AirbornePorcine opened this issue Jan 15, 2016 · 11 comments
Closed

aws_autoscaling_schedule - cannot set zero to max/min/desired #4690

AirbornePorcine opened this issue Jan 15, 2016 · 11 comments

Comments

@AirbornePorcine
Copy link

Hi!

So I'm attempting to create a aws_autoscaling_schedule resource that shuts down all my instances overnight. When I try to do this with terraform however, any field of max_size/min_size/desired_capacity that is set to zero is effectively ignored. If they're all set to zero, you get this error:

Error Creating Autoscaling Scheduled Action: ValidationError: At least one of max size, min size, or desired capacity must be specified
    status code: 400, request id: 02af3c57-bba3-11e5-a6c3-99fcfc3310db

If I set any single field to a non-zero value, then my autoscaling schedule (via aws autoscaling describe-scheduled-action) looks like this (min/desired set to zero, max set to 2):

{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "xxx",
            "MaxSize": 2,
            "ScheduledActionARN": "xxx",
            "ScheduledActionName": "ShutdownAfterBusinessHours",
            "StartTime": "2016-01-15T16:20:00Z",
            "Time": "2016-01-15T16:20:00Z",
            "EndTime": "2016-01-15T16:30:00Z"
        }
    ]
}

Looking at the code in resource_aws_autoscheduling_schedule.go, I noticed the following:

    if attr, ok := d.GetOk("min_size"); ok {
        params.MinSize = aws.Int64(int64(attr.(int)))
    }

    if attr, ok := d.GetOk("max_size"); ok {
        params.MaxSize = aws.Int64(int64(attr.(int)))
    }

    if attr, ok := d.GetOk("desired_capacity"); ok {
        params.DesiredCapacity = aws.Int64(int64(attr.(int)))
    }

The d.GetOk call is specifically meant to not return zero values. Changing this to just Ok wouldn't work very well since then (as I understand it), not specifying a field would be equivalent to a zero value.

So, looking for a little guidance on how you'd like to resolve this, then I can submit a PR. Thanks!

@AirbornePorcine
Copy link
Author

Oh, I should note - I did attempt to use zero values through the AWS CLI manually, and it does fully accept a scheduled scaling action that sets min/desired to zero, which is the effect we're looking for.

@stack72
Copy link
Contributor

stack72 commented Jan 15, 2016

@AirbornePorcine please can you post a short snippet of your terraform config that I can use as an acceptance test to fix this bug? (Remember to remove secrets from the config if there are any)

@AirbornePorcine
Copy link
Author

For sure.

resource "aws_autoscaling_schedule" "ScaleDown" {
  provider = "aws"
  autoscaling_group_name = "MyAutoScalingGroup"
  scheduled_action_name = "ShutdownAfterBusinessHours"
  max_size = 0
  min_size = 0
  desired_capacity = 0
  start_time = "2016-01-16T07:00:00Z"
  end_time = "2016-01-16T13:00:00Z"
}

@stack72
Copy link
Contributor

stack72 commented Jan 15, 2016

thanks @AirbornePorcine, I will submit a PR to fix this shortly

@stack72
Copy link
Contributor

stack72 commented Jan 15, 2016

@AirbornePorcine ok, I have been able to add a test to prove this is the case. unfortunately, I believe this is actually a known bug and will need solving in Terraform core

I have opened a PR with the test to show the issue to the core team #4693

@jangrewe
Copy link

Just wanted to leave a "me too!" note, as i was trying to shut down our integration/staging environments over night and now have 1 instance still running ;-)

@stack72
Copy link
Contributor

stack72 commented Jan 28, 2016

@AirbornePorcine (and @jangrewe) so a PR has just been merged that sets default values for min_size, max_size and desired_capacity to 0. This means that your 0 will now work by default :)

Hope this helps!

@stack72 stack72 closed this as completed Jan 28, 2016
@jangrewe
Copy link

It does, thanks! =)

@AirbornePorcine
Copy link
Author

Thanks, works for us!

@daveadams
Copy link
Contributor

Unfortunately this "fix" broke our use case for this resource. We don't want to specify desired_capacity or max_size in our scheduled action. But thanks to the default of zero, we now get an error that desired_capacity cannot be less than min_size.

@ghost
Copy link

ghost commented Apr 27, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants