diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 37718f9f1..177ef391b 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -16,7 +16,9 @@ import ( "github.com/hashicorp/aws-sdk-go/gen/s3" awsSDK "github.com/awslabs/aws-sdk-go/aws" + awsIAM "github.com/awslabs/aws-sdk-go/service/IAM" awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2" + awsRDS "github.com/awslabs/aws-sdk-go/service/rds" ) type Config struct { @@ -36,6 +38,8 @@ type AWSClient struct { rdsconn *rds.RDS iamconn *iam.IAM ec2SDKconn *awsEC2.EC2 + rdsSDKconn *awsRDS.RDS + iamSDKconn *awsIAM.IAM } // Client configures and returns a fully initailized AWSClient @@ -60,12 +64,15 @@ func (c *Config) Client() (interface{}, error) { log.Println("[INFO] Building AWS auth structure") creds := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token) + log.Println("[INFO] Building AWS SDK auth structure") sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token) - log.Println("[INFO] Initializing ELB connection") - client.elbconn = elb.New(&awsSDK.Config{ + awsConfig := &awsSDK.Config{ Credentials: sdkCreds, Region: c.Region, - }) + } + + log.Println("[INFO] Initializing ELB SDK connection") + client.elbconn = elb.New(awsConfig) log.Println("[INFO] Initializing AutoScaling connection") client.autoscalingconn = autoscaling.New(creds, c.Region, nil) @@ -81,12 +88,15 @@ func (c *Config) Client() (interface{}, error) { client.r53conn = route53.New(creds, "us-east-1", nil) log.Println("[INFO] Initializing EC2 Connection") client.ec2conn = ec2.New(creds, c.Region, nil) - client.iamconn = iam.New(creds, c.Region, nil) - client.ec2SDKconn = awsEC2.New(&awsSDK.Config{ - Credentials: sdkCreds, - Region: c.Region, - }) + log.Println("[INFO] Initializing EC2 SDK Connection") + client.ec2SDKconn = awsEC2.New(awsConfig) + + log.Println("[INFO] Initializing RDS SDK Connection") + client.rdsSDKconn = awsRDS.New(awsConfig) + + log.Println("[INFO] Initializing IAM SDK Connection") + client.iamSDKconn = awsIAM.New(awsConfig) } if len(errs) > 0 { diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 267f51aef..ff71ad2a0 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -5,9 +5,9 @@ import ( "log" "time" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/iam" - "github.com/hashicorp/aws-sdk-go/gen/rds" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/IAM" + "github.com/awslabs/aws-sdk-go/service/rds" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" @@ -194,10 +194,10 @@ func resourceAwsDbInstance() *schema.Resource { } func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).rdsconn + conn := meta.(*AWSClient).rdsSDKconn tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{})) - opts := rds.CreateDBInstanceMessage{ - AllocatedStorage: aws.Integer(d.Get("allocated_storage").(int)), + opts := rds.CreateDBInstanceInput{ + AllocatedStorage: aws.Long(int64(d.Get("allocated_storage").(int))), DBInstanceClass: aws.String(d.Get("instance_class").(string)), DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), DBName: aws.String(d.Get("name").(string)), @@ -214,14 +214,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } attr := d.Get("backup_retention_period") - opts.BackupRetentionPeriod = aws.Integer(attr.(int)) + opts.BackupRetentionPeriod = aws.Long(int64(attr.(int))) if attr, ok := d.GetOk("iops"); ok { - opts.IOPS = aws.Integer(attr.(int)) + opts.IOPS = aws.Long(int64(attr.(int))) } if attr, ok := d.GetOk("port"); ok { - opts.Port = aws.Integer(attr.(int)) + opts.Port = aws.Long(int64(attr.(int))) } if attr, ok := d.GetOk("multi_az"); ok { @@ -253,17 +253,17 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { - var s []string + var s []*string for _, v := range attr.List() { - s = append(s, v.(string)) + s = append(s, aws.String(v.(string))) } opts.VPCSecurityGroupIDs = s } if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 { - var s []string + var s []*string for _, v := range attr.List() { - s = append(s, v.(string)) + s = append(s, aws.String(v.(string))) } opts.DBSecurityGroups = s } @@ -345,7 +345,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { // list tags for resource // set tags - conn := meta.(*AWSClient).rdsconn + conn := meta.(*AWSClient).rdsSDKconn arn, err := buildRDSARN(d, meta) if err != nil { name := "" @@ -355,7 +355,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Error building ARN for DB Instance, not setting Tags for DB %s", name) } else { - resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceMessage{ + resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: aws.String(arn), }) @@ -363,7 +363,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Error retreiving tags for ARN: %s", arn) } - var dt []rds.Tag + var dt []*rds.Tag if len(resp.TagList) > 0 { dt = resp.TagList } @@ -396,11 +396,11 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { } func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).rdsconn + conn := meta.(*AWSClient).rdsSDKconn log.Printf("[DEBUG] DB Instance destroy: %v", d.Id()) - opts := rds.DeleteDBInstanceMessage{DBInstanceIdentifier: aws.String(d.Id())} + opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())} finalSnapshot := d.Get("final_snapshot_identifier").(string) if finalSnapshot == "" { @@ -433,11 +433,11 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error } func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).rdsconn + conn := meta.(*AWSClient).rdsSDKconn d.Partial(true) - req := &rds.ModifyDBInstanceMessage{ + req := &rds.ModifyDBInstanceInput{ ApplyImmediately: aws.Boolean(d.Get("apply_immediately").(bool)), DBInstanceIdentifier: aws.String(d.Id()), } @@ -445,11 +445,11 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error if d.HasChange("allocated_storage") { d.SetPartial("allocated_storage") - req.AllocatedStorage = aws.Integer(d.Get("allocated_storage").(int)) + req.AllocatedStorage = aws.Long(int64(d.Get("allocated_storage").(int))) } if d.HasChange("backup_retention_period") { d.SetPartial("backup_retention_period") - req.BackupRetentionPeriod = aws.Integer(d.Get("backup_retention_period").(int)) + req.BackupRetentionPeriod = aws.Long(int64(d.Get("backup_retention_period").(int))) } if d.HasChange("instance_class") { d.SetPartial("instance_class") @@ -465,7 +465,7 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("iops") { d.SetPartial("iops") - req.IOPS = aws.Integer(d.Get("iops").(int)) + req.IOPS = aws.Long(int64(d.Get("iops").(int))) } if d.HasChange("backup_window") { d.SetPartial("backup_window") @@ -490,9 +490,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error if d.HasChange("vpc_security_group_ids") { if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { - var s []string + var s []*string for _, v := range attr.List() { - s = append(s, v.(string)) + s = append(s, aws.String(v.(string))) } req.VPCSecurityGroupIDs = s } @@ -500,9 +500,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error if d.HasChange("vpc_security_group_ids") { if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 { - var s []string + var s []*string for _, v := range attr.List() { - s = append(s, v.(string)) + s = append(s, aws.String(v.(string))) } req.DBSecurityGroups = s } @@ -527,9 +527,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error func resourceAwsBbInstanceRetrieve( d *schema.ResourceData, meta interface{}) (*rds.DBInstance, error) { - conn := meta.(*AWSClient).rdsconn + conn := meta.(*AWSClient).rdsSDKconn - opts := rds.DescribeDBInstancesMessage{ + opts := rds.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(d.Id()), } @@ -552,9 +552,7 @@ func resourceAwsBbInstanceRetrieve( } } - v := resp.DBInstances[0] - - return &v, nil + return resp.DBInstances[0], nil } func resourceAwsDbInstanceStateRefreshFunc( @@ -576,10 +574,10 @@ func resourceAwsDbInstanceStateRefreshFunc( } func buildRDSARN(d *schema.ResourceData, meta interface{}) (string, error) { - iamconn := meta.(*AWSClient).iamconn + iamconn := meta.(*AWSClient).iamSDKconn region := meta.(*AWSClient).region - // An zero value GetUserRequest{} defers to the currently logged in user - resp, err := iamconn.GetUser(&iam.GetUserRequest{}) + // An zero value GetUserInput{} defers to the currently logged in user + resp, err := iamconn.GetUser(&iam.GetUserInput{}) if err != nil { return "", err } diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index ba86d005a..49156be50 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -9,8 +9,8 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/rds" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/rds" ) func TestAccAWSDBInstance(t *testing.T) { @@ -47,7 +47,7 @@ func TestAccAWSDBInstance(t *testing.T) { } func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).rdsconn + conn := testAccProvider.Meta().(*AWSClient).rdsSDKconn for _, rs := range s.RootModule().Resources { if rs.Type != "aws_db_instance" { @@ -56,7 +56,7 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { // Try to find the Group resp, err := conn.DescribeDBInstances( - &rds.DescribeDBInstancesMessage{ + &rds.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(rs.Primary.ID), }) @@ -110,9 +110,9 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC return fmt.Errorf("No DB Instance ID is set") } - conn := testAccProvider.Meta().(*AWSClient).rdsconn + conn := testAccProvider.Meta().(*AWSClient).rdsSDKconn - opts := rds.DescribeDBInstancesMessage{ + opts := rds.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(rs.Primary.ID), } @@ -127,7 +127,7 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC return fmt.Errorf("DB Instance not found") } - *v = resp.DBInstances[0] + *v = *resp.DBInstances[0] return nil } diff --git a/builtin/providers/aws/tagsRDS.go b/builtin/providers/aws/tagsRDS.go index 8eb592427..845a5db3a 100644 --- a/builtin/providers/aws/tagsRDS.go +++ b/builtin/providers/aws/tagsRDS.go @@ -3,8 +3,8 @@ package aws import ( "log" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/rds" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/rds" "github.com/hashicorp/terraform/helper/schema" ) @@ -20,12 +20,12 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) error { // Set tags if len(remove) > 0 { log.Printf("[DEBUG] Removing tags: %#v", remove) - k := make([]string, len(remove), len(remove)) + k := make([]*string, len(remove), len(remove)) for i, t := range remove { - k[i] = *t.Key + k[i] = t.Key } - err := conn.RemoveTagsFromResource(&rds.RemoveTagsFromResourceMessage{ + _, err := conn.RemoveTagsFromResource(&rds.RemoveTagsFromResourceInput{ ResourceName: aws.String(arn), TagKeys: k, }) @@ -35,7 +35,7 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) error { } if len(create) > 0 { log.Printf("[DEBUG] Creating tags: %#v", create) - err := conn.AddTagsToResource(&rds.AddTagsToResourceMessage{ + _, err := conn.AddTagsToResource(&rds.AddTagsToResourceInput{ ResourceName: aws.String(arn), Tags: create, }) @@ -51,7 +51,7 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) error { // diffTags takes our tags locally and the ones remotely and returns // the set of tags that must be created, and the set of tags that must // be destroyed. -func diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) { +func diffTagsRDS(oldTags, newTags []*rds.Tag) ([]*rds.Tag, []*rds.Tag) { // First, we're creating everything we have create := make(map[string]interface{}) for _, t := range newTags { @@ -59,7 +59,7 @@ func diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) { } // Build the list of what to remove - var remove []rds.Tag + var remove []*rds.Tag for _, t := range oldTags { old, ok := create[*t.Key] if !ok || old != *t.Value { @@ -72,10 +72,10 @@ func diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) { } // tagsFromMap returns the tags for the given map of data. -func tagsFromMapRDS(m map[string]interface{}) []rds.Tag { - result := make([]rds.Tag, 0, len(m)) +func tagsFromMapRDS(m map[string]interface{}) []*rds.Tag { + result := make([]*rds.Tag, 0, len(m)) for k, v := range m { - result = append(result, rds.Tag{ + result = append(result, &rds.Tag{ Key: aws.String(k), Value: aws.String(v.(string)), }) @@ -85,7 +85,7 @@ func tagsFromMapRDS(m map[string]interface{}) []rds.Tag { } // tagsToMap turns the list of tags into a map. -func tagsToMapRDS(ts []rds.Tag) map[string]string { +func tagsToMapRDS(ts []*rds.Tag) map[string]string { result := make(map[string]string) for _, t := range ts { result[*t.Key] = *t.Value diff --git a/builtin/providers/aws/tagsRDS_test.go b/builtin/providers/aws/tagsRDS_test.go index 1d9da8357..8321d13ef 100644 --- a/builtin/providers/aws/tagsRDS_test.go +++ b/builtin/providers/aws/tagsRDS_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/aws-sdk-go/gen/rds" + "github.com/awslabs/aws-sdk-go/service/rds" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -63,9 +63,9 @@ func TestDiffRDSTags(t *testing.T) { // testAccCheckTags can be used to check the tags on a resource. func testAccCheckRDSTags( - ts *[]rds.Tag, key string, value string) resource.TestCheckFunc { + ts []*rds.Tag, key string, value string) resource.TestCheckFunc { return func(s *terraform.State) error { - m := tagsToMapRDS(*ts) + m := tagsToMapRDS(ts) v, ok := m[key] if value != "" && !ok { return fmt.Errorf("Missing tag: %s", key)