-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial CRUD work for the Autoscaling Group Scheduled Actions
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 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
102 changes: 102 additions & 0 deletions
102
builtin/providers/aws/resource_aws_autoscaling_schedule.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,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 | ||
} |