provider/aws: Convert AWS AutoScalingGroup to awslabs/aws-sdk-go

This commit is contained in:
Clint Shryock 2015-02-20 11:28:20 -06:00
parent 08949866c5
commit b38a3767eb
3 changed files with 27 additions and 28 deletions

View File

@ -7,13 +7,14 @@ import (
"unicode"
"github.com/hashicorp/terraform/helper/multierror"
"github.com/mitchellh/goamz/autoscaling"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb"
"github.com/mitchellh/goamz/rds"
awsGo "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/autoscaling"
awsAutoScaling "github.com/awslabs/aws-sdk-go/gen/autoscaling"
"github.com/awslabs/aws-sdk-go/gen/route53"
"github.com/awslabs/aws-sdk-go/gen/s3"
)
@ -32,6 +33,7 @@ type AWSClient struct {
rdsconn *rds.Rds
r53conn *route53.Route53
region string
awsAutoScalingconn *awsAutoScaling.AutoScaling
}
// Client configures and returns a fully initailized AWSClient
@ -64,6 +66,8 @@ func (c *Config) Client() (interface{}, error) {
client.ec2conn = ec2.New(auth, region)
log.Println("[INFO] Initializing ELB connection")
client.elbconn = elb.New(auth, region)
log.Println("[INFO] Initializing AutoScaling connection")
client.autoscalingconn = autoscaling.New(auth, region)
log.Println("[INFO] Initializing S3 connection")
client.s3conn = s3.New(creds, c.Region, nil)
log.Println("[INFO] Initializing RDS connection")
@ -74,8 +78,8 @@ func (c *Config) Client() (interface{}, error) {
// See http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html
log.Println("[INFO] Initializing Route53 connection")
client.r53conn = route53.New(creds, "us-east-1", nil)
log.Println("[INFO] Initializing AutoScaling connection")
client.autoscalingconn = autoscaling.New(creds, c.Region, nil)
log.Println("[INFO] Initializing AWS Go AutoScaling connection")
client.awsAutoScalingconn = awsAutoScaling.New(creds, c.Region, nil)
}
if len(errs) > 0 {

View File

@ -123,7 +123,7 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
}
func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn
autoscalingconn := meta.(*AWSClient).awsAutoScalingconn
var autoScalingGroupOpts autoscaling.CreateAutoScalingGroupType
autoScalingGroupOpts.AutoScalingGroupName = aws.String(d.Get("name").(string))
@ -201,7 +201,7 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e
}
func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn
autoscalingconn := meta.(*AWSClient).awsAutoScalingconn
opts := autoscaling.UpdateAutoScalingGroupType{
AutoScalingGroupName: aws.String(d.Id()),
@ -234,7 +234,7 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
}
func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn
autoscalingconn := meta.(*AWSClient).awsAutoScalingconn
// Read the autoscaling group first. If it doesn't exist, we're done.
// We need the group in order to check if there are instances attached.
@ -278,7 +278,7 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
func getAwsAutoscalingGroup(
d *schema.ResourceData,
meta interface{}) (*autoscaling.AutoScalingGroup, error) {
autoscalingconn := meta.(*AWSClient).autoscalingconn
autoscalingconn := meta.(*AWSClient).awsAutoScalingconn
describeOpts := autoscaling.AutoScalingGroupNamesType{
AutoScalingGroupNames: []string{d.Id()},
@ -298,7 +298,7 @@ func getAwsAutoscalingGroup(
// Search for the autoscaling group
for idx, asc := range describeGroups.AutoScalingGroups {
if asc.Name == d.Id() {
if *asc.AutoScalingGroupName == d.Id() {
return &describeGroups.AutoScalingGroups[idx], nil
}
}
@ -309,20 +309,17 @@ func getAwsAutoscalingGroup(
}
func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{}) error {
autoscalingconn := meta.(*AWSClient).autoscalingconn
autoscalingconn := meta.(*AWSClient).awsAutoScalingconn
// First, set the capacity to zero so the group will drain
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
opts := autoscaling.UpdateAutoScalingGroup{
Name: d.Id(),
DesiredCapacity: 0,
MinSize: 0,
MaxSize: 0,
SetDesiredCapacity: true,
SetMinSize: true,
SetMaxSize: true,
opts := autoscaling.UpdateAutoScalingGroupType{
AutoScalingGroupName: aws.String(d.Id()),
DesiredCapacity: aws.Integer(0),
MinSize: aws.Integer(0),
MaxSize: aws.Integer(0),
}
if _, err := autoscalingconn.UpdateAutoScalingGroup(&opts); err != nil {
if err := autoscalingconn.UpdateAutoScalingGroup(&opts); err != nil {
return fmt.Errorf("Error setting capacity to zero to drain: %s", err)
}

View File

@ -6,9 +6,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
_ "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/autoscaling"
"github.com/mitchellh/goamz/autoscaling"
)
func TestAccAWSAutoScalingGroup_basic(t *testing.T) {