From eb82f2bf2ad5a5c29057a59c20b51baa35677c87 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Mon, 6 Apr 2015 12:14:12 -0500 Subject: [PATCH] provider/aws: Convert Key Pair to upstream aws-sdk-go --- builtin/providers/aws/config.go | 5 ++++ .../providers/aws/resource_aws_key_pair.go | 26 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 7e84d3a27..0811d86a5 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -14,6 +14,9 @@ import ( "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" ) type Config struct { @@ -32,6 +35,7 @@ type AWSClient struct { region string rdsconn *rds.RDS iamconn *iam.IAM + ec2SDKconn *awsEC2.EC2 } // Client configures and returns a fully initailized AWSClient @@ -74,6 +78,7 @@ func (c *Config) Client() (interface{}, error) { client.ec2conn = ec2.New(creds, c.Region, nil) client.iamconn = iam.New(creds, c.Region, nil) + client.ec2SDKconn = awsEC2.New(&awsSDK.Config{Region: "us-west-2"}) } if len(errs) > 0 { diff --git a/builtin/providers/aws/resource_aws_key_pair.go b/builtin/providers/aws/resource_aws_key_pair.go index e96ecf620..2a96c916b 100644 --- a/builtin/providers/aws/resource_aws_key_pair.go +++ b/builtin/providers/aws/resource_aws_key_pair.go @@ -1,13 +1,12 @@ package aws import ( - "encoding/base64" "fmt" "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/ec2" + awsSDK "github.com/awslabs/aws-sdk-go/aws" + awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2" ) func resourceAwsKeyPair() *schema.Resource { @@ -37,13 +36,13 @@ func resourceAwsKeyPair() *schema.Resource { } func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + ec2conn := meta.(*AWSClient).ec2SDKconn keyName := d.Get("key_name").(string) publicKey := d.Get("public_key").(string) - req := &ec2.ImportKeyPairRequest{ - KeyName: aws.String(keyName), - PublicKeyMaterial: []byte(base64.StdEncoding.EncodeToString([]byte(publicKey))), + req := &awsEC2.ImportKeyPairInput{ + KeyName: awsSDK.String(keyName), + PublicKeyMaterial: []byte(publicKey), } resp, err := ec2conn.ImportKeyPair(req) if err != nil { @@ -55,10 +54,9 @@ func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error { } func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn - - req := &ec2.DescribeKeyPairsRequest{ - KeyNames: []string{d.Id()}, + ec2conn := meta.(*AWSClient).ec2SDKconn + req := &awsEC2.DescribeKeyPairsInput{ + KeyNames: []*string{awsSDK.String(d.Id())}, } resp, err := ec2conn.DescribeKeyPairs(req) if err != nil { @@ -77,10 +75,10 @@ func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error { } func resourceAwsKeyPairDelete(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + ec2conn := meta.(*AWSClient).ec2SDKconn - err := ec2conn.DeleteKeyPair(&ec2.DeleteKeyPairRequest{ - KeyName: aws.String(d.Id()), + _, err := ec2conn.DeleteKeyPair(&awsEC2.DeleteKeyPairInput{ + KeyName: awsSDK.String(d.Id()), }) return err }