From 31258e06c65d85eeee2cd86131bb4cecaeba48cc Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 20 May 2015 06:21:23 -0500 Subject: [PATCH] provider/aws: fix breakages from awserr refactor This landed in aws-sdk-go yesterday, breaking the AWS provider in many places: https://github.com/awslabs/aws-sdk-go/commit/3c259c9586a4a82d6f00e7c01a69263f798e8ffe Here, with much sedding, grepping, and manual massaging, we attempt to catch Terraform up to the new `awserr.Error` interface world. --- builtin/providers/aws/config.go | 2 +- ...source_aws_app_cookie_stickiness_policy.go | 3 +- .../aws/resource_aws_autoscaling_group.go | 9 ++--- .../resource_aws_autoscaling_group_test.go | 5 +-- .../aws/resource_aws_customer_gateway.go | 7 ++-- .../providers/aws/resource_aws_db_instance.go | 8 +++-- .../aws/resource_aws_db_instance_test.go | 6 ++-- .../aws/resource_aws_db_parameter_group.go | 5 +-- .../resource_aws_db_parameter_group_test.go | 5 +-- .../aws/resource_aws_db_security_group.go | 5 +-- .../resource_aws_db_security_group_test.go | 5 +-- .../aws/resource_aws_db_subnet_group.go | 7 ++-- .../aws/resource_aws_db_subnet_group_test.go | 5 +-- .../providers/aws/resource_aws_ebs_volume.go | 3 +- builtin/providers/aws/resource_aws_eip.go | 5 +-- .../providers/aws/resource_aws_eip_test.go | 5 +-- .../aws/resource_aws_elasticache_cluster.go | 7 ++-- ...resource_aws_elasticache_security_group.go | 5 +-- .../resource_aws_elasticache_subnet_group.go | 5 +-- builtin/providers/aws/resource_aws_elb.go | 5 +-- .../providers/aws/resource_aws_elb_test.go | 5 +-- .../aws/resource_aws_iam_access_key.go | 3 +- .../aws/resource_aws_iam_access_key_test.go | 5 +-- .../providers/aws/resource_aws_iam_group.go | 3 +- .../aws/resource_aws_iam_group_policy.go | 4 ++- .../aws/resource_aws_iam_group_test.go | 5 +-- .../aws/resource_aws_iam_instance_profile.go | 6 ++-- .../providers/aws/resource_aws_iam_policy.go | 5 +-- .../providers/aws/resource_aws_iam_role.go | 3 +- .../aws/resource_aws_iam_role_policy.go | 4 ++- .../aws/resource_aws_iam_role_test.go | 5 +-- .../providers/aws/resource_aws_iam_user.go | 3 +- .../aws/resource_aws_iam_user_policy.go | 4 ++- .../aws/resource_aws_iam_user_test.go | 5 +-- .../providers/aws/resource_aws_instance.go | 6 ++-- .../aws/resource_aws_instance_test.go | 8 +++-- .../aws/resource_aws_internet_gateway.go | 22 +++++++------ .../aws/resource_aws_internet_gateway_test.go | 5 +-- .../aws/resource_aws_key_pair_test.go | 5 +-- .../aws/resource_aws_launch_configuration.go | 5 +-- .../resource_aws_launch_configuration_test.go | 5 +-- ...esource_aws_lb_cookie_stickiness_policy.go | 3 +- .../providers/aws/resource_aws_network_acl.go | 5 +-- .../aws/resource_aws_network_acl_test.go | 5 +-- .../aws/resource_aws_network_interface.go | 3 +- .../resource_aws_network_interface_test.go | 3 +- .../aws/resource_aws_proxy_protocol_policy.go | 1 + .../aws/resource_aws_route53_record.go | 13 +++++--- .../aws/resource_aws_route53_zone.go | 4 ++- .../resource_aws_route53_zone_association.go | 4 ++- .../providers/aws/resource_aws_route_table.go | 11 ++++--- .../resource_aws_route_table_association.go | 9 ++--- ...source_aws_route_table_association_test.go | 5 +-- .../aws/resource_aws_route_table_test.go | 5 +-- .../providers/aws/resource_aws_s3_bucket.go | 6 ++-- .../aws/resource_aws_security_group.go | 12 ++++--- .../aws/resource_aws_security_group_rule.go | 7 ++-- .../resource_aws_security_group_rule_test.go | 5 +-- .../aws/resource_aws_security_group_test.go | 5 +-- .../providers/aws/resource_aws_sqs_queue.go | 33 +++++++++---------- .../aws/resource_aws_sqs_queue_test.go | 11 +++---- builtin/providers/aws/resource_aws_subnet.go | 12 ++++--- .../providers/aws/resource_aws_subnet_test.go | 5 +-- builtin/providers/aws/resource_aws_vpc.go | 7 ++-- .../aws/resource_aws_vpc_dhcp_options.go | 9 ++--- .../aws/resource_aws_vpc_dhcp_options_test.go | 5 +-- .../resource_aws_vpc_peering_connection.go | 3 +- .../providers/aws/resource_aws_vpc_test.go | 5 +-- .../aws/resource_aws_vpn_connection.go | 7 ++-- .../providers/aws/resource_aws_vpn_gateway.go | 15 +++++---- .../aws/resource_aws_vpn_gateway_test.go | 5 +-- .../aws/resource_vpn_connection_route.go | 5 +-- builtin/providers/aws/s3_tags.go | 3 +- state/remote/s3.go | 5 +-- 74 files changed, 271 insertions(+), 188 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index bd03236ad..ff742436b 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -36,7 +36,7 @@ type AWSClient struct { elbconn *elb.ELB autoscalingconn *autoscaling.AutoScaling s3conn *s3.S3 - sqsconn *sqs.SQS + sqsconn *sqs.SQS r53conn *route53.Route53 region string rdsconn *rds.RDS diff --git a/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy.go b/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy.go index 62a3713fa..66c240826 100644 --- a/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy.go +++ b/builtin/providers/aws/resource_aws_app_cookie_stickiness_policy.go @@ -5,6 +5,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" ) @@ -90,7 +91,7 @@ func resourceAwsAppCookieStickinessPolicyRead(d *schema.ResourceData, meta inter getResp, err := elbconn.DescribeLoadBalancerPolicies(request) 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. d.SetId("") return nil diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index a53a4b636..19abd3da3 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "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/elb" ) @@ -292,8 +293,8 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{}) // scaling operations within 5m. err = resource.Retry(5*time.Minute, func() error { if _, err := conn.DeleteAutoScalingGroup(&deleteopts); err != nil { - if awserr, ok := err.(aws.APIError); ok { - switch awserr.Code { + if awserr, ok := err.(awserr.Error); ok { + switch awserr.Code() { case "InvalidGroup.NotFound": // Already gone? Sure! return nil @@ -332,8 +333,8 @@ func getAwsAutoscalingGroup( log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts) describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts) if err != nil { - autoscalingerr, ok := err.(aws.APIError) - if ok && autoscalingerr.Code == "InvalidGroup.NotFound" { + autoscalingerr, ok := err.(awserr.Error) + if ok && autoscalingerr.Code() == "InvalidGroup.NotFound" { d.SetId("") return nil, nil } diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index 5097d5833..bddf05c3f 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -7,6 +7,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -141,11 +142,11 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error { } // Verify the error - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidGroup.NotFound" { + if ec2err.Code() != "InvalidGroup.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_customer_gateway.go b/builtin/providers/aws/resource_aws_customer_gateway.go index 7c7d027b7..6fa1d39ab 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway.go +++ b/builtin/providers/aws/resource_aws_customer_gateway.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" @@ -100,7 +101,7 @@ func customerGatewayRefreshFunc(conn *ec2.EC2, gatewayId string) resource.StateR Filters: []*ec2.Filter{gatewayFilter}, }) 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 } else { log.Printf("Error on CustomerGatewayRefresh: %s", err) @@ -130,7 +131,7 @@ func resourceAwsCustomerGatewayRead(d *schema.ResourceData, meta interface{}) er Filters: []*ec2.Filter{gatewayFilter}, }) 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("") return nil } else { @@ -172,7 +173,7 @@ func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{}) CustomerGatewayID: aws.String(d.Id()), }) 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("") return nil } else { diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index bf85d2e05..34e78184c 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -7,6 +7,7 @@ import ( "time" "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/rds" @@ -275,7 +276,8 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } log.Printf("[DEBUG] DB Instance create configuration: %#v", opts) - _, err := conn.CreateDBInstance(&opts) + var err error + _, err = conn.CreateDBInstance(&opts) if err != nil { return fmt.Errorf("Error creating DB Instance: %s", err) } @@ -558,8 +560,8 @@ func resourceAwsDbInstanceRetrieve( resp, err := conn.DescribeDBInstances(&opts) if err != nil { - dbinstanceerr, ok := err.(aws.APIError) - if ok && dbinstanceerr.Code == "DBInstanceNotFound" { + dbinstanceerr, ok := err.(awserr.Error) + if ok && dbinstanceerr.Code() == "DBInstanceNotFound" { return nil, nil } return nil, fmt.Errorf("Error retrieving DB Instances: %s", err) diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 2a22d2393..3b81817da 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform/terraform" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "github.com/awslabs/aws-sdk-go/service/rds" ) @@ -57,6 +58,7 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { } // Try to find the Group + var err error resp, err := conn.DescribeDBInstances( &rds.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(rs.Primary.ID), @@ -70,11 +72,11 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { } // Verify the error - newerr, ok := err.(*aws.APIError) + newerr, ok := err.(awserr.Error) if !ok { return err } - if newerr.Code != "InvalidDBInstance.NotFound" { + if newerr.Code() != "InvalidDBInstance.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_db_parameter_group.go b/builtin/providers/aws/resource_aws_db_parameter_group.go index 0757a9681..57758ae5b 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "github.com/awslabs/aws-sdk-go/service/rds" ) @@ -203,12 +204,12 @@ func resourceAwsDbParameterGroupDeleteRefreshFunc( } if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil { - rdserr, ok := err.(aws.APIError) + rdserr, ok := err.(awserr.Error) if !ok { return d, "error", err } - if rdserr.Code != "DBParameterGroupNotFoundFault" { + if rdserr.Code() != "DBParameterGroupNotFoundFault" { return d, "error", err } } diff --git a/builtin/providers/aws/resource_aws_db_parameter_group_test.go b/builtin/providers/aws/resource_aws_db_parameter_group_test.go index 593b38957..57400fb0c 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group_test.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -127,11 +128,11 @@ func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error { } // Verify the error - newerr, ok := err.(aws.APIError) + newerr, ok := err.(awserr.Error) if !ok { return err } - if newerr.Code != "InvalidDBParameterGroup.NotFound" { + if newerr.Code() != "InvalidDBParameterGroup.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_db_security_group.go b/builtin/providers/aws/resource_aws_db_security_group.go index 818999ce0..94d87e370 100644 --- a/builtin/providers/aws/resource_aws_db_security_group.go +++ b/builtin/providers/aws/resource_aws_db_security_group.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/multierror" @@ -170,8 +171,8 @@ func resourceAwsDbSecurityGroupDelete(d *schema.ResourceData, meta interface{}) _, err := conn.DeleteDBSecurityGroup(&opts) if err != nil { - newerr, ok := err.(aws.APIError) - if ok && newerr.Code == "InvalidDBSecurityGroup.NotFound" { + newerr, ok := err.(awserr.Error) + if ok && newerr.Code() == "InvalidDBSecurityGroup.NotFound" { return nil } return err diff --git a/builtin/providers/aws/resource_aws_db_security_group_test.go b/builtin/providers/aws/resource_aws_db_security_group_test.go index c7b8d2d1e..a2065114a 100644 --- a/builtin/providers/aws/resource_aws_db_security_group_test.go +++ b/builtin/providers/aws/resource_aws_db_security_group_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -59,11 +60,11 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error { } // Verify the error - newerr, ok := err.(aws.APIError) + newerr, ok := err.(awserr.Error) if !ok { return err } - if newerr.Code != "InvalidDBSecurityGroup.NotFound" { + if newerr.Code() != "InvalidDBSecurityGroup.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_db_subnet_group.go b/builtin/providers/aws/resource_aws_db_subnet_group.go index 286099ac6..598d291c4 100644 --- a/builtin/providers/aws/resource_aws_db_subnet_group.go +++ b/builtin/providers/aws/resource_aws_db_subnet_group.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -77,7 +78,7 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro describeResp, err := rdsconn.DescribeDBSubnetGroups(&describeOpts) 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. d.SetId("") return nil @@ -139,12 +140,12 @@ func resourceAwsDbSubnetGroupDeleteRefreshFunc( } if _, err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil { - rdserr, ok := err.(aws.APIError) + rdserr, ok := err.(awserr.Error) if !ok { return d, "error", err } - if rdserr.Code != "DBSubnetGroupNotFoundFault" { + if rdserr.Code() != "DBSubnetGroupNotFoundFault" { return d, "error", err } } diff --git a/builtin/providers/aws/resource_aws_db_subnet_group_test.go b/builtin/providers/aws/resource_aws_db_subnet_group_test.go index 89bf27c77..06e9e92c4 100644 --- a/builtin/providers/aws/resource_aws_db_subnet_group_test.go +++ b/builtin/providers/aws/resource_aws_db_subnet_group_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/terraform" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "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 - rdserr, ok := err.(aws.APIError) + rdserr, ok := err.(awserr.Error) if !ok { return err } - if rdserr.Code != "DBSubnetGroupNotFoundFault" { + if rdserr.Code() != "DBSubnetGroupNotFoundFault" { return err } } diff --git a/builtin/providers/aws/resource_aws_ebs_volume.go b/builtin/providers/aws/resource_aws_ebs_volume.go index ccf4ca009..815ec59a0 100644 --- a/builtin/providers/aws/resource_aws_ebs_volume.go +++ b/builtin/providers/aws/resource_aws_ebs_volume.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -102,7 +103,7 @@ func resourceAwsEbsVolumeRead(d *schema.ResourceData, meta interface{}) error { response, err := conn.DescribeVolumes(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_eip.go b/builtin/providers/aws/resource_aws_eip.go index cb3ea6bbe..f184cad78 100644 --- a/builtin/providers/aws/resource_aws_eip.go +++ b/builtin/providers/aws/resource_aws_eip.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -123,7 +124,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error { describeAddresses, err := ec2conn.DescribeAddresses(req) 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("") return nil } @@ -247,7 +248,7 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error { if err == nil { return nil } - if _, ok := err.(aws.APIError); !ok { + if _, ok := err.(awserr.Error); !ok { return resource.RetryError{Err: err} } diff --git a/builtin/providers/aws/resource_aws_eip_test.go b/builtin/providers/aws/resource_aws_eip_test.go index b87794131..7509d71cc 100644 --- a/builtin/providers/aws/resource_aws_eip_test.go +++ b/builtin/providers/aws/resource_aws_eip_test.go @@ -6,6 +6,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -98,12 +99,12 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error { } // Verify the error - providerErr, ok := err.(aws.APIError) + providerErr, ok := err.(awserr.Error) if !ok { return err } - if providerErr.Code != "InvalidAllocationID.NotFound" { + if providerErr.Code() != "InvalidAllocationID.NotFound" { return fmt.Errorf("Unexpected error: %s", err) } } diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index 9cb6a86b0..b62df2dec 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -8,6 +8,7 @@ import ( "time" "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/iam" "github.com/hashicorp/terraform/helper/hashcode" @@ -310,9 +311,9 @@ func CacheClusterStateRefreshFunc(conn *elasticache.ElastiCache, clusterID, give CacheClusterID: aws.String(clusterID), }) if err != nil { - apierr := err.(aws.APIError) - log.Printf("[DEBUG] message: %v, code: %v", apierr.Message, apierr.Code) - if apierr.Message == fmt.Sprintf("CacheCluster not found: %v", clusterID) { + apierr := err.(awserr.Error) + log.Printf("[DEBUG] message: %v, code: %v", apierr.Message(), apierr.Code()) + if apierr.Message() == fmt.Sprintf("CacheCluster not found: %v", clusterID) { log.Printf("[DEBUG] Detect deletion") return nil, "", nil } diff --git a/builtin/providers/aws/resource_aws_elasticache_security_group.go b/builtin/providers/aws/resource_aws_elasticache_security_group.go index d9ce60198..4fb47f85b 100644 --- a/builtin/providers/aws/resource_aws_elasticache_security_group.go +++ b/builtin/providers/aws/resource_aws_elasticache_security_group.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" @@ -125,12 +126,12 @@ func resourceAwsElasticacheSecurityGroupDelete(d *schema.ResourceData, meta inte CacheSecurityGroupName: aws.String(d.Id()), }) if err != nil { - apierr, ok := err.(aws.APIError) + apierr, ok := err.(awserr.Error) if !ok { return err } log.Printf("[DEBUG] APIError.Code: %v", apierr.Code) - switch apierr.Code { + switch apierr.Code() { case "InvalidCacheSecurityGroupState": return err case "DependencyViolation": diff --git a/builtin/providers/aws/resource_aws_elasticache_subnet_group.go b/builtin/providers/aws/resource_aws_elasticache_subnet_group.go index eb74de283..0c1605016 100644 --- a/builtin/providers/aws/resource_aws_elasticache_subnet_group.go +++ b/builtin/providers/aws/resource_aws_elasticache_subnet_group.go @@ -5,6 +5,7 @@ import ( "log" "time" + "github.com/awslabs/aws-sdk-go/aws/awserr" "github.com/awslabs/aws-sdk-go/service/elasticache" "github.com/hashicorp/aws-sdk-go/aws" "github.com/hashicorp/terraform/helper/hashcode" @@ -119,12 +120,12 @@ func resourceAwsElasticacheSubnetGroupDelete(d *schema.ResourceData, meta interf CacheSubnetGroupName: aws.String(d.Id()), }) if err != nil { - apierr, ok := err.(aws.APIError) + apierr, ok := err.(awserr.Error) if !ok { return err } log.Printf("[DEBUG] APIError.Code: %v", apierr.Code) - switch apierr.Code { + switch apierr.Code() { case "DependencyViolation": // If it is a dependency violation, we want to retry return err diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 4b8a96442..0afcba888 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -6,6 +6,7 @@ import ( "log" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" @@ -552,6 +553,6 @@ func resourceAwsElbListenerHash(v interface{}) int { } func isLoadBalancerNotFound(err error) bool { - elberr, ok := err.(aws.APIError) - return ok && elberr.Code == "LoadBalancerNotFound" + elberr, ok := err.(awserr.Error) + return ok && elberr.Code() == "LoadBalancerNotFound" } diff --git a/builtin/providers/aws/resource_aws_elb_test.go b/builtin/providers/aws/resource_aws_elb_test.go index 17cda3899..6c5b685ac 100644 --- a/builtin/providers/aws/resource_aws_elb_test.go +++ b/builtin/providers/aws/resource_aws_elb_test.go @@ -8,6 +8,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -381,12 +382,12 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error { } // Verify the error - providerErr, ok := err.(aws.APIError) + providerErr, ok := err.(awserr.Error) if !ok { return err } - if providerErr.Code != "InvalidLoadBalancerName.NotFound" { + if providerErr.Code() != "InvalidLoadBalancerName.NotFound" { return fmt.Errorf("Unexpected error: %s", err) } } diff --git a/builtin/providers/aws/resource_aws_iam_access_key.go b/builtin/providers/aws/resource_aws_iam_access_key.go index efeec62f7..491e547fc 100644 --- a/builtin/providers/aws/resource_aws_iam_access_key.go +++ b/builtin/providers/aws/resource_aws_iam_access_key.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -71,7 +72,7 @@ func resourceAwsIamAccessKeyRead(d *schema.ResourceData, meta interface{}) error getResp, err := iamconn.ListAccessKeys(request) 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. d.SetId("") return nil diff --git a/builtin/providers/aws/resource_aws_iam_access_key_test.go b/builtin/providers/aws/resource_aws_iam_access_key_test.go index 0aacc058d..ef6e49de1 100644 --- a/builtin/providers/aws/resource_aws_iam_access_key_test.go +++ b/builtin/providers/aws/resource_aws_iam_access_key_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -49,11 +50,11 @@ func testAccCheckAWSAccessKeyDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "NoSuchEntity" { + if ec2err.Code() != "NoSuchEntity" { return err } } diff --git a/builtin/providers/aws/resource_aws_iam_group.go b/builtin/providers/aws/resource_aws_iam_group.go index 1d0bc6cf4..98a5354fe 100644 --- a/builtin/providers/aws/resource_aws_iam_group.go +++ b/builtin/providers/aws/resource_aws_iam_group.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -66,7 +67,7 @@ func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error { getResp, err := iamconn.GetGroup(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_group_policy.go b/builtin/providers/aws/resource_aws_iam_group_policy.go index 51190aa5f..cf34faaa1 100644 --- a/builtin/providers/aws/resource_aws_iam_group_policy.go +++ b/builtin/providers/aws/resource_aws_iam_group_policy.go @@ -6,6 +6,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" @@ -66,9 +67,10 @@ func resourceAwsIamGroupPolicyRead(d *schema.ResourceData, meta interface{}) err GroupName: aws.String(group), } + var err error getResp, err := iamconn.GetGroupPolicy(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_group_test.go b/builtin/providers/aws/resource_aws_iam_group_test.go index 389161017..4200cdbe0 100644 --- a/builtin/providers/aws/resource_aws_iam_group_test.go +++ b/builtin/providers/aws/resource_aws_iam_group_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -46,11 +47,11 @@ func testAccCheckAWSGroupDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "NoSuchEntity" { + if ec2err.Code() != "NoSuchEntity" { return err } } diff --git a/builtin/providers/aws/resource_aws_iam_instance_profile.go b/builtin/providers/aws/resource_aws_iam_instance_profile.go index 7a69ae2da..4d3e10ae6 100644 --- a/builtin/providers/aws/resource_aws_iam_instance_profile.go +++ b/builtin/providers/aws/resource_aws_iam_instance_profile.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -59,6 +60,7 @@ func resourceAwsIamInstanceProfileCreate(d *schema.ResourceData, meta interface{ Path: aws.String(d.Get("path").(string)), } + var err error response, err := iamconn.CreateInstanceProfile(request) if err == nil { err = instanceProfileReadResult(d, response.InstanceProfile) @@ -87,7 +89,7 @@ func instanceProfileRemoveRole(iamconn *iam.IAM, profileName, roleName string) e } _, 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 err @@ -156,7 +158,7 @@ func resourceAwsIamInstanceProfileRead(d *schema.ResourceData, meta interface{}) result, err := iamconn.GetInstanceProfile(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_policy.go b/builtin/providers/aws/resource_aws_iam_policy.go index 9d4e3d6dd..c0a435fdb 100644 --- a/builtin/providers/aws/resource_aws_iam_policy.go +++ b/builtin/providers/aws/resource_aws_iam_policy.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -73,7 +74,7 @@ func resourceAwsIamPolicyRead(d *schema.ResourceData, meta interface{}) error { response, err := iamconn.GetPolicy(request) 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("") return nil } @@ -118,7 +119,7 @@ func resourceAwsIamPolicyDelete(d *schema.ResourceData, meta interface{}) error _, err := iamconn.DeletePolicy(request) 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 fmt.Errorf("Error reading IAM policy %s: %#v", d.Id(), err) diff --git a/builtin/providers/aws/resource_aws_iam_role.go b/builtin/providers/aws/resource_aws_iam_role.go index 6a9bdc00a..f8ec7b358 100644 --- a/builtin/providers/aws/resource_aws_iam_role.go +++ b/builtin/providers/aws/resource_aws_iam_role.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -72,7 +73,7 @@ func resourceAwsIamRoleRead(d *schema.ResourceData, meta interface{}) error { getResp, err := iamconn.GetRole(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_role_policy.go b/builtin/providers/aws/resource_aws_iam_role_policy.go index 0eb073a9d..d3f7dbae3 100644 --- a/builtin/providers/aws/resource_aws_iam_role_policy.go +++ b/builtin/providers/aws/resource_aws_iam_role_policy.go @@ -6,6 +6,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" @@ -66,9 +67,10 @@ func resourceAwsIamRolePolicyRead(d *schema.ResourceData, meta interface{}) erro RoleName: aws.String(role), } + var err error getResp, err := iamconn.GetRolePolicy(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_role_test.go b/builtin/providers/aws/resource_aws_iam_role_test.go index d7f05fcfc..cbb75c3c4 100644 --- a/builtin/providers/aws/resource_aws_iam_role_test.go +++ b/builtin/providers/aws/resource_aws_iam_role_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -46,11 +47,11 @@ func testAccCheckAWSRoleDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "NoSuchEntity" { + if ec2err.Code() != "NoSuchEntity" { return err } } diff --git a/builtin/providers/aws/resource_aws_iam_user.go b/builtin/providers/aws/resource_aws_iam_user.go index 73c5ac8f0..3fffd2665 100644 --- a/builtin/providers/aws/resource_aws_iam_user.go +++ b/builtin/providers/aws/resource_aws_iam_user.go @@ -4,6 +4,7 @@ import ( "fmt" "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/hashicorp/terraform/helper/schema" @@ -75,7 +76,7 @@ func resourceAwsIamUserRead(d *schema.ResourceData, meta interface{}) error { getResp, err := iamconn.GetUser(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_user_policy.go b/builtin/providers/aws/resource_aws_iam_user_policy.go index 96ea6afc0..80cb044ff 100644 --- a/builtin/providers/aws/resource_aws_iam_user_policy.go +++ b/builtin/providers/aws/resource_aws_iam_user_policy.go @@ -6,6 +6,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" @@ -66,9 +67,10 @@ func resourceAwsIamUserPolicyRead(d *schema.ResourceData, meta interface{}) erro UserName: aws.String(user), } + var err error getResp, err := iamconn.GetUserPolicy(request) 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_iam_user_test.go b/builtin/providers/aws/resource_aws_iam_user_test.go index 513636f98..7db0ae670 100644 --- a/builtin/providers/aws/resource_aws_iam_user_test.go +++ b/builtin/providers/aws/resource_aws_iam_user_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -46,11 +47,11 @@ func testAccCheckAWSUserDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "NoSuchEntity" { + if ec2err.Code() != "NoSuchEntity" { return err } } diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index e51892475..8224ba4f2 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -11,6 +11,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" @@ -515,6 +516,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error { // Create the instance log.Printf("[DEBUG] Run configuration: %#v", runOpts) + var err error runResp, err := conn.RunInstances(runOpts) if err != nil { 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 the instance was not found, return nil so that we can show // 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("") return nil } @@ -776,7 +778,7 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRe InstanceIDs: []*string{aws.String(instanceID)}, }) 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. resp = nil } else { diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index b976b836f..b90cf436a 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -6,6 +6,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -482,6 +483,7 @@ func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schem } // Try to find the resource + var err error resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{ 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 - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidInstanceID.NotFound" { + if ec2err.Code() != "InvalidInstanceID.NotFound" { return err } } @@ -526,7 +528,7 @@ func testAccCheckInstanceExistsWithProviders(n string, i *ec2.Instance, provider resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{ 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 } if err != nil { diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go index 706a337ec..d0bcd47b5 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway.go +++ b/builtin/providers/aws/resource_aws_internet_gateway.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -33,6 +34,7 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{}) // Create the gateway log.Printf("[DEBUG] Creating internet gateway") + var err error resp, err := conn.CreateInternetGateway(nil) if err != nil { return fmt.Errorf("Error creating internet gateway: %s", err) @@ -120,12 +122,12 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{}) return nil } - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - switch ec2err.Code { + switch ec2err.Code() { case "InvalidInternetGatewayID.NotFound": return nil case "DependencyViolation": @@ -226,13 +228,13 @@ func detachIGStateRefreshFunc(conn *ec2.EC2, instanceID, vpcID string) resource. VPCID: aws.String(vpcID), }) if err != nil { - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if ok { - if ec2err.Code == "InvalidInternetGatewayID.NotFound" { + if ec2err.Code() == "InvalidInternetGatewayID.NotFound" { return nil, "Not Found", err - } else if ec2err.Code == "Gateway.NotAttached" { + } else if ec2err.Code() == "Gateway.NotAttached" { return "detached", "detached", nil - } else if ec2err.Code == "DependencyViolation" { + } else if ec2err.Code() == "DependencyViolation" { return nil, "detaching", nil } } @@ -251,8 +253,8 @@ func IGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { InternetGatewayIDs: []*string{aws.String(id)}, }) if err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidInternetGatewayID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" { resp = nil } else { 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)}, }) if err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidInternetGatewayID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" { resp = nil } else { log.Printf("[ERROR] Error on IGStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_internet_gateway_test.go b/builtin/providers/aws/resource_aws_internet_gateway_test.go index 93897308c..23aeb1e2e 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway_test.go +++ b/builtin/providers/aws/resource_aws_internet_gateway_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -135,11 +136,11 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidInternetGatewayID.NotFound" { + if ec2err.Code() != "InvalidInternetGatewayID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_key_pair_test.go b/builtin/providers/aws/resource_aws_key_pair_test.go index 62c1b57cf..874c74406 100644 --- a/builtin/providers/aws/resource_aws_key_pair_test.go +++ b/builtin/providers/aws/resource_aws_key_pair_test.go @@ -6,6 +6,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -78,11 +79,11 @@ func testAccCheckAWSKeyPairDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidKeyPair.NotFound" { + if ec2err.Code() != "InvalidKeyPair.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index f7d1acf95..0ba78aa72 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -10,6 +10,7 @@ import ( "time" "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/ec2" "github.com/hashicorp/terraform/helper/hashcode" @@ -440,8 +441,8 @@ func resourceAwsLaunchConfigurationDelete(d *schema.ResourceData, meta interface LaunchConfigurationName: aws.String(d.Id()), }) if err != nil { - autoscalingerr, ok := err.(aws.APIError) - if ok && autoscalingerr.Code == "InvalidConfiguration.NotFound" { + autoscalingerr, ok := err.(awserr.Error) + if ok && autoscalingerr.Code() == "InvalidConfiguration.NotFound" { return nil } diff --git a/builtin/providers/aws/resource_aws_launch_configuration_test.go b/builtin/providers/aws/resource_aws_launch_configuration_test.go index 775288dba..86c970c32 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration_test.go +++ b/builtin/providers/aws/resource_aws_launch_configuration_test.go @@ -8,6 +8,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -119,11 +120,11 @@ func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error { } // Verify the error - providerErr, ok := err.(aws.APIError) + providerErr, ok := err.(awserr.Error) if !ok { return err } - if providerErr.Code != "InvalidLaunchConfiguration.NotFound" { + if providerErr.Code() != "InvalidLaunchConfiguration.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy.go b/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy.go index cc3d89c76..7907e3df4 100644 --- a/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy.go +++ b/builtin/providers/aws/resource_aws_lb_cookie_stickiness_policy.go @@ -5,6 +5,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" ) @@ -90,7 +91,7 @@ func resourceAwsLBCookieStickinessPolicyRead(d *schema.ResourceData, meta interf getResp, err := elbconn.DescribeLoadBalancerPolicies(request) 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. d.SetId("") return nil diff --git a/builtin/providers/aws/resource_aws_network_acl.go b/builtin/providers/aws/resource_aws_network_acl.go index 081a288b4..4ff439493 100644 --- a/builtin/providers/aws/resource_aws_network_acl.go +++ b/builtin/providers/aws/resource_aws_network_acl.go @@ -9,6 +9,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" @@ -393,8 +394,8 @@ func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error NetworkACLID: aws.String(d.Id()), }) if err != nil { - ec2err := err.(aws.APIError) - switch ec2err.Code { + ec2err := err.(awserr.Error) + switch ec2err.Code() { case "InvalidNetworkAclID.NotFound": return nil case "DependencyViolation": diff --git a/builtin/providers/aws/resource_aws_network_acl_test.go b/builtin/providers/aws/resource_aws_network_acl_test.go index 8c5686786..1e625fc83 100644 --- a/builtin/providers/aws/resource_aws_network_acl_test.go +++ b/builtin/providers/aws/resource_aws_network_acl_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -244,12 +245,12 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error { return nil } - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } // Confirm error code is what we want - if ec2err.Code != "InvalidNetworkAclID.NotFound" { + if ec2err.Code() != "InvalidNetworkAclID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_network_interface.go b/builtin/providers/aws/resource_aws_network_interface.go index 446627c34..ec029778f 100644 --- a/builtin/providers/aws/resource_aws_network_interface.go +++ b/builtin/providers/aws/resource_aws_network_interface.go @@ -8,6 +8,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "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) 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 d.SetId("") return nil diff --git a/builtin/providers/aws/resource_aws_network_interface_test.go b/builtin/providers/aws/resource_aws_network_interface_test.go index 6df6ded7a..d40802590 100644 --- a/builtin/providers/aws/resource_aws_network_interface_test.go +++ b/builtin/providers/aws/resource_aws_network_interface_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -155,7 +156,7 @@ func testAccCheckAWSENIDestroy(s *terraform.State) error { _, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request) 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 } diff --git a/builtin/providers/aws/resource_aws_proxy_protocol_policy.go b/builtin/providers/aws/resource_aws_proxy_protocol_policy.go index bdd5a8a5a..1b428195d 100644 --- a/builtin/providers/aws/resource_aws_proxy_protocol_policy.go +++ b/builtin/providers/aws/resource_aws_proxy_protocol_policy.go @@ -165,6 +165,7 @@ func resourceAwsProxyProtocolPolicyDelete(d *schema.ResourceData, meta interface req := &elb.DescribeLoadBalancersInput{ LoadBalancerNames: []*string{elbname}, } + var err error resp, err := elbconn.DescribeLoadBalancers(req) if err != nil { if isLoadBalancerNotFound(err) { diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 268bf2d04..e59d8e50e 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "github.com/awslabs/aws-sdk-go/service/route53" ) @@ -116,6 +117,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er conn := meta.(*AWSClient).r53conn zone := cleanZoneID(d.Get("zone_id").(string)) + var err error zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)}) if err != nil { return err @@ -156,8 +158,8 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er Refresh: func() (interface{}, string, error) { resp, err := conn.ChangeResourceRecordSets(req) if err != nil { - if r53err, ok := err.(aws.APIError); ok { - if r53err.Code == "PriorRequestNotComplete" { + if r53err, ok := err.(awserr.Error); ok { + if r53err.Code() == "PriorRequestNotComplete" { // There is some pending operation, so just retry // in a bit. return nil, "rejected", nil @@ -280,6 +282,7 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er zone := cleanZoneID(d.Get("zone_id").(string)) log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s", zone, d.Get("name").(string)) + var err error zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)}) if err != nil { return err @@ -314,14 +317,14 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er Refresh: func() (interface{}, string, error) { _, err := conn.ChangeResourceRecordSets(req) if err != nil { - if r53err, ok := err.(aws.APIError); ok { - if r53err.Code == "PriorRequestNotComplete" { + if r53err, ok := err.(awserr.Error); ok { + if r53err.Code() == "PriorRequestNotComplete" { // There is some pending operation, so just retry // in a bit. return 42, "rejected", nil } - if r53err.Code == "InvalidChangeBatch" { + if r53err.Code() == "InvalidChangeBatch" { // This means that the record is already gone. return 42, "accepted", nil } diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index b89907371..6d6f6782a 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "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) + var err error resp, err := r53.CreateHostedZone(req) if err != nil { 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())}) if err != nil { // 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_route53_zone_association.go b/builtin/providers/aws/resource_aws_route53_zone_association.go index d2fc2a2c4..808b92912 100644 --- a/builtin/providers/aws/resource_aws_route53_zone_association.go +++ b/builtin/providers/aws/resource_aws_route53_zone_association.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "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) + var err error resp, err := r53.AssociateVPCWithHostedZone(req) if err != nil { return err @@ -93,7 +95,7 @@ func resourceAwsRoute53ZoneAssociationRead(d *schema.ResourceData, meta interfac zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone_id)}) if err != nil { // 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("") return nil } diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 75e6af6e9..26248bac1 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "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 // eventually consistency stuff. So we have to just wait a // bit... - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "Gateway.NotAttached" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "Gateway.NotAttached" { time.Sleep(20 * time.Second) continue } @@ -329,8 +330,8 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error RouteTableID: aws.String(d.Id()), }) if err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidRouteTableID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidRouteTableID.NotFound" { return nil } @@ -391,7 +392,7 @@ func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.St RouteTableIDs: []*string{aws.String(id)}, }) 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 } else { log.Printf("Error on RouteTableStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_route_table_association.go b/builtin/providers/aws/resource_aws_route_table_association.go index eb9d9663a..3115363a9 100644 --- a/builtin/providers/aws/resource_aws_route_table_association.go +++ b/builtin/providers/aws/resource_aws_route_table_association.go @@ -5,6 +5,7 @@ import ( "log" "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/hashicorp/terraform/helper/schema" ) @@ -102,8 +103,8 @@ func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interfa resp, err := conn.ReplaceRouteTableAssociation(req) if err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidAssociationID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidAssociationID.NotFound" { // Not found, so just create a new one return resourceAwsRouteTableAssociationCreate(d, meta) } @@ -126,8 +127,8 @@ func resourceAwsRouteTableAssociationDelete(d *schema.ResourceData, meta interfa AssociationID: aws.String(d.Id()), }) if err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidAssociationID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidAssociationID.NotFound" { return nil } diff --git a/builtin/providers/aws/resource_aws_route_table_association_test.go b/builtin/providers/aws/resource_aws_route_table_association_test.go index 2729bd1f0..19ddaae38 100644 --- a/builtin/providers/aws/resource_aws_route_table_association_test.go +++ b/builtin/providers/aws/resource_aws_route_table_association_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -51,11 +52,11 @@ func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error { }) if err != nil { // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidRouteTableID.NotFound" { + if ec2err.Code() != "InvalidRouteTableID.NotFound" { return err } return nil diff --git a/builtin/providers/aws/resource_aws_route_table_test.go b/builtin/providers/aws/resource_aws_route_table_test.go index 74f6ab2ac..6020545ed 100644 --- a/builtin/providers/aws/resource_aws_route_table_test.go +++ b/builtin/providers/aws/resource_aws_route_table_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -171,11 +172,11 @@ func testAccCheckRouteTableDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidRouteTableID.NotFound" { + if ec2err.Code() != "InvalidRouteTableID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index d615151f1..142b80069 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "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 { s3conn := meta.(*AWSClient).s3conn - _, err := s3conn.HeadBucket(&s3.HeadBucketInput{ + var err error + _, err = s3conn.HeadBucket(&s3.HeadBucketInput{ Bucket: aws.String(d.Id()), }) 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("") } else { // some of the AWS SDK's errors can be empty strings, so let's add diff --git a/builtin/providers/aws/resource_aws_security_group.go b/builtin/providers/aws/resource_aws_security_group.go index c25827971..310e478d7 100644 --- a/builtin/providers/aws/resource_aws_security_group.go +++ b/builtin/providers/aws/resource_aws_security_group.go @@ -8,6 +8,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" @@ -166,6 +167,7 @@ func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er } securityGroupOpts.GroupName = aws.String(groupName) + var err error log.Printf( "[DEBUG] Security Group create configuration: %#v", securityGroupOpts) createResp, err := conn.CreateSecurityGroup(securityGroupOpts) @@ -300,12 +302,12 @@ func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) er GroupID: aws.String(d.Id()), }) if err != nil { - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - switch ec2err.Code { + switch ec2err.Code() { case "InvalidGroup.NotFound": return nil case "DependencyViolation": @@ -530,9 +532,9 @@ func SGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { } resp, err := conn.DescribeSecurityGroups(req) if err != nil { - if ec2err, ok := err.(aws.APIError); ok { - if ec2err.Code == "InvalidSecurityGroupID.NotFound" || - ec2err.Code == "InvalidGroup.NotFound" { + if ec2err, ok := err.(awserr.Error); ok { + if ec2err.Code() == "InvalidSecurityGroupID.NotFound" || + ec2err.Code() == "InvalidGroup.NotFound" { resp = nil err = nil } diff --git a/builtin/providers/aws/resource_aws_security_group_rule.go b/builtin/providers/aws/resource_aws_security_group_rule.go index b5fb3058f..9e8c7c13d 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule.go +++ b/builtin/providers/aws/resource_aws_security_group_rule.go @@ -8,6 +8,7 @@ import ( "strings" "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/hashicorp/terraform/helper/hashcode" "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) if err != nil { - if ec2err, ok := err.(aws.APIError); ok { - if ec2err.Code == "InvalidSecurityGroupID.NotFound" || - ec2err.Code == "InvalidGroup.NotFound" { + if ec2err, ok := err.(awserr.Error); ok { + if ec2err.Code() == "InvalidSecurityGroupID.NotFound" || + ec2err.Code() == "InvalidGroup.NotFound" { resp = nil err = nil } diff --git a/builtin/providers/aws/resource_aws_security_group_rule_test.go b/builtin/providers/aws/resource_aws_security_group_rule_test.go index ff75b4431..e02694ab0 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule_test.go +++ b/builtin/providers/aws/resource_aws_security_group_rule_test.go @@ -6,6 +6,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -216,12 +217,12 @@ func testAccCheckAWSSecurityGroupRuleDestroy(s *terraform.State) error { return nil } - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } // Confirm error code is what we want - if ec2err.Code != "InvalidGroup.NotFound" { + if ec2err.Code() != "InvalidGroup.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_security_group_test.go b/builtin/providers/aws/resource_aws_security_group_test.go index 406df4791..e0e138cd8 100644 --- a/builtin/providers/aws/resource_aws_security_group_test.go +++ b/builtin/providers/aws/resource_aws_security_group_test.go @@ -7,6 +7,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -310,12 +311,12 @@ func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error { return nil } - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } // Confirm error code is what we want - if ec2err.Code != "InvalidGroup.NotFound" { + if ec2err.Code() != "InvalidGroup.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_sqs_queue.go b/builtin/providers/aws/resource_aws_sqs_queue.go index 6aa56a553..b664bf2eb 100644 --- a/builtin/providers/aws/resource_aws_sqs_queue.go +++ b/builtin/providers/aws/resource_aws_sqs_queue.go @@ -12,16 +12,15 @@ import ( ) var AttributeMap = map[string]string{ - "delay_seconds" : "DelaySeconds", - "max_message_size" : "MaximumMessageSize", - "message_retention_seconds" : "MessageRetentionPeriod", - "receive_wait_time_seconds" : "ReceiveMessageWaitTimeSeconds", - "visibility_timeout_seconds" : "VisibilityTimeout", - "policy" : "Policy", - "redrive_policy": "RedrivePolicy", + "delay_seconds": "DelaySeconds", + "max_message_size": "MaximumMessageSize", + "message_retention_seconds": "MessageRetentionPeriod", + "receive_wait_time_seconds": "ReceiveMessageWaitTimeSeconds", + "visibility_timeout_seconds": "VisibilityTimeout", + "policy": "Policy", + "redrive_policy": "RedrivePolicy", } - // 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 // default values specified below) @@ -39,12 +38,12 @@ func resourceAwsSqsQueue() *schema.Resource { ForceNew: true, }, "delay_seconds": &schema.Schema{ - Type: schema.TypeInt, + Type: schema.TypeInt, Optional: true, Computed: true, }, "max_message_size": &schema.Schema{ - Type: schema.TypeInt, + Type: schema.TypeInt, Optional: true, Computed: true, }, @@ -79,14 +78,14 @@ func resourceAwsSqsQueueCreate(d *schema.ResourceData, meta interface{}) error { sqsconn := meta.(*AWSClient).sqsconn name := d.Get("name").(string) - + log.Printf("[DEBUG] SQS queue create: %s", name) req := &sqs.CreateQueueInput{ QueueName: aws.String(name), } - attributes := make(map[string]*string) + attributes := make(map[string]*string) resource := *resourceAwsSqsQueue() @@ -139,11 +138,11 @@ func resourceAwsSqsQueueUpdate(d *schema.ResourceData, meta interface{}) error { if len(attributes) > 0 { req := &sqs.SetQueueAttributesInput{ - QueueURL: aws.String(d.Id()), + QueueURL: aws.String(d.Id()), Attributes: &attributes, } sqsconn.SetQueueAttributes(req) - } + } return resourceAwsSqsQueueRead(d, meta) } @@ -152,7 +151,7 @@ func resourceAwsSqsQueueRead(d *schema.ResourceData, meta interface{}) error { sqsconn := meta.(*AWSClient).sqsconn attributeOutput, err := sqsconn.GetQueueAttributes(&sqs.GetQueueAttributesInput{ - QueueURL: aws.String(d.Id()), + QueueURL: aws.String(d.Id()), AttributeNames: []*string{aws.String("All")}, }) if err != nil { @@ -167,7 +166,7 @@ func resourceAwsSqsQueueRead(d *schema.ResourceData, meta interface{}) error { if attrmap[oKey] != nil { if resource.Schema[iKey].Type == schema.TypeInt { value, err := strconv.Atoi(*attrmap[oKey]) - if err != nil { + if err != nil { return err } d.Set(iKey, value) @@ -193,5 +192,3 @@ func resourceAwsSqsQueueDelete(d *schema.ResourceData, meta interface{}) error { } return nil } - - diff --git a/builtin/providers/aws/resource_aws_sqs_queue_test.go b/builtin/providers/aws/resource_aws_sqs_queue_test.go index 5f99b6615..f6d990c3a 100644 --- a/builtin/providers/aws/resource_aws_sqs_queue_test.go +++ b/builtin/providers/aws/resource_aws_sqs_queue_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -32,7 +33,6 @@ func TestAccAWSSQSQueue(t *testing.T) { }) } - func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).sqsconn @@ -51,7 +51,7 @@ func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error { } // Verify the error is what we want - _, ok := err.(aws.APIError) + _, ok := err.(awserr.Error) if !ok { return err } @@ -60,7 +60,6 @@ func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error { return nil } - func testAccCheckAWSSQSExistsWithDefaults(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -75,7 +74,7 @@ func testAccCheckAWSSQSExistsWithDefaults(n string) resource.TestCheckFunc { conn := testAccProvider.Meta().(*AWSClient).sqsconn params := &sqs.GetQueueAttributesInput{ - QueueURL: aws.String(rs.Primary.ID), + QueueURL: aws.String(rs.Primary.ID), AttributeNames: []*string{aws.String("All")}, } resp, err := conn.GetQueueAttributes(params) @@ -125,7 +124,7 @@ func testAccCheckAWSSQSExistsWithOverrides(n string) resource.TestCheckFunc { conn := testAccProvider.Meta().(*AWSClient).sqsconn params := &sqs.GetQueueAttributesInput{ - QueueURL: aws.String(rs.Primary.ID), + QueueURL: aws.String(rs.Primary.ID), AttributeNames: []*string{aws.String("All")}, } resp, err := conn.GetQueueAttributes(params) @@ -176,4 +175,4 @@ resource "aws_sqs_queue" "queue-with-overrides" { receive_wait_time_seconds = 10 visibility_timeout_seconds = 60 } -` \ No newline at end of file +` diff --git a/builtin/providers/aws/resource_aws_subnet.go b/builtin/providers/aws/resource_aws_subnet.go index 5d10d0da5..f6d56681a 100644 --- a/builtin/providers/aws/resource_aws_subnet.go +++ b/builtin/providers/aws/resource_aws_subnet.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "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)), } + var err error resp, err := conn.CreateSubnet(createOpts) if err != nil { @@ -98,7 +100,7 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error { }) 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. d.SetId("") return nil @@ -171,14 +173,14 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error { Refresh: func() (interface{}, string, error) { _, err := conn.DeleteSubnet(req) if err != nil { - if apiErr, ok := err.(aws.APIError); ok { - if apiErr.Code == "DependencyViolation" { + if apiErr, ok := err.(awserr.Error); ok { + if apiErr.Code() == "DependencyViolation" { // There is some pending operation, so just retry // in a bit. return 42, "pending", nil } - if apiErr.Code == "InvalidSubnetID.NotFound" { + if apiErr.Code() == "InvalidSubnetID.NotFound" { return 42, "destroyed", nil } } @@ -204,7 +206,7 @@ func SubnetStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc SubnetIDs: []*string{aws.String(id)}, }) 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 } else { log.Printf("Error on SubnetStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_subnet_test.go b/builtin/providers/aws/resource_aws_subnet_test.go index fbf1f4a92..206333d41 100644 --- a/builtin/providers/aws/resource_aws_subnet_test.go +++ b/builtin/providers/aws/resource_aws_subnet_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -63,11 +64,11 @@ func testAccCheckSubnetDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidSubnetID.NotFound" { + if ec2err.Code() != "InvalidSubnetID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index fca43891c..b13c1521b 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "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()) if _, err := conn.DeleteVPC(DeleteVpcOpts); err != nil { - ec2err, ok := err.(aws.APIError) - if ok && ec2err.Code == "InvalidVpcID.NotFound" { + ec2err, ok := err.(awserr.Error) + if ok && ec2err.Code() == "InvalidVpcID.NotFound" { return nil } @@ -267,7 +268,7 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { } resp, err := conn.DescribeVPCs(DescribeVpcOpts) 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 } else { log.Printf("Error on VPCStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go index 89e16b4e3..4fd2d24f4 100644 --- a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go +++ b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -191,12 +192,12 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e log.Printf("[WARN] %s", err) - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - switch ec2err.Code { + switch ec2err.Code() { case "InvalidDhcpOptionsID.NotFound": return nil case "DependencyViolation": @@ -241,7 +242,7 @@ func findVPCsByDHCPOptionsID(conn *ec2.EC2, id string) ([]*ec2.VPC, error) { resp, err := conn.DescribeVPCs(req) 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, err @@ -260,7 +261,7 @@ func DHCPOptionsStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefresh resp, err := conn.DescribeDHCPOptions(DescribeDhcpOpts) 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 } else { log.Printf("Error on DHCPOptionsStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go b/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go index 74ab93953..221ba99fc 100644 --- a/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go +++ b/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -58,11 +59,11 @@ func testAccCheckDHCPOptionsDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidDhcpOptionsID.NotFound" { + if ec2err.Code() != "InvalidDhcpOptionsID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index c3e097c38..9a277a92b 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -179,7 +180,7 @@ func resourceAwsVPCPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r VPCPeeringConnectionIDs: []*string{aws.String(id)}, }) 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 } else { log.Printf("Error on VPCPeeringConnectionStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index 0abf8bc63..8ee7820aa 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -133,11 +134,11 @@ func testAccCheckVpcDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidVpcID.NotFound" { + if ec2err.Code() != "InvalidVpcID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_aws_vpn_connection.go b/builtin/providers/aws/resource_aws_vpn_connection.go index bd8e1b16e..5780c887d 100644 --- a/builtin/providers/aws/resource_aws_vpn_connection.go +++ b/builtin/providers/aws/resource_aws_vpn_connection.go @@ -7,6 +7,7 @@ import ( "time" "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/hashicorp/terraform/helper/hashcode" @@ -200,7 +201,7 @@ func vpnConnectionRefreshFunc(conn *ec2.EC2, connectionId string) resource.State }) 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 } else { 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())}, }) 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("") return nil } else { @@ -285,7 +286,7 @@ func resourceAwsVpnConnectionDelete(d *schema.ResourceData, meta interface{}) er VPNConnectionID: aws.String(d.Id()), }) 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("") return nil } else { diff --git a/builtin/providers/aws/resource_aws_vpn_gateway.go b/builtin/providers/aws/resource_aws_vpn_gateway.go index 03b171ca3..b909a460d 100644 --- a/builtin/providers/aws/resource_aws_vpn_gateway.go +++ b/builtin/providers/aws/resource_aws_vpn_gateway.go @@ -6,6 +6,7 @@ import ( "time" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -66,7 +67,7 @@ func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error { VPNGatewayIDs: []*string{aws.String(d.Id())}, }) 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("") return nil } else { @@ -136,12 +137,12 @@ func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error return nil } - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - switch ec2err.Code { + switch ec2err.Code() { case "InvalidVpnGatewayID.NotFound": return nil case "IncorrectState": @@ -221,12 +222,12 @@ func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error VPCID: aws.String(vpcID.(string)), }) if err != nil { - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if ok { - if ec2err.Code == "InvalidVpnGatewayID.NotFound" { + if ec2err.Code() == "InvalidVpnGatewayID.NotFound" { err = nil wait = false - } else if ec2err.Code == "InvalidVpnGatewayAttachment.NotFound" { + } else if ec2err.Code() == "InvalidVpnGatewayAttachment.NotFound" { err = nil wait = false } @@ -271,7 +272,7 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) VPNGatewayIDs: []*string{aws.String(id)}, }) 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 } else { log.Printf("[ERROR] Error on VpnGatewayStateRefresh: %s", err) diff --git a/builtin/providers/aws/resource_aws_vpn_gateway_test.go b/builtin/providers/aws/resource_aws_vpn_gateway_test.go index 679c5fa81..1643da86c 100644 --- a/builtin/providers/aws/resource_aws_vpn_gateway_test.go +++ b/builtin/providers/aws/resource_aws_vpn_gateway_test.go @@ -5,6 +5,7 @@ import ( "testing" "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/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -135,11 +136,11 @@ func testAccCheckVpnGatewayDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(aws.APIError) + ec2err, ok := err.(awserr.Error) if !ok { return err } - if ec2err.Code != "InvalidVpnGatewayID.NotFound" { + if ec2err.Code() != "InvalidVpnGatewayID.NotFound" { return err } } diff --git a/builtin/providers/aws/resource_vpn_connection_route.go b/builtin/providers/aws/resource_vpn_connection_route.go index 863a891e7..198f730d2 100644 --- a/builtin/providers/aws/resource_vpn_connection_route.go +++ b/builtin/providers/aws/resource_vpn_connection_route.go @@ -6,6 +6,7 @@ import ( "strings" "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/hashicorp/terraform/helper/schema" @@ -82,7 +83,7 @@ func resourceAwsVpnConnectionRouteRead(d *schema.ResourceData, meta interface{}) Filters: routeFilters, }) 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("") return nil } else { @@ -117,7 +118,7 @@ func resourceAwsVpnConnectionRouteDelete(d *schema.ResourceData, meta interface{ VPNConnectionID: aws.String(d.Get("vpn_connection_id").(string)), }) 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("") return nil } else { diff --git a/builtin/providers/aws/s3_tags.go b/builtin/providers/aws/s3_tags.go index 388a2df7a..01782f238 100644 --- a/builtin/providers/aws/s3_tags.go +++ b/builtin/providers/aws/s3_tags.go @@ -4,6 +4,7 @@ import ( "log" "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/hashicorp/terraform/helper/schema" ) @@ -101,7 +102,7 @@ func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) { } 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. return []*s3.Tag{}, nil } else if err != nil { diff --git a/state/remote/s3.go b/state/remote/s3.go index 6db07d070..8ff50a2df 100644 --- a/state/remote/s3.go +++ b/state/remote/s3.go @@ -7,6 +7,7 @@ import ( "os" "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/service/s3" ) @@ -78,8 +79,8 @@ func (c *S3Client) Get() (*Payload, error) { }) if err != nil { - if awserr := aws.Error(err); awserr != nil { - if awserr.Code == "NoSuchKey" { + if awserr := awserr.Error(err); awserr != nil { + if awserr.Code() == "NoSuchKey" { return nil, nil } else { return nil, err