provider/aws: fix breakages from awserr refactor

This landed in aws-sdk-go yesterday, breaking the AWS provider in many places:

3c259c9586

Here, with much sedding, grepping, and manual massaging, we attempt to
catch Terraform up to the new `awserr.Error` interface world.
This commit is contained in:
Paul Hinze 2015-05-20 06:21:23 -05:00
parent 046e9b4c88
commit 31258e06c6
74 changed files with 271 additions and 188 deletions

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -90,7 +91,7 @@ func resourceAwsAppCookieStickinessPolicyRead(d *schema.ResourceData, meta inter
getResp, err := elbconn.DescribeLoadBalancerPolicies(request) getResp, err := elbconn.DescribeLoadBalancerPolicies(request)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "PolicyNotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "PolicyNotFound" {
// The policy is gone. // The policy is gone.
d.SetId("") d.SetId("")
return nil return nil

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/autoscaling" "github.com/awslabs/aws-sdk-go/service/autoscaling"
"github.com/awslabs/aws-sdk-go/service/elb" "github.com/awslabs/aws-sdk-go/service/elb"
) )
@ -292,8 +293,8 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
// scaling operations within 5m. // scaling operations within 5m.
err = resource.Retry(5*time.Minute, func() error { err = resource.Retry(5*time.Minute, func() error {
if _, err := conn.DeleteAutoScalingGroup(&deleteopts); err != nil { if _, err := conn.DeleteAutoScalingGroup(&deleteopts); err != nil {
if awserr, ok := err.(aws.APIError); ok { if awserr, ok := err.(awserr.Error); ok {
switch awserr.Code { switch awserr.Code() {
case "InvalidGroup.NotFound": case "InvalidGroup.NotFound":
// Already gone? Sure! // Already gone? Sure!
return nil return nil
@ -332,8 +333,8 @@ func getAwsAutoscalingGroup(
log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts) log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts) describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
if err != nil { if err != nil {
autoscalingerr, ok := err.(aws.APIError) autoscalingerr, ok := err.(awserr.Error)
if ok && autoscalingerr.Code == "InvalidGroup.NotFound" { if ok && autoscalingerr.Code() == "InvalidGroup.NotFound" {
d.SetId("") d.SetId("")
return nil, nil return nil, nil
} }

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/autoscaling" "github.com/awslabs/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -141,11 +142,11 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidGroup.NotFound" { if ec2err.Code() != "InvalidGroup.NotFound" {
return err return err
} }
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -100,7 +101,7 @@ func customerGatewayRefreshFunc(conn *ec2.EC2, gatewayId string) resource.StateR
Filters: []*ec2.Filter{gatewayFilter}, Filters: []*ec2.Filter{gatewayFilter},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on CustomerGatewayRefresh: %s", err) log.Printf("Error on CustomerGatewayRefresh: %s", err)
@ -130,7 +131,7 @@ func resourceAwsCustomerGatewayRead(d *schema.ResourceData, meta interface{}) er
Filters: []*ec2.Filter{gatewayFilter}, Filters: []*ec2.Filter{gatewayFilter},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {
@ -172,7 +173,7 @@ func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{})
CustomerGatewayID: aws.String(d.Id()), CustomerGatewayID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
@ -275,7 +276,8 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] DB Instance create configuration: %#v", opts) log.Printf("[DEBUG] DB Instance create configuration: %#v", opts)
_, err := conn.CreateDBInstance(&opts) var err error
_, err = conn.CreateDBInstance(&opts)
if err != nil { if err != nil {
return fmt.Errorf("Error creating DB Instance: %s", err) return fmt.Errorf("Error creating DB Instance: %s", err)
} }
@ -558,8 +560,8 @@ func resourceAwsDbInstanceRetrieve(
resp, err := conn.DescribeDBInstances(&opts) resp, err := conn.DescribeDBInstances(&opts)
if err != nil { if err != nil {
dbinstanceerr, ok := err.(aws.APIError) dbinstanceerr, ok := err.(awserr.Error)
if ok && dbinstanceerr.Code == "DBInstanceNotFound" { if ok && dbinstanceerr.Code() == "DBInstanceNotFound" {
return nil, nil return nil, nil
} }
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err) return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
) )
@ -57,6 +58,7 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
} }
// Try to find the Group // Try to find the Group
var err error
resp, err := conn.DescribeDBInstances( resp, err := conn.DescribeDBInstances(
&rds.DescribeDBInstancesInput{ &rds.DescribeDBInstancesInput{
DBInstanceIdentifier: aws.String(rs.Primary.ID), DBInstanceIdentifier: aws.String(rs.Primary.ID),
@ -70,11 +72,11 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
newerr, ok := err.(*aws.APIError) newerr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if newerr.Code != "InvalidDBInstance.NotFound" { if newerr.Code() != "InvalidDBInstance.NotFound" {
return err return err
} }
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
) )
@ -203,12 +204,12 @@ func resourceAwsDbParameterGroupDeleteRefreshFunc(
} }
if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil { if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
rdserr, ok := err.(aws.APIError) rdserr, ok := err.(awserr.Error)
if !ok { if !ok {
return d, "error", err return d, "error", err
} }
if rdserr.Code != "DBParameterGroupNotFoundFault" { if rdserr.Code() != "DBParameterGroupNotFoundFault" {
return d, "error", err return d, "error", err
} }
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -127,11 +128,11 @@ func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
newerr, ok := err.(aws.APIError) newerr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if newerr.Code != "InvalidDBParameterGroup.NotFound" { if newerr.Code() != "InvalidDBParameterGroup.NotFound" {
return err return err
} }
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/multierror"
@ -170,8 +171,8 @@ func resourceAwsDbSecurityGroupDelete(d *schema.ResourceData, meta interface{})
_, err := conn.DeleteDBSecurityGroup(&opts) _, err := conn.DeleteDBSecurityGroup(&opts)
if err != nil { if err != nil {
newerr, ok := err.(aws.APIError) newerr, ok := err.(awserr.Error)
if ok && newerr.Code == "InvalidDBSecurityGroup.NotFound" { if ok && newerr.Code() == "InvalidDBSecurityGroup.NotFound" {
return nil return nil
} }
return err return err

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -59,11 +60,11 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
newerr, ok := err.(aws.APIError) newerr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if newerr.Code != "InvalidDBSecurityGroup.NotFound" { if newerr.Code() != "InvalidDBSecurityGroup.NotFound" {
return err return err
} }
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -77,7 +78,7 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
describeResp, err := rdsconn.DescribeDBSubnetGroups(&describeOpts) describeResp, err := rdsconn.DescribeDBSubnetGroups(&describeOpts)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "DBSubnetGroupNotFoundFault" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "DBSubnetGroupNotFoundFault" {
// Update state to indicate the db subnet no longer exists. // Update state to indicate the db subnet no longer exists.
d.SetId("") d.SetId("")
return nil return nil
@ -139,12 +140,12 @@ func resourceAwsDbSubnetGroupDeleteRefreshFunc(
} }
if _, err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil { if _, err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil {
rdserr, ok := err.(aws.APIError) rdserr, ok := err.(awserr.Error)
if !ok { if !ok {
return d, "error", err return d, "error", err
} }
if rdserr.Code != "DBSubnetGroupNotFoundFault" { if rdserr.Code() != "DBSubnetGroupNotFoundFault" {
return d, "error", err return d, "error", err
} }
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
) )
@ -55,11 +56,11 @@ func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
rdserr, ok := err.(aws.APIError) rdserr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if rdserr.Code != "DBSubnetGroupNotFoundFault" { if rdserr.Code() != "DBSubnetGroupNotFoundFault" {
return err return err
} }
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -102,7 +103,7 @@ func resourceAwsEbsVolumeRead(d *schema.ResourceData, meta interface{}) error {
response, err := conn.DescribeVolumes(request) response, err := conn.DescribeVolumes(request)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVolume.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVolume.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -123,7 +124,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
describeAddresses, err := ec2conn.DescribeAddresses(req) describeAddresses, err := ec2conn.DescribeAddresses(req)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidAllocationID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidAllocationID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} }
@ -247,7 +248,7 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
if err == nil { if err == nil {
return nil return nil
} }
if _, ok := err.(aws.APIError); !ok { if _, ok := err.(awserr.Error); !ok {
return resource.RetryError{Err: err} return resource.RetryError{Err: err}
} }

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -98,12 +99,12 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
providerErr, ok := err.(aws.APIError) providerErr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if providerErr.Code != "InvalidAllocationID.NotFound" { if providerErr.Code() != "InvalidAllocationID.NotFound" {
return fmt.Errorf("Unexpected error: %s", err) return fmt.Errorf("Unexpected error: %s", err)
} }
} }

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elasticache" "github.com/awslabs/aws-sdk-go/service/elasticache"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -310,9 +311,9 @@ func CacheClusterStateRefreshFunc(conn *elasticache.ElastiCache, clusterID, give
CacheClusterID: aws.String(clusterID), CacheClusterID: aws.String(clusterID),
}) })
if err != nil { if err != nil {
apierr := err.(aws.APIError) apierr := err.(awserr.Error)
log.Printf("[DEBUG] message: %v, code: %v", apierr.Message, apierr.Code) log.Printf("[DEBUG] message: %v, code: %v", apierr.Message(), apierr.Code())
if apierr.Message == fmt.Sprintf("CacheCluster not found: %v", clusterID) { if apierr.Message() == fmt.Sprintf("CacheCluster not found: %v", clusterID) {
log.Printf("[DEBUG] Detect deletion") log.Printf("[DEBUG] Detect deletion")
return nil, "", nil return nil, "", nil
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elasticache" "github.com/awslabs/aws-sdk-go/service/elasticache"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -125,12 +126,12 @@ func resourceAwsElasticacheSecurityGroupDelete(d *schema.ResourceData, meta inte
CacheSecurityGroupName: aws.String(d.Id()), CacheSecurityGroupName: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
apierr, ok := err.(aws.APIError) apierr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
log.Printf("[DEBUG] APIError.Code: %v", apierr.Code) log.Printf("[DEBUG] APIError.Code: %v", apierr.Code)
switch apierr.Code { switch apierr.Code() {
case "InvalidCacheSecurityGroupState": case "InvalidCacheSecurityGroupState":
return err return err
case "DependencyViolation": case "DependencyViolation":

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"time" "time"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elasticache" "github.com/awslabs/aws-sdk-go/service/elasticache"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -119,12 +120,12 @@ func resourceAwsElasticacheSubnetGroupDelete(d *schema.ResourceData, meta interf
CacheSubnetGroupName: aws.String(d.Id()), CacheSubnetGroupName: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
apierr, ok := err.(aws.APIError) apierr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
log.Printf("[DEBUG] APIError.Code: %v", apierr.Code) log.Printf("[DEBUG] APIError.Code: %v", apierr.Code)
switch apierr.Code { switch apierr.Code() {
case "DependencyViolation": case "DependencyViolation":
// If it is a dependency violation, we want to retry // If it is a dependency violation, we want to retry
return err return err

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -552,6 +553,6 @@ func resourceAwsElbListenerHash(v interface{}) int {
} }
func isLoadBalancerNotFound(err error) bool { func isLoadBalancerNotFound(err error) bool {
elberr, ok := err.(aws.APIError) elberr, ok := err.(awserr.Error)
return ok && elberr.Code == "LoadBalancerNotFound" return ok && elberr.Code() == "LoadBalancerNotFound"
} }

View File

@ -8,6 +8,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -381,12 +382,12 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
providerErr, ok := err.(aws.APIError) providerErr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if providerErr.Code != "InvalidLoadBalancerName.NotFound" { if providerErr.Code() != "InvalidLoadBalancerName.NotFound" {
return fmt.Errorf("Unexpected error: %s", err) return fmt.Errorf("Unexpected error: %s", err)
} }
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -71,7 +72,7 @@ func resourceAwsIamAccessKeyRead(d *schema.ResourceData, meta interface{}) error
getResp, err := iamconn.ListAccessKeys(request) getResp, err := iamconn.ListAccessKeys(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX TEST ME if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX TEST ME
// the user does not exist, so the key can't exist. // the user does not exist, so the key can't exist.
d.SetId("") d.SetId("")
return nil return nil

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -49,11 +50,11 @@ func testAccCheckAWSAccessKeyDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "NoSuchEntity" { if ec2err.Code() != "NoSuchEntity" {
return err return err
} }
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -66,7 +67,7 @@ func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error {
getResp, err := iamconn.GetGroup(request) getResp, err := iamconn.GetGroup(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -66,9 +67,10 @@ func resourceAwsIamGroupPolicyRead(d *schema.ResourceData, meta interface{}) err
GroupName: aws.String(group), GroupName: aws.String(group),
} }
var err error
getResp, err := iamconn.GetGroupPolicy(request) getResp, err := iamconn.GetGroupPolicy(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX test me if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -46,11 +47,11 @@ func testAccCheckAWSGroupDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "NoSuchEntity" { if ec2err.Code() != "NoSuchEntity" {
return err return err
} }
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -59,6 +60,7 @@ func resourceAwsIamInstanceProfileCreate(d *schema.ResourceData, meta interface{
Path: aws.String(d.Get("path").(string)), Path: aws.String(d.Get("path").(string)),
} }
var err error
response, err := iamconn.CreateInstanceProfile(request) response, err := iamconn.CreateInstanceProfile(request)
if err == nil { if err == nil {
err = instanceProfileReadResult(d, response.InstanceProfile) err = instanceProfileReadResult(d, response.InstanceProfile)
@ -87,7 +89,7 @@ func instanceProfileRemoveRole(iamconn *iam.IAM, profileName, roleName string) e
} }
_, err := iamconn.RemoveRoleFromInstanceProfile(request) _, err := iamconn.RemoveRoleFromInstanceProfile(request)
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
return nil return nil
} }
return err return err
@ -156,7 +158,7 @@ func resourceAwsIamInstanceProfileRead(d *schema.ResourceData, meta interface{})
result, err := iamconn.GetInstanceProfile(request) result, err := iamconn.GetInstanceProfile(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -73,7 +74,7 @@ func resourceAwsIamPolicyRead(d *schema.ResourceData, meta interface{}) error {
response, err := iamconn.GetPolicy(request) response, err := iamconn.GetPolicy(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
d.SetId("") d.SetId("")
return nil return nil
} }
@ -118,7 +119,7 @@ func resourceAwsIamPolicyDelete(d *schema.ResourceData, meta interface{}) error
_, err := iamconn.DeletePolicy(request) _, err := iamconn.DeletePolicy(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
return nil return nil
} }
return fmt.Errorf("Error reading IAM policy %s: %#v", d.Id(), err) return fmt.Errorf("Error reading IAM policy %s: %#v", d.Id(), err)

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -72,7 +73,7 @@ func resourceAwsIamRoleRead(d *schema.ResourceData, meta interface{}) error {
getResp, err := iamconn.GetRole(request) getResp, err := iamconn.GetRole(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX test me if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -66,9 +67,10 @@ func resourceAwsIamRolePolicyRead(d *schema.ResourceData, meta interface{}) erro
RoleName: aws.String(role), RoleName: aws.String(role),
} }
var err error
getResp, err := iamconn.GetRolePolicy(request) getResp, err := iamconn.GetRolePolicy(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX test me if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -46,11 +47,11 @@ func testAccCheckAWSRoleDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "NoSuchEntity" { if ec2err.Code() != "NoSuchEntity" {
return err return err
} }
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -75,7 +76,7 @@ func resourceAwsIamUserRead(d *schema.ResourceData, meta interface{}) error {
getResp, err := iamconn.GetUser(request) getResp, err := iamconn.GetUser(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX test me if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -66,9 +67,10 @@ func resourceAwsIamUserPolicyRead(d *schema.ResourceData, meta interface{}) erro
UserName: aws.String(user), UserName: aws.String(user),
} }
var err error
getResp, err := iamconn.GetUserPolicy(request) getResp, err := iamconn.GetUserPolicy(request)
if err != nil { if err != nil {
if iamerr, ok := err.(aws.APIError); ok && iamerr.Code == "NoSuchEntity" { // XXX test me if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX test me
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -46,11 +47,11 @@ func testAccCheckAWSUserDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "NoSuchEntity" { if ec2err.Code() != "NoSuchEntity" {
return err return err
} }
} }

View File

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -515,6 +516,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
// Create the instance // Create the instance
log.Printf("[DEBUG] Run configuration: %#v", runOpts) log.Printf("[DEBUG] Run configuration: %#v", runOpts)
var err error
runResp, err := conn.RunInstances(runOpts) runResp, err := conn.RunInstances(runOpts)
if err != nil { if err != nil {
return fmt.Errorf("Error launching source instance: %s", err) return fmt.Errorf("Error launching source instance: %s", err)
@ -581,7 +583,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
if err != nil { if err != nil {
// If the instance was not found, return nil so that we can show // If the instance was not found, return nil so that we can show
// that the instance is gone. // that the instance is gone.
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidInstanceID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} }
@ -776,7 +778,7 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRe
InstanceIDs: []*string{aws.String(instanceID)}, InstanceIDs: []*string{aws.String(instanceID)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidInstanceID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
// Set this to nil as if we didn't find anything. // Set this to nil as if we didn't find anything.
resp = nil resp = nil
} else { } else {

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -482,6 +483,7 @@ func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schem
} }
// Try to find the resource // Try to find the resource
var err error
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{ resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIDs: []*string{aws.String(rs.Primary.ID)}, InstanceIDs: []*string{aws.String(rs.Primary.ID)},
}) })
@ -494,11 +496,11 @@ func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schem
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidInstanceID.NotFound" { if ec2err.Code() != "InvalidInstanceID.NotFound" {
return err return err
} }
} }
@ -526,7 +528,7 @@ func testAccCheckInstanceExistsWithProviders(n string, i *ec2.Instance, provider
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{ resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIDs: []*string{aws.String(rs.Primary.ID)}, InstanceIDs: []*string{aws.String(rs.Primary.ID)},
}) })
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidInstanceID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
continue continue
} }
if err != nil { if err != nil {

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -33,6 +34,7 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{})
// Create the gateway // Create the gateway
log.Printf("[DEBUG] Creating internet gateway") log.Printf("[DEBUG] Creating internet gateway")
var err error
resp, err := conn.CreateInternetGateway(nil) resp, err := conn.CreateInternetGateway(nil)
if err != nil { if err != nil {
return fmt.Errorf("Error creating internet gateway: %s", err) return fmt.Errorf("Error creating internet gateway: %s", err)
@ -120,12 +122,12 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{})
return nil return nil
} }
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
switch ec2err.Code { switch ec2err.Code() {
case "InvalidInternetGatewayID.NotFound": case "InvalidInternetGatewayID.NotFound":
return nil return nil
case "DependencyViolation": case "DependencyViolation":
@ -226,13 +228,13 @@ func detachIGStateRefreshFunc(conn *ec2.EC2, instanceID, vpcID string) resource.
VPCID: aws.String(vpcID), VPCID: aws.String(vpcID),
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok { if ok {
if ec2err.Code == "InvalidInternetGatewayID.NotFound" { if ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
return nil, "Not Found", err return nil, "Not Found", err
} else if ec2err.Code == "Gateway.NotAttached" { } else if ec2err.Code() == "Gateway.NotAttached" {
return "detached", "detached", nil return "detached", "detached", nil
} else if ec2err.Code == "DependencyViolation" { } else if ec2err.Code() == "DependencyViolation" {
return nil, "detaching", nil return nil, "detaching", nil
} }
} }
@ -251,8 +253,8 @@ func IGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
InternetGatewayIDs: []*string{aws.String(id)}, InternetGatewayIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidInternetGatewayID.NotFound" { if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("[ERROR] Error on IGStateRefresh: %s", err) log.Printf("[ERROR] Error on IGStateRefresh: %s", err)
@ -284,8 +286,8 @@ func IGAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resourc
InternetGatewayIDs: []*string{aws.String(id)}, InternetGatewayIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidInternetGatewayID.NotFound" { if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("[ERROR] Error on IGStateRefresh: %s", err) log.Printf("[ERROR] Error on IGStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -135,11 +136,11 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidInternetGatewayID.NotFound" { if ec2err.Code() != "InvalidInternetGatewayID.NotFound" {
return err return err
} }
} }

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -78,11 +79,11 @@ func testAccCheckAWSKeyPairDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidKeyPair.NotFound" { if ec2err.Code() != "InvalidKeyPair.NotFound" {
return err return err
} }
} }

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/autoscaling" "github.com/awslabs/aws-sdk-go/service/autoscaling"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -440,8 +441,8 @@ func resourceAwsLaunchConfigurationDelete(d *schema.ResourceData, meta interface
LaunchConfigurationName: aws.String(d.Id()), LaunchConfigurationName: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
autoscalingerr, ok := err.(aws.APIError) autoscalingerr, ok := err.(awserr.Error)
if ok && autoscalingerr.Code == "InvalidConfiguration.NotFound" { if ok && autoscalingerr.Code() == "InvalidConfiguration.NotFound" {
return nil return nil
} }

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/autoscaling" "github.com/awslabs/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -119,11 +120,11 @@ func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error {
} }
// Verify the error // Verify the error
providerErr, ok := err.(aws.APIError) providerErr, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if providerErr.Code != "InvalidLaunchConfiguration.NotFound" { if providerErr.Code() != "InvalidLaunchConfiguration.NotFound" {
return err return err
} }
} }

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/elb" "github.com/awslabs/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -90,7 +91,7 @@ func resourceAwsLBCookieStickinessPolicyRead(d *schema.ResourceData, meta interf
getResp, err := elbconn.DescribeLoadBalancerPolicies(request) getResp, err := elbconn.DescribeLoadBalancerPolicies(request)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "PolicyNotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "PolicyNotFound" {
// The policy is gone. // The policy is gone.
d.SetId("") d.SetId("")
return nil return nil

View File

@ -9,6 +9,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -393,8 +394,8 @@ func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error
NetworkACLID: aws.String(d.Id()), NetworkACLID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
ec2err := err.(aws.APIError) ec2err := err.(awserr.Error)
switch ec2err.Code { switch ec2err.Code() {
case "InvalidNetworkAclID.NotFound": case "InvalidNetworkAclID.NotFound":
return nil return nil
case "DependencyViolation": case "DependencyViolation":

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -244,12 +245,12 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
return nil return nil
} }
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
// Confirm error code is what we want // Confirm error code is what we want
if ec2err.Code != "InvalidNetworkAclID.NotFound" { if ec2err.Code() != "InvalidNetworkAclID.NotFound" {
return err return err
} }
} }

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -102,7 +103,7 @@ func resourceAwsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
describeResp, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request) describeResp, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidNetworkInterfaceID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidNetworkInterfaceID.NotFound" {
// The ENI is gone now, so just remove it from the state // The ENI is gone now, so just remove it from the state
d.SetId("") d.SetId("")
return nil return nil

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -155,7 +156,7 @@ func testAccCheckAWSENIDestroy(s *terraform.State) error {
_, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request) _, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidNetworkInterfaceID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidNetworkInterfaceID.NotFound" {
return nil return nil
} }

View File

@ -165,6 +165,7 @@ func resourceAwsProxyProtocolPolicyDelete(d *schema.ResourceData, meta interface
req := &elb.DescribeLoadBalancersInput{ req := &elb.DescribeLoadBalancersInput{
LoadBalancerNames: []*string{elbname}, LoadBalancerNames: []*string{elbname},
} }
var err error
resp, err := elbconn.DescribeLoadBalancers(req) resp, err := elbconn.DescribeLoadBalancers(req)
if err != nil { if err != nil {
if isLoadBalancerNotFound(err) { if isLoadBalancerNotFound(err) {

View File

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/route53" "github.com/awslabs/aws-sdk-go/service/route53"
) )
@ -116,6 +117,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
conn := meta.(*AWSClient).r53conn conn := meta.(*AWSClient).r53conn
zone := cleanZoneID(d.Get("zone_id").(string)) zone := cleanZoneID(d.Get("zone_id").(string))
var err error
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)}) zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)})
if err != nil { if err != nil {
return err return err
@ -156,8 +158,8 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
Refresh: func() (interface{}, string, error) { Refresh: func() (interface{}, string, error) {
resp, err := conn.ChangeResourceRecordSets(req) resp, err := conn.ChangeResourceRecordSets(req)
if err != nil { if err != nil {
if r53err, ok := err.(aws.APIError); ok { if r53err, ok := err.(awserr.Error); ok {
if r53err.Code == "PriorRequestNotComplete" { if r53err.Code() == "PriorRequestNotComplete" {
// There is some pending operation, so just retry // There is some pending operation, so just retry
// in a bit. // in a bit.
return nil, "rejected", nil return nil, "rejected", nil
@ -280,6 +282,7 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
zone := cleanZoneID(d.Get("zone_id").(string)) zone := cleanZoneID(d.Get("zone_id").(string))
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s", log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
zone, d.Get("name").(string)) zone, d.Get("name").(string))
var err error
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)}) zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)})
if err != nil { if err != nil {
return err return err
@ -314,14 +317,14 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
Refresh: func() (interface{}, string, error) { Refresh: func() (interface{}, string, error) {
_, err := conn.ChangeResourceRecordSets(req) _, err := conn.ChangeResourceRecordSets(req)
if err != nil { if err != nil {
if r53err, ok := err.(aws.APIError); ok { if r53err, ok := err.(awserr.Error); ok {
if r53err.Code == "PriorRequestNotComplete" { if r53err.Code() == "PriorRequestNotComplete" {
// There is some pending operation, so just retry // There is some pending operation, so just retry
// in a bit. // in a bit.
return 42, "rejected", nil return 42, "rejected", nil
} }
if r53err.Code == "InvalidChangeBatch" { if r53err.Code() == "InvalidChangeBatch" {
// This means that the record is already gone. // This means that the record is already gone.
return 42, "accepted", nil return 42, "accepted", nil
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/route53" "github.com/awslabs/aws-sdk-go/service/route53"
) )
@ -78,6 +79,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
} }
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name) log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
var err error
resp, err := r53.CreateHostedZone(req) resp, err := r53.CreateHostedZone(req)
if err != nil { if err != nil {
return err return err
@ -114,7 +116,7 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(d.Id())}) zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(d.Id())})
if err != nil { if err != nil {
// Handle a deleted zone // Handle a deleted zone
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" { if r53err, ok := err.(awserr.Error); ok && r53err.Code() == "NoSuchHostedZone" {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/route53" "github.com/awslabs/aws-sdk-go/service/route53"
) )
@ -56,6 +57,7 @@ func resourceAwsRoute53ZoneAssociationCreate(d *schema.ResourceData, meta interf
} }
log.Printf("[DEBUG] Associating Route53 Private Zone %s with VPC %s with region %s", *req.HostedZoneID, *req.VPC.VPCID, *req.VPC.VPCRegion) log.Printf("[DEBUG] Associating Route53 Private Zone %s with VPC %s with region %s", *req.HostedZoneID, *req.VPC.VPCID, *req.VPC.VPCRegion)
var err error
resp, err := r53.AssociateVPCWithHostedZone(req) resp, err := r53.AssociateVPCWithHostedZone(req)
if err != nil { if err != nil {
return err return err
@ -93,7 +95,7 @@ func resourceAwsRoute53ZoneAssociationRead(d *schema.ResourceData, meta interfac
zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone_id)}) zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone_id)})
if err != nil { if err != nil {
// Handle a deleted zone // Handle a deleted zone
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" { if r53err, ok := err.(awserr.Error); ok && r53err.Code() == "NoSuchHostedZone" {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -224,8 +225,8 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
// If we get a Gateway.NotAttached, it is usually some // If we get a Gateway.NotAttached, it is usually some
// eventually consistency stuff. So we have to just wait a // eventually consistency stuff. So we have to just wait a
// bit... // bit...
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "Gateway.NotAttached" { if ok && ec2err.Code() == "Gateway.NotAttached" {
time.Sleep(20 * time.Second) time.Sleep(20 * time.Second)
continue continue
} }
@ -329,8 +330,8 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
RouteTableID: aws.String(d.Id()), RouteTableID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidRouteTableID.NotFound" { if ok && ec2err.Code() == "InvalidRouteTableID.NotFound" {
return nil return nil
} }
@ -391,7 +392,7 @@ func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.St
RouteTableIDs: []*string{aws.String(id)}, RouteTableIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidRouteTableID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidRouteTableID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on RouteTableStateRefresh: %s", err) log.Printf("Error on RouteTableStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -102,8 +103,8 @@ func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interfa
resp, err := conn.ReplaceRouteTableAssociation(req) resp, err := conn.ReplaceRouteTableAssociation(req)
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidAssociationID.NotFound" { if ok && ec2err.Code() == "InvalidAssociationID.NotFound" {
// Not found, so just create a new one // Not found, so just create a new one
return resourceAwsRouteTableAssociationCreate(d, meta) return resourceAwsRouteTableAssociationCreate(d, meta)
} }
@ -126,8 +127,8 @@ func resourceAwsRouteTableAssociationDelete(d *schema.ResourceData, meta interfa
AssociationID: aws.String(d.Id()), AssociationID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidAssociationID.NotFound" { if ok && ec2err.Code() == "InvalidAssociationID.NotFound" {
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -51,11 +52,11 @@ func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
}) })
if err != nil { if err != nil {
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidRouteTableID.NotFound" { if ec2err.Code() != "InvalidRouteTableID.NotFound" {
return err return err
} }
return nil return nil

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -171,11 +172,11 @@ func testAccCheckRouteTableDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidRouteTableID.NotFound" { if ec2err.Code() != "InvalidRouteTableID.NotFound" {
return err return err
} }
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/s3" "github.com/awslabs/aws-sdk-go/service/s3"
) )
@ -146,11 +147,12 @@ 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.HeadBucketInput{ var err error
_, err = s3conn.HeadBucket(&s3.HeadBucketInput{
Bucket: aws.String(d.Id()), Bucket: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
if awsError, ok := err.(aws.APIError); ok && awsError.StatusCode == 404 { if awsError, ok := err.(awserr.RequestFailure); ok && awsError.StatusCode() == 404 {
d.SetId("") d.SetId("")
} else { } else {
// some of the AWS SDK's errors can be empty strings, so let's add // some of the AWS SDK's errors can be empty strings, so let's add

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -166,6 +167,7 @@ func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
} }
securityGroupOpts.GroupName = aws.String(groupName) securityGroupOpts.GroupName = aws.String(groupName)
var err error
log.Printf( log.Printf(
"[DEBUG] Security Group create configuration: %#v", securityGroupOpts) "[DEBUG] Security Group create configuration: %#v", securityGroupOpts)
createResp, err := conn.CreateSecurityGroup(securityGroupOpts) createResp, err := conn.CreateSecurityGroup(securityGroupOpts)
@ -300,12 +302,12 @@ func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er
GroupID: aws.String(d.Id()), GroupID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
switch ec2err.Code { switch ec2err.Code() {
case "InvalidGroup.NotFound": case "InvalidGroup.NotFound":
return nil return nil
case "DependencyViolation": case "DependencyViolation":
@ -530,9 +532,9 @@ func SGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
} }
resp, err := conn.DescribeSecurityGroups(req) resp, err := conn.DescribeSecurityGroups(req)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok { if ec2err, ok := err.(awserr.Error); ok {
if ec2err.Code == "InvalidSecurityGroupID.NotFound" || if ec2err.Code() == "InvalidSecurityGroupID.NotFound" ||
ec2err.Code == "InvalidGroup.NotFound" { ec2err.Code() == "InvalidGroup.NotFound" {
resp = nil resp = nil
err = nil err = nil
} }

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -244,9 +245,9 @@ func findResourceSecurityGroup(conn *ec2.EC2, id string) (*ec2.SecurityGroup, er
} }
resp, err := conn.DescribeSecurityGroups(req) resp, err := conn.DescribeSecurityGroups(req)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok { if ec2err, ok := err.(awserr.Error); ok {
if ec2err.Code == "InvalidSecurityGroupID.NotFound" || if ec2err.Code() == "InvalidSecurityGroupID.NotFound" ||
ec2err.Code == "InvalidGroup.NotFound" { ec2err.Code() == "InvalidGroup.NotFound" {
resp = nil resp = nil
err = nil err = nil
} }

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -216,12 +217,12 @@ func testAccCheckAWSSecurityGroupRuleDestroy(s *terraform.State) error {
return nil return nil
} }
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
// Confirm error code is what we want // Confirm error code is what we want
if ec2err.Code != "InvalidGroup.NotFound" { if ec2err.Code() != "InvalidGroup.NotFound" {
return err return err
} }
} }

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -310,12 +311,12 @@ func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
return nil return nil
} }
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
// Confirm error code is what we want // Confirm error code is what we want
if ec2err.Code != "InvalidGroup.NotFound" { if ec2err.Code() != "InvalidGroup.NotFound" {
return err return err
} }
} }

