-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a resource for aws_autoscaling_schedule
- Loading branch information
Showing
5 changed files
with
263 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
builtin/providers/aws/resource_aws_autoscaling_schedule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/autoscaling" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAWSAutoscalingSchedule_basic(t *testing.T) { | ||
var schedule autoscaling.ScheduledUpdateGroupAction | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccAWSAutoscalingScheduleConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckScalingScheduleExists(n string, policy *autoscaling.ScheduledUpdateGroupAction) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
autoScalingGroup, _ := rs.Primary.Attributes["autoscaling_group_name"] | ||
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn | ||
params := &autoscaling.DescribeScheduledActionsInput{ | ||
AutoScalingGroupName: aws.String(autoScalingGroup), | ||
ScheduledActionNames: []*string{aws.String(rs.Primary.ID)}, | ||
} | ||
|
||
resp, err := conn.DescribeScheduledActions(params) | ||
if err != nil { | ||
return err | ||
} | ||
if len(resp.ScheduledUpdateGroupActions) == 0 { | ||
return fmt.Errorf("Scaling Schedule not found") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSAutoscalingScheduleDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_autoscaling_schedule" { | ||
continue | ||
} | ||
|
||
autoScalingGroup, _ := rs.Primary.Attributes["autoscaling_group_name"] | ||
params := &autoscaling.DescribeScheduledActionsInput{ | ||
AutoScalingGroupName: aws.String(autoScalingGroup), | ||
ScheduledActionNames: []*string{aws.String(rs.Primary.ID)}, | ||
} | ||
|
||
resp, err := conn.DescribeScheduledActions(params) | ||
|
||
if err == nil { | ||
if len(resp.ScheduledUpdateGroupActions) != 0 && | ||
*resp.ScheduledUpdateGroupActions[0].ScheduledActionName == rs.Primary.ID { | ||
return fmt.Errorf("Scaling Schedule Still Exists: %s", rs.Primary.ID) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
var testAccAWSAutoscalingScheduleConfig = fmt.Sprintf(` | ||
resource "aws_launch_configuration" "foobar" { | ||
name = "terraform-test-foobar5" | ||
image_id = "ami-21f78e11" | ||
instance_type = "t1.micro" | ||
} | ||
resource "aws_autoscaling_group" "foobar" { | ||
availability_zones = ["us-west-2a"] | ||
name = "terraform-test-foobar5" | ||
max_size = 1 | ||
min_size = 1 | ||
health_check_grace_period = 300 | ||
health_check_type = "ELB" | ||
force_delete = true | ||
termination_policies = ["OldestInstance"] | ||
launch_configuration = "${aws_launch_configuration.foobar.name}" | ||
tag { | ||
key = "Foo" | ||
value = "foo-bar" | ||
propagate_at_launch = true | ||
} | ||
} | ||
resource "aws_autoscaling_schedule" "foobar" { | ||
scheduled_action_name = "foobar" | ||
min_size = 0 | ||
max_size = 1 | ||
desired_capacity = 0 | ||
start_time = "2016-12-11T18:00:00Z" | ||
end_time = "2016-12-12T06:00:00Z" | ||
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}" | ||
} | ||
`) |
55 changes: 55 additions & 0 deletions
55
website/source/docs/providers/aws/r/autoscaling_schedule.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_autoscaling_schedule" | ||
sidebar_current: "docs-aws-resource-autoscaling-schedule" | ||
description: |- | ||
Provides an AutoScaling Schedule resource. | ||
--- | ||
|
||
# aws\_autoscaling\_schedule | ||
|
||
Provides an AutoScaling Schedule resource. | ||
|
||
## Example Usage | ||
``` | ||
resource "aws_autoscaling_group" "foobar" { | ||
availability_zones = ["us-west-2a"] | ||
name = "terraform-test-foobar5" | ||
max_size = 1 | ||
min_size = 1 | ||
health_check_grace_period = 300 | ||
health_check_type = "ELB" | ||
force_delete = true | ||
termination_policies = ["OldestInstance"] | ||
} | ||
resource "aws_autoscaling_schedule" "foobar" { | ||
scheduled_action_name = "foobar" | ||
min_size = 0 | ||
max_size = 1 | ||
desired_capacity = 0 | ||
start_time = "2016-12-11T18:00:00Z" | ||
end_time = "2016-12-12T06:00:00Z" | ||
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `autoscaling_group_name` - (Required) The name or Amazon Resource Name (ARN) of the Auto Scaling group. | ||
* `scheduled_action_name` - (Required) The name of this scaling action. | ||
* `start_time` - (Optional) The time for this action to start, in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only (for example, 2014-06-01T00:00:00Z ). | ||
If you try to schedule your action in the past, Auto Scaling returns an error message. | ||
* `end_time` - (Optional) The time for this action to end, in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only (for example, 2014-06-01T00:00:00Z ). | ||
If you try to schedule your action in the past, Auto Scaling returns an error messag | ||
* `recurrence` - (Optional) The time when recurring future actions will start. Start time is specified by the user following the Unix cron syntax format. | ||
* `min_size` - (Optional) The minimum size for the Auto Scaling group. | ||
* `max_size` - (Optional) The maximum size for the Auto Scaling group. | ||
* `desired_capacity` - (Optional) The number of EC2 instances that should be running in the group. | ||
|
||
~> **NOTE:** When `start_time` and `end_time` are specified with `recurrence` , they form the boundaries of when the recurring action will start and stop. | ||
|
||
## Attribute Reference | ||
* `arn` - The ARN assigned by AWS to the autoscaling schedule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters