providers/aws: cleanup of connections, upgrades network acl test

This commit is contained in:
Clint Shryock 2015-04-16 15:02:04 -05:00
parent 2566975c8e
commit 331f6705b8
2 changed files with 37 additions and 47 deletions

View File

@ -6,17 +6,14 @@ import (
"github.com/hashicorp/terraform/helper/multierror"
"github.com/awslabs/aws-sdk-go/service/elb"
"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/gen/ec2"
awsSDK "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/autoscaling"
awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/awslabs/aws-sdk-go/service/elb"
"github.com/awslabs/aws-sdk-go/service/iam"
"github.com/awslabs/aws-sdk-go/service/rds"
"github.com/awslabs/aws-sdk-go/service/route53"
"github.com/awslabs/aws-sdk-go/service/s3"
)
type Config struct {
@ -28,6 +25,7 @@ type Config struct {
type AWSClient struct {
ec2conn *ec2.EC2
ec2SDKconn *ec2.EC2
elbconn *elb.ELB
autoscalingconn *autoscaling.AutoScaling
s3conn *s3.S3
@ -35,7 +33,6 @@ type AWSClient struct {
region string
rdsconn *rds.RDS
iamconn *iam.IAM
ec2SDKconn *awsEC2.EC2
}
// Client configures and returns a fully initailized AWSClient
@ -59,40 +56,35 @@ 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)
awsConfig := &awsSDK.Config{
Credentials: sdkCreds,
awsConfig := &aws.Config{
Credentials: creds,
Region: c.Region,
}
log.Println("[INFO] Initializing ELB SDK connection")
log.Println("[INFO] Initializing ELB connection")
client.elbconn = elb.New(awsConfig)
log.Println("[INFO] Initializing S3 connection")
client.s3conn = s3.New(awsConfig)
log.Println("[INFO] Initializing EC2 Connection")
client.ec2conn = ec2.New(creds, c.Region, nil)
log.Println("[INFO] Initializing RDS SDK Connection")
log.Println("[INFO] Initializing RDS Connection")
client.rdsconn = rds.New(awsConfig)
log.Println("[INFO] Initializing IAM SDK Connection")
log.Println("[INFO] Initializing IAM Connection")
client.iamconn = iam.New(awsConfig)
log.Println("[INFO] Initializing AutoScaling SDK connection")
log.Println("[INFO] Initializing AutoScaling connection")
client.autoscalingconn = autoscaling.New(awsConfig)
log.Println("[INFO] Initializing EC2 SDK Connection")
client.ec2SDKconn = awsEC2.New(awsConfig)
log.Println("[INFO] Initializing EC2 Connection")
client.ec2conn = ec2.New(awsConfig)
client.ec2SDKconn = ec2.New(awsConfig)
// aws-sdk-go uses v4 for signing requests, which requires all global
// endpoints to use 'us-east-1'.
// See http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html
log.Println("[INFO] Initializing Route 53 SDK connection")
client.r53conn = route53.New(&awsSDK.Config{
Credentials: sdkCreds,
client.r53conn = route53.New(&aws.Config{
Credentials: creds,
Region: "us-east-1",
})

View File

@ -4,12 +4,10 @@ import (
"fmt"
"testing"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/terraform/terraform"
// "github.com/hashicorp/terraform/helper/hashcode"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource"
// "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSNetworkAcl_EgressAndIngressRules(t *testing.T) {
@ -151,7 +149,7 @@ func TestAccAWSNetworkAcl_OnlyEgressRules(t *testing.T) {
Config: testAccAWSNetworkAclEgressConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNetworkAclExists("aws_network_acl.bond", &networkAcl),
testAccCheckTags(&networkAcl.Tags, "foo", "bar"),
testAccCheckTagsSDK(&networkAcl.Tags, "foo", "bar"),
),
},
},
@ -192,8 +190,8 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
}
// Retrieve the network acl
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
NetworkACLIDs: []string{rs.Primary.ID},
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
NetworkACLIDs: []*string{aws.String(rs.Primary.ID)},
})
if err == nil {
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
@ -228,15 +226,15 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resou
}
conn := testAccProvider.Meta().(*AWSClient).ec2conn
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
NetworkACLIDs: []string{rs.Primary.ID},
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
NetworkACLIDs: []*string{aws.String(rs.Primary.ID)},
})
if err != nil {
return err
}
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
*networkAcl = resp.NetworkACLs[0]
*networkAcl = *resp.NetworkACLs[0]
return nil
}
@ -246,7 +244,7 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resou
func testIngressRuleLength(networkAcl *ec2.NetworkACL, length int) resource.TestCheckFunc {
return func(s *terraform.State) error {
var ingressEntries []ec2.NetworkACLEntry
var ingressEntries []*ec2.NetworkACLEntry
for _, e := range networkAcl.Entries {
if *e.Egress == false {
ingressEntries = append(ingressEntries, e)
@ -267,12 +265,12 @@ func testAccCheckSubnetIsAssociatedWithAcl(acl string, sub string) resource.Test
subnet := s.RootModule().Resources[sub]
conn := testAccProvider.Meta().(*AWSClient).ec2conn
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
NetworkACLIDs: []string{networkAcl.Primary.ID},
Filters: []ec2.Filter{
ec2.Filter{
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
NetworkACLIDs: []*string{aws.String(networkAcl.Primary.ID)},
Filters: []*ec2.Filter{
&ec2.Filter{
Name: aws.String("association.subnet-id"),
Values: []string{subnet.Primary.ID},
Values: []*string{aws.String(subnet.Primary.ID)},
},
},
})
@ -297,12 +295,12 @@ func testAccCheckSubnetIsNotAssociatedWithAcl(acl string, subnet string) resourc
subnet := s.RootModule().Resources[subnet]
conn := testAccProvider.Meta().(*AWSClient).ec2conn
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
NetworkACLIDs: []string{networkAcl.Primary.ID},
Filters: []ec2.Filter{
ec2.Filter{
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
NetworkACLIDs: []*string{aws.String(networkAcl.Primary.ID)},
Filters: []*ec2.Filter{
&ec2.Filter{
Name: aws.String("association.subnet-id"),
Values: []string{subnet.Primary.ID},
Values: []*string{aws.String(subnet.Primary.ID)},
},
},
})