provider/aws: Convert Key Pair to upstream aws-sdk-go

This commit is contained in:
Clint Shryock 2015-04-06 12:14:12 -05:00
parent 2b294ddb81
commit eb82f2bf2a
2 changed files with 17 additions and 14 deletions

View File

@ -14,6 +14,9 @@ import (
"github.com/hashicorp/aws-sdk-go/gen/rds" "github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/aws-sdk-go/gen/route53" "github.com/hashicorp/aws-sdk-go/gen/route53"
"github.com/hashicorp/aws-sdk-go/gen/s3" "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 { type Config struct {
@ -32,6 +35,7 @@ type AWSClient struct {
region string region string
rdsconn *rds.RDS rdsconn *rds.RDS
iamconn *iam.IAM iamconn *iam.IAM
ec2SDKconn *awsEC2.EC2
} }
// Client configures and returns a fully initailized AWSClient // 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.ec2conn = ec2.New(creds, c.Region, nil)
client.iamconn = iam.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 { if len(errs) > 0 {

View File

@ -1,13 +1,12 @@
package aws package aws
import ( import (
"encoding/base64"
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/aws-sdk-go/aws" awsSDK "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2"
) )
func resourceAwsKeyPair() *schema.Resource { func resourceAwsKeyPair() *schema.Resource {
@ -37,13 +36,13 @@ func resourceAwsKeyPair() *schema.Resource {
} }
func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
keyName := d.Get("key_name").(string) keyName := d.Get("key_name").(string)
publicKey := d.Get("public_key").(string) publicKey := d.Get("public_key").(string)
req := &ec2.ImportKeyPairRequest{ req := &awsEC2.ImportKeyPairInput{
KeyName: aws.String(keyName), KeyName: awsSDK.String(keyName),
PublicKeyMaterial: []byte(base64.StdEncoding.EncodeToString([]byte(publicKey))), PublicKeyMaterial: []byte(publicKey),
} }
resp, err := ec2conn.ImportKeyPair(req) resp, err := ec2conn.ImportKeyPair(req)
if err != nil { if err != nil {
@ -55,10 +54,9 @@ func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2SDKconn
req := &awsEC2.DescribeKeyPairsInput{
req := &ec2.DescribeKeyPairsRequest{ KeyNames: []*string{awsSDK.String(d.Id())},
KeyNames: []string{d.Id()},
} }
resp, err := ec2conn.DescribeKeyPairs(req) resp, err := ec2conn.DescribeKeyPairs(req)
if err != nil { if err != nil {
@ -77,10 +75,10 @@ func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAwsKeyPairDelete(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{ _, err := ec2conn.DeleteKeyPair(&awsEC2.DeleteKeyPairInput{
KeyName: aws.String(d.Id()), KeyName: awsSDK.String(d.Id()),
}) })
return err return err
} }