Skip to content

Commit

Permalink
Initial CRUD work for the Autoscaling Group Scheduled Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 committed Dec 11, 2015
1 parent 3330da0 commit 9040111
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func Provider() terraform.ResourceProvider {
"aws_autoscaling_group": resourceAwsAutoscalingGroup(),
"aws_autoscaling_notification": resourceAwsAutoscalingNotification(),
"aws_autoscaling_policy": resourceAwsAutoscalingPolicy(),
"aws_autoscaling_schedule": resourceAwsAutoscalingSchedule(),
"aws_cloudformation_stack": resourceAwsCloudFormationStack(),
"aws_cloudtrail": resourceAwsCloudTrail(),
"aws_cloudwatch_log_group": resourceAwsCloudWatchLogGroup(),
Expand Down
102 changes: 102 additions & 0 deletions builtin/providers/aws/resource_aws_autoscaling_schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsAutoscalingSchedule() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAutoscalingScheduleCreate,
Read: resourceAwsAutoscalingScheduleRead,
Update: resourceAwsAutoscalingScheduleUpdate,
Delete: resourceAwsAutoscalingScheduleDelete,

Schema: map[string]*schema.Schema{
"scheduled_action_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"autoscaling_group_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"min_size": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"max_size": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"desired_capacity": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
},
}
}

func resourceAwsAutoscalingScheduleCreate(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn
params := autoscaling.PutScheduledUpdateGroupActionInput{
AutoScalingGroupName: aws.String(d.Get("autoscaling_group_name").(string)),
ScheduledActionName: aws.String(d.Get("scheduled_action_name").(string)),
}

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

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

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

log.Printf("[INFO] Creating Autoscaling Scheduled Action: %s", d.Get("scheduled_action_name").(string))
_, err := autoscalingconn.PutScheduledUpdateGroupAction(params)
if err != nil {
return fmt.Errorf("Error Creating Autoscaling Scheduled Action: %s", err.Error())
}

d.SetId(d.Get("scheduled_action_name").(string))

return resourceAwsAutoscalingScheduleRead(d, meta)
}

func resourceAwsAutoscalingScheduleRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceAwsAutoscalingScheduleUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceAwsAutoscalingScheduleDelete(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn

params := autoscaling.DeleteScheduledActionInput{
AutoScalingGroupName: aws.String(d.Get("autoscaling_group_name").(string)),
ScheduledActionName: aws.String(d.Get("scheduled_action_name").(string)),
}

log.Printf("[INFO] Deleting Autoscaling Scheduled Action: %s", d.Get("scheduled_action_name").(string))
_, err := autoscalingconn.DeleteScheduledAction(params)
if err != nil {
return fmt.Errorf("Error deleting Autoscaling Scheduled Action: %s", err.Error())
}

return nil
}

0 comments on commit 9040111

Please sign in to comment.