View File

@ -12,16 +12,15 @@ import (
) )
var AttributeMap = map[string]string{ var AttributeMap = map[string]string{
"delay_seconds" : "DelaySeconds", "delay_seconds": "DelaySeconds",
"max_message_size" : "MaximumMessageSize", "max_message_size": "MaximumMessageSize",
"message_retention_seconds" : "MessageRetentionPeriod", "message_retention_seconds": "MessageRetentionPeriod",
"receive_wait_time_seconds" : "ReceiveMessageWaitTimeSeconds", "receive_wait_time_seconds": "ReceiveMessageWaitTimeSeconds",
"visibility_timeout_seconds" : "VisibilityTimeout", "visibility_timeout_seconds": "VisibilityTimeout",
"policy" : "Policy", "policy": "Policy",
"redrive_policy": "RedrivePolicy", "redrive_policy": "RedrivePolicy",
} }
// A number of these are marked as computed because if you don't // A number of these are marked as computed because if you don't
// provide a value, SQS will provide you with defaults (which are the // provide a value, SQS will provide you with defaults (which are the
// default values specified below) // default values specified below)
@ -193,5 +192,3 @@ func resourceAwsSqsQueueDelete(d *schema.ResourceData, meta interface{}) error {
} }
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/sqs" "github.com/awslabs/aws-sdk-go/service/sqs"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -32,7 +33,6 @@ func TestAccAWSSQSQueue(t *testing.T) {
}) })
} }
func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error { func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).sqsconn conn := testAccProvider.Meta().(*AWSClient).sqsconn
@ -51,7 +51,7 @@ func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
_, ok := err.(aws.APIError) _, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
@ -60,7 +60,6 @@ func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckAWSSQSExistsWithDefaults(n string) resource.TestCheckFunc { func testAccCheckAWSSQSExistsWithDefaults(n string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -59,6 +60,7 @@ func resourceAwsSubnetCreate(d *schema.ResourceData, meta interface{}) error {
VPCID: aws.String(d.Get("vpc_id").(string)), VPCID: aws.String(d.Get("vpc_id").(string)),
} }
var err error
resp, err := conn.CreateSubnet(createOpts) resp, err := conn.CreateSubnet(createOpts)
if err != nil { if err != nil {
@ -98,7 +100,7 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidSubnetID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSubnetID.NotFound" {
// Update state to indicate the subnet no longer exists. // Update state to indicate the subnet no longer exists.
d.SetId("") d.SetId("")
return nil return nil
@ -171,14 +173,14 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
Refresh: func() (interface{}, string, error) { Refresh: func() (interface{}, string, error) {
_, err := conn.DeleteSubnet(req) _, err := conn.DeleteSubnet(req)
if err != nil { if err != nil {
if apiErr, ok := err.(aws.APIError); ok { if apiErr, ok := err.(awserr.Error); ok {
if apiErr.Code == "DependencyViolation" { if apiErr.Code() == "DependencyViolation" {
// There is some pending operation, so just retry // There is some pending operation, so just retry
// in a bit. // in a bit.
return 42, "pending", nil return 42, "pending", nil
} }
if apiErr.Code == "InvalidSubnetID.NotFound" { if apiErr.Code() == "InvalidSubnetID.NotFound" {
return 42, "destroyed", nil return 42, "destroyed", nil
} }
} }
@ -204,7 +206,7 @@ func SubnetStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc
SubnetIDs: []*string{aws.String(id)}, SubnetIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidSubnetID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSubnetID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on SubnetStateRefresh: %s", err) log.Printf("Error on SubnetStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -63,11 +64,11 @@ func testAccCheckSubnetDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidSubnetID.NotFound" { if ec2err.Code() != "InvalidSubnetID.NotFound" {
return err return err
} }
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -247,8 +248,8 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
} }
log.Printf("[INFO] Deleting VPC: %s", d.Id()) log.Printf("[INFO] Deleting VPC: %s", d.Id())
if _, err := conn.DeleteVPC(DeleteVpcOpts); err != nil { if _, err := conn.DeleteVPC(DeleteVpcOpts); err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code == "InvalidVpcID.NotFound" { if ok && ec2err.Code() == "InvalidVpcID.NotFound" {
return nil return nil
} }
@ -267,7 +268,7 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
} }
resp, err := conn.DescribeVPCs(DescribeVpcOpts) resp, err := conn.DescribeVPCs(DescribeVpcOpts)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on VPCStateRefresh: %s", err) log.Printf("Error on VPCStateRefresh: %s", err)

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -191,12 +192,12 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e
log.Printf("[WARN] %s", err) log.Printf("[WARN] %s", err)
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
switch ec2err.Code { switch ec2err.Code() {
case "InvalidDhcpOptionsID.NotFound": case "InvalidDhcpOptionsID.NotFound":
return nil return nil
case "DependencyViolation": case "DependencyViolation":
@ -241,7 +242,7 @@ func findVPCsByDHCPOptionsID(conn *ec2.EC2, id string) ([]*ec2.VPC, error) {
resp, err := conn.DescribeVPCs(req) resp, err := conn.DescribeVPCs(req)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
return nil, nil return nil, nil
} }
return nil, err return nil, err
@ -260,7 +261,7 @@ func DHCPOptionsStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefresh
resp, err := conn.DescribeDHCPOptions(DescribeDhcpOpts) resp, err := conn.DescribeDHCPOptions(DescribeDhcpOpts)
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidDhcpOptionsID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidDhcpOptionsID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on DHCPOptionsStateRefresh: %s", err) log.Printf("Error on DHCPOptionsStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -58,11 +59,11 @@ func testAccCheckDHCPOptionsDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidDhcpOptionsID.NotFound" { if ec2err.Code() != "InvalidDhcpOptionsID.NotFound" {
return err return err
} }
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -179,7 +180,7 @@ func resourceAwsVPCPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r
VPCPeeringConnectionIDs: []*string{aws.String(id)}, VPCPeeringConnectionIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcPeeringConnectionID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on VPCPeeringConnectionStateRefresh: %s", err) log.Printf("Error on VPCPeeringConnectionStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -133,11 +134,11 @@ func testAccCheckVpcDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidVpcID.NotFound" { if ec2err.Code() != "InvalidVpcID.NotFound" {
return err return err
} }
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -200,7 +201,7 @@ func vpnConnectionRefreshFunc(conn *ec2.EC2, connectionId string) resource.State
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("Error on VPNConnectionRefresh: %s", err) log.Printf("Error on VPNConnectionRefresh: %s", err)
@ -224,7 +225,7 @@ func resourceAwsVpnConnectionRead(d *schema.ResourceData, meta interface{}) erro
VPNConnectionIDs: []*string{aws.String(d.Id())}, VPNConnectionIDs: []*string{aws.String(d.Id())},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {
@ -285,7 +286,7 @@ func resourceAwsVpnConnectionDelete(d *schema.ResourceData, meta interface{}) er
VPNConnectionID: aws.String(d.Id()), VPNConnectionID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -66,7 +67,7 @@ func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
VPNGatewayIDs: []*string{aws.String(d.Id())}, VPNGatewayIDs: []*string{aws.String(d.Id())},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {
@ -136,12 +137,12 @@ func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error
return nil return nil
} }
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
switch ec2err.Code { switch ec2err.Code() {
case "InvalidVpnGatewayID.NotFound": case "InvalidVpnGatewayID.NotFound":
return nil return nil
case "IncorrectState": case "IncorrectState":
@ -221,12 +222,12 @@ func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error
VPCID: aws.String(vpcID.(string)), VPCID: aws.String(vpcID.(string)),
}) })
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if ok { if ok {
if ec2err.Code == "InvalidVpnGatewayID.NotFound" { if ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
err = nil err = nil
wait = false wait = false
} else if ec2err.Code == "InvalidVpnGatewayAttachment.NotFound" { } else if ec2err.Code() == "InvalidVpnGatewayAttachment.NotFound" {
err = nil err = nil
wait = false wait = false
} }
@ -271,7 +272,7 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string)
VPNGatewayIDs: []*string{aws.String(id)}, VPNGatewayIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
resp = nil resp = nil
} else { } else {
log.Printf("[ERROR] Error on VpnGatewayStateRefresh: %s", err) log.Printf("[ERROR] Error on VpnGatewayStateRefresh: %s", err)

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -135,11 +136,11 @@ func testAccCheckVpnGatewayDestroy(s *terraform.State) error {
} }
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(awserr.Error)
if !ok { if !ok {
return err return err
} }
if ec2err.Code != "InvalidVpnGatewayID.NotFound" { if ec2err.Code() != "InvalidVpnGatewayID.NotFound" {
return err return err
} }
} }

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -82,7 +83,7 @@ func resourceAwsVpnConnectionRouteRead(d *schema.ResourceData, meta interface{})
Filters: routeFilters, Filters: routeFilters,
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {
@ -117,7 +118,7 @@ func resourceAwsVpnConnectionRouteDelete(d *schema.ResourceData, meta interface{
VPNConnectionID: aws.String(d.Get("vpn_connection_id").(string)), VPNConnectionID: aws.String(d.Get("vpn_connection_id").(string)),
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnConnectionID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
d.SetId("") d.SetId("")
return nil return nil
} else { } else {

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/service/s3" "github.com/awslabs/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -101,7 +102,7 @@ func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) {
} }
response, err := s3conn.GetBucketTagging(request) response, err := s3conn.GetBucketTagging(request)
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" { if ec2err, ok := err.(awserr.Error); 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 {

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/awserr"
"github.com/awslabs/aws-sdk-go/aws/credentials" "github.com/awslabs/aws-sdk-go/aws/credentials"
"github.com/awslabs/aws-sdk-go/service/s3" "github.com/awslabs/aws-sdk-go/service/s3"
) )
@ -78,8 +79,8 @@ func (c *S3Client) Get() (*Payload, error) {
}) })
if err != nil { if err != nil {
if awserr := aws.Error(err); awserr != nil { if awserr := awserr.Error(err); awserr != nil {
if awserr.Code == "NoSuchKey" { if awserr.Code() == "NoSuchKey" {
return nil, nil return nil, nil
} else { } else {
return nil, err return nil, err