Merge branch 'f-aws-upstream-s3'
* f-aws-upstream-s3: provider/aws: Conver AWS S3 to upstream sdk
This commit is contained in:
commit
c59bfd0ca5
|
@ -8,9 +8,9 @@ import (
|
||||||
|
|
||||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
|
||||||
|
|
||||||
awsSDK "github.com/awslabs/aws-sdk-go/aws"
|
awsSDK "github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
|
@ -71,7 +71,7 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
client.elbconn = elb.New(awsConfig)
|
client.elbconn = elb.New(awsConfig)
|
||||||
|
|
||||||
log.Println("[INFO] Initializing S3 connection")
|
log.Println("[INFO] Initializing S3 connection")
|
||||||
client.s3conn = s3.New(creds, c.Region, nil)
|
client.s3conn = s3.New(awsConfig)
|
||||||
|
|
||||||
log.Println("[INFO] Initializing EC2 Connection")
|
log.Println("[INFO] Initializing EC2 Connection")
|
||||||
client.ec2conn = ec2.New(creds, c.Region, nil)
|
client.ec2conn = ec2.New(creds, c.Region, nil)
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsS3Bucket() *schema.Resource {
|
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)
|
log.Printf("[DEBUG] S3 bucket create: %s, ACL: %s", bucket, acl)
|
||||||
|
|
||||||
req := &s3.CreateBucketRequest{
|
req := &s3.CreateBucketInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
ACL: aws.String(acl),
|
ACL: aws.String(acl),
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func resourceAwsS3BucketUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
s3conn := meta.(*AWSClient).s3conn
|
s3conn := meta.(*AWSClient).s3conn
|
||||||
|
|
||||||
err := s3conn.HeadBucket(&s3.HeadBucketRequest{
|
_, err := s3conn.HeadBucket(&s3.HeadBucketInput{
|
||||||
Bucket: aws.String(d.Id()),
|
Bucket: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,7 +104,7 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
s3conn := meta.(*AWSClient).s3conn
|
s3conn := meta.(*AWSClient).s3conn
|
||||||
|
|
||||||
log.Printf("[DEBUG] S3 Delete Bucket: %s", d.Id())
|
log.Printf("[DEBUG] S3 Delete Bucket: %s", d.Id())
|
||||||
err := s3conn.DeleteBucket(&s3.DeleteBucketRequest{
|
_, err := s3conn.DeleteBucket(&s3.DeleteBucketInput{
|
||||||
Bucket: aws.String(d.Id()),
|
Bucket: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSS3Bucket(t *testing.T) {
|
func TestAccAWSS3Bucket(t *testing.T) {
|
||||||
|
@ -37,7 +37,7 @@ func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
|
||||||
if rs.Type != "aws_s3_bucket" {
|
if rs.Type != "aws_s3_bucket" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := conn.DeleteBucket(&s3.DeleteBucketRequest{
|
_, err := conn.DeleteBucket(&s3.DeleteBucketInput{
|
||||||
Bucket: aws.String(rs.Primary.ID),
|
Bucket: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -59,7 +59,7 @@ func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
||||||
err := conn.HeadBucket(&s3.HeadBucketRequest{
|
_, err := conn.HeadBucket(&s3.HeadBucketInput{
|
||||||
Bucket: aws.String(rs.Primary.ID),
|
Bucket: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/xml"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +20,7 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error {
|
||||||
// Set tags
|
// Set tags
|
||||||
if len(remove) > 0 {
|
if len(remove) > 0 {
|
||||||
log.Printf("[DEBUG] Removing tags: %#v", remove)
|
log.Printf("[DEBUG] Removing tags: %#v", remove)
|
||||||
err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingRequest{
|
_, err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{
|
||||||
Bucket: aws.String(d.Get("bucket").(string)),
|
Bucket: aws.String(d.Get("bucket").(string)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,30 +29,14 @@ func setTagsS3(conn *s3.S3, d *schema.ResourceData) error {
|
||||||
}
|
}
|
||||||
if len(create) > 0 {
|
if len(create) > 0 {
|
||||||
log.Printf("[DEBUG] Creating tags: %#v", create)
|
log.Printf("[DEBUG] Creating tags: %#v", create)
|
||||||
tagging := s3.Tagging{
|
req := &s3.PutBucketTaggingInput{
|
||||||
TagSet: create,
|
Bucket: aws.String(d.Get("bucket").(string)),
|
||||||
XMLName: xml.Name{
|
Tagging: &s3.Tagging{
|
||||||
Space: "http://s3.amazonaws.com/doc/2006-03-01/",
|
TagSet: create,
|
||||||
Local: "Tagging",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// 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{
|
_, err := conn.PutBucketTagging(req)
|
||||||
Bucket: aws.String(d.Get("bucket").(string)),
|
|
||||||
ContentMD5: aws.String(base),
|
|
||||||
Tagging: &tagging,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = conn.PutBucketTagging(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// 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
|
// the set of tags that must be created, and the set of tags that must
|
||||||
// be destroyed.
|
// 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
|
// First, we're creating everything we have
|
||||||
create := make(map[string]interface{})
|
create := make(map[string]interface{})
|
||||||
for _, t := range newTags {
|
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
|
// Build the list of what to remove
|
||||||
var remove []s3.Tag
|
var remove []*s3.Tag
|
||||||
for _, t := range oldTags {
|
for _, t := range oldTags {
|
||||||
old, ok := create[*t.Key]
|
old, ok := create[*t.Key]
|
||||||
if !ok || old != *t.Value {
|
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.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func tagsFromMapS3(m map[string]interface{}) []s3.Tag {
|
func tagsFromMapS3(m map[string]interface{}) []*s3.Tag {
|
||||||
result := make([]s3.Tag, 0, len(m))
|
result := make([]*s3.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
result = append(result, s3.Tag{
|
result = append(result, &s3.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(v.(string)),
|
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.
|
// 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)
|
result := make(map[string]string)
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
result[*t.Key] = *t.Value
|
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
|
// 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
|
// s3.GetBucketTagging, except returns an empty slice instead of an error when
|
||||||
// there are no tags.
|
// there are no tags.
|
||||||
func getTagSetS3(s3conn *s3.S3, bucket string) ([]s3.Tag, error) {
|
func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) {
|
||||||
request := &s3.GetBucketTaggingRequest{
|
request := &s3.GetBucketTaggingInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s3conn.GetBucketTagging(request)
|
response, err := s3conn.GetBucketTagging(request)
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" {
|
||||||
// There is no tag set associated with the bucket.
|
// There is no tag set associated with the bucket.
|
||||||
return []s3.Tag{}, nil
|
return []*s3.Tag{}, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"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.
|
// testAccCheckTags can be used to check the tags on a resource.
|
||||||
func testAccCheckTagsS3(
|
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 {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMapS3(*ts)
|
m := tagsToMapS3(*ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
|
|
Loading…
Reference in New Issue