diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index abcbc412c..13f28bd02 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform/helper/multierror" + "github.com/awslabs/aws-sdk-go/service/s3" "github.com/hashicorp/aws-sdk-go/aws" "github.com/hashicorp/aws-sdk-go/gen/autoscaling" "github.com/hashicorp/aws-sdk-go/gen/ec2" @@ -13,7 +14,6 @@ import ( "github.com/hashicorp/aws-sdk-go/gen/iam" "github.com/hashicorp/aws-sdk-go/gen/rds" "github.com/hashicorp/aws-sdk-go/gen/route53" - "github.com/hashicorp/aws-sdk-go/gen/s3" awsSDK "github.com/awslabs/aws-sdk-go/aws" awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2" @@ -59,13 +59,18 @@ 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(creds, c.Region, nil) log.Println("[INFO] Initializing AutoScaling connection") client.autoscalingconn = autoscaling.New(creds, c.Region, nil) log.Println("[INFO] Initializing S3 connection") - client.s3conn = s3.New(creds, c.Region, nil) + client.s3conn = s3.New(&awsSDK.Config{ + Credentials: sdkCreds, + Region: c.Region, + }) log.Println("[INFO] Initializing RDS connection") client.rdsconn = rds.New(creds, c.Region, nil) @@ -78,7 +83,6 @@ func (c *Config) Client() (interface{}, error) { client.ec2conn = ec2.New(creds, c.Region, nil) client.iamconn = iam.New(creds, c.Region, nil) - sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token) client.ec2SDKconn = awsEC2.New(&awsSDK.Config{ Credentials: sdkCreds, Region: c.Region, diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index a33f9b35f..2d2e022d2 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -6,8 +6,8 @@ import ( "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/s3" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/s3" ) func resourceAwsS3Bucket() *schema.Resource { @@ -46,7 +46,7 @@ func resourceAwsS3BucketCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] S3 bucket create: %s, ACL: %s", bucket, acl) - req := &s3.CreateBucketRequest{ + req := &s3.CreateBucketInput{ Bucket: aws.String(bucket), ACL: aws.String(acl), } @@ -81,7 +81,7 @@ func resourceAwsS3BucketUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { s3conn := meta.(*AWSClient).s3conn - err := s3conn.HeadBucket(&s3.HeadBucketRequest{ + _, err := s3conn.HeadBucket(&s3.HeadBucketInput{ Bucket: aws.String(d.Id()), }) if err != nil { @@ -104,7 +104,7 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error { s3conn := meta.(*AWSClient).s3conn log.Printf("[DEBUG] S3 Delete Bucket: %s", d.Id()) - err := s3conn.DeleteBucket(&s3.DeleteBucketRequest{ + _, err := s3conn.DeleteBucket(&s3.DeleteBucketInput{ Bucket: aws.String(d.Id()), }) if err != nil { diff --git a/builtin/providers/aws/resource_aws_s3_bucket_test.go b/builtin/providers/aws/resource_aws_s3_bucket_test.go index bb4432c9d..4e396801d 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_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/s3" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/s3" ) func TestAccAWSS3Bucket(t *testing.T) { @@ -37,7 +37,7 @@ func testAccCheckAWSS3BucketDestroy(s *terraform.State) error { if rs.Type != "aws_s3_bucket" { continue } - err := conn.DeleteBucket(&s3.DeleteBucketRequest{ + _, err := conn.DeleteBucket(&s3.DeleteBucketInput{ Bucket: aws.String(rs.Primary.ID), }) if err != nil { @@ -59,7 +59,7 @@ func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc { } conn := testAccProvider.Meta().(*AWSClient).s3conn - err := conn.HeadBucket(&s3.HeadBucketRequest{ + _, err := conn.HeadBucket(&s3.HeadBucketInput{ Bucket: aws.String(rs.Primary.ID), }) diff --git a/builtin/providers/aws/s3_tags.go b/builtin/providers/aws/s3_tags.go index 4b8234b9b..388a2df7a 100644 --- a/builtin/providers/aws/s3_tags.go +++ b/builtin/providers/aws/s3_tags.go @@ -1,13 +1,10 @@ package aws import ( - "crypto/md5" - "encoding/base64" - "encoding/xml" "log" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/s3" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/s3" "github.com/hashicorp/terraform/helper/schema" ) @@ -23,7 +20,7 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error { // Set tags if len(remove) > 0 { log.Printf("[DEBUG] Removing tags: %#v", remove) - err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingRequest{ + _, err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{ Bucket: aws.String(d.Get("bucket").(string)), }) if err != nil { @@ -32,30 +29,14 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error { } if len(create) > 0 { log.Printf("[DEBUG] Creating tags: %#v", create) - tagging := s3.Tagging{ - TagSet: create, - XMLName: xml.Name{ - Space: "http://s3.amazonaws.com/doc/2006-03-01/", - Local: "Tagging", + req := &s3.PutBucketTaggingInput{ + Bucket: aws.String(d.Get("bucket").(string)), + Tagging: &s3.Tagging{ + TagSet: create, }, } - // AWS S3 API requires us to send a base64 encoded md5 hash of the - // content, which we need to build ourselves since aws-sdk-go does not. - b, err := xml.Marshal(tagging) - if err != nil { - return err - } - h := md5.New() - h.Write(b) - base := base64.StdEncoding.EncodeToString(h.Sum(nil)) - req := &s3.PutBucketTaggingRequest{ - Bucket: aws.String(d.Get("bucket").(string)), - ContentMD5: aws.String(base), - Tagging: &tagging, - } - - err = conn.PutBucketTagging(req) + _, err := conn.PutBucketTagging(req) if err != nil { return err } @@ -68,7 +49,7 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) 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 diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) { +func diffTagsS3(oldTags, newTags []*s3.Tag) ([]*s3.Tag, []*s3.Tag) { // First, we're creating everything we have create := make(map[string]interface{}) for _, t := range newTags { @@ -76,7 +57,7 @@ func diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) { } // Build the list of what to remove - var remove []s3.Tag + var remove []*s3.Tag for _, t := range oldTags { old, ok := create[*t.Key] if !ok || old != *t.Value { @@ -89,10 +70,10 @@ func diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) { } // tagsFromMap returns the tags for the given map of data. -func tagsFromMapS3(m map[string]interface{}) []s3.Tag { - result := make([]s3.Tag, 0, len(m)) +func tagsFromMapS3(m map[string]interface{}) []*s3.Tag { + result := make([]*s3.Tag, 0, len(m)) for k, v := range m { - result = append(result, s3.Tag{ + result = append(result, &s3.Tag{ Key: aws.String(k), Value: aws.String(v.(string)), }) @@ -102,7 +83,7 @@ func tagsFromMapS3(m map[string]interface{}) []s3.Tag { } // tagsToMap turns the list of tags into a map. -func tagsToMapS3(ts []s3.Tag) map[string]string { +func tagsToMapS3(ts []*s3.Tag) map[string]string { result := make(map[string]string) for _, t := range ts { result[*t.Key] = *t.Value @@ -114,15 +95,15 @@ func tagsToMapS3(ts []s3.Tag) map[string]string { // return a slice of s3 tags associated with the given s3 bucket. Essentially // s3.GetBucketTagging, except returns an empty slice instead of an error when // there are no tags. -func getTagSetS3(s3conn *s3.S3, bucket string) ([]s3.Tag, error) { - request := &s3.GetBucketTaggingRequest{ +func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) { + request := &s3.GetBucketTaggingInput{ Bucket: aws.String(bucket), } response, err := s3conn.GetBucketTagging(request) if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" { // There is no tag set associated with the bucket. - return []s3.Tag{}, nil + return []*s3.Tag{}, nil } else if err != nil { return nil, err } diff --git a/builtin/providers/aws/s3_tags_test.go b/builtin/providers/aws/s3_tags_test.go index 9b082c6e4..70c76cf0d 100644 --- a/builtin/providers/aws/s3_tags_test.go +++ b/builtin/providers/aws/s3_tags_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/aws-sdk-go/gen/s3" + "github.com/awslabs/aws-sdk-go/service/s3" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -63,7 +63,7 @@ func TestDiffTagsS3(t *testing.T) { // testAccCheckTags can be used to check the tags on a resource. func testAccCheckTagsS3( - ts *[]s3.Tag, key string, value string) resource.TestCheckFunc { + ts *[]*s3.Tag, key string, value string) resource.TestCheckFunc { return func(s *terraform.State) error { m := tagsToMapS3(*ts) v, ok := m[key]