Skip to content

Commit 31258e0

Browse files
committed
provider/aws: fix breakages from awserr refactor
This landed in aws-sdk-go yesterday, breaking the AWS provider in many places: aws/aws-sdk-go@3c259c9 Here, with much sedding, grepping, and manual massaging, we attempt to catch Terraform up to the new `awserr.Error` interface world.
1 parent 046e9b4 commit 31258e0

74 files changed

Lines changed: 271 additions & 188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

builtin/providers/aws/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type AWSClient struct {
3636
elbconn *elb.ELB
3737
autoscalingconn *autoscaling.AutoScaling
3838
s3conn *s3.S3
39-
sqsconn *sqs.SQS
39+
sqsconn *sqs.SQS
4040
r53conn *route53.Route53
4141
region string
4242
rdsconn *rds.RDS

builtin/providers/aws/resource_aws_app_cookie_stickiness_policy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/awslabs/aws-sdk-go/aws"
8+
"github.com/awslabs/aws-sdk-go/aws/awserr"
89
"github.com/awslabs/aws-sdk-go/service/elb"
910
"github.com/hashicorp/terraform/helper/schema"
1011
)
@@ -90,7 +91,7 @@ func resourceAwsAppCookieStickinessPolicyRead(d *schema.ResourceData, meta inter
9091

9192
getResp, err := elbconn.DescribeLoadBalancerPolicies(request)
9293
if err != nil {
93-
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "PolicyNotFound" {
94+
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "PolicyNotFound" {
9495
// The policy is gone.
9596
d.SetId("")
9697
return nil

builtin/providers/aws/resource_aws_autoscaling_group.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform/helper/schema"
1111

1212
"github.com/awslabs/aws-sdk-go/aws"
13+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1314
"github.com/awslabs/aws-sdk-go/service/autoscaling"
1415
"github.com/awslabs/aws-sdk-go/service/elb"
1516
)
@@ -292,8 +293,8 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
292293
// scaling operations within 5m.
293294
err = resource.Retry(5*time.Minute, func() error {
294295
if _, err := conn.DeleteAutoScalingGroup(&deleteopts); err != nil {
295-
if awserr, ok := err.(aws.APIError); ok {
296-
switch awserr.Code {
296+
if awserr, ok := err.(awserr.Error); ok {
297+
switch awserr.Code() {
297298
case "InvalidGroup.NotFound":
298299
// Already gone? Sure!
299300
return nil
@@ -332,8 +333,8 @@ func getAwsAutoscalingGroup(
332333
log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
333334
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
334335
if err != nil {
335-
autoscalingerr, ok := err.(aws.APIError)
336-
if ok && autoscalingerr.Code == "InvalidGroup.NotFound" {
336+
autoscalingerr, ok := err.(awserr.Error)
337+
if ok && autoscalingerr.Code() == "InvalidGroup.NotFound" {
337338
d.SetId("")
338339
return nil, nil
339340
}

builtin/providers/aws/resource_aws_autoscaling_group_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/awslabs/aws-sdk-go/aws"
10+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1011
"github.com/awslabs/aws-sdk-go/service/autoscaling"
1112
"github.com/hashicorp/terraform/helper/resource"
1213
"github.com/hashicorp/terraform/terraform"
@@ -141,11 +142,11 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
141142
}
142143

143144
// Verify the error
144-
ec2err, ok := err.(aws.APIError)
145+
ec2err, ok := err.(awserr.Error)
145146
if !ok {
146147
return err
147148
}
148-
if ec2err.Code != "InvalidGroup.NotFound" {
149+
if ec2err.Code() != "InvalidGroup.NotFound" {
149150
return err
150151
}
151152
}

builtin/providers/aws/resource_aws_customer_gateway.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/awslabs/aws-sdk-go/aws"
9+
"github.com/awslabs/aws-sdk-go/aws/awserr"
910
"github.com/awslabs/aws-sdk-go/service/ec2"
1011

1112
"github.com/hashicorp/terraform/helper/resource"
@@ -100,7 +101,7 @@ func customerGatewayRefreshFunc(conn *ec2.EC2, gatewayId string) resource.StateR
100101
Filters: []*ec2.Filter{gatewayFilter},
101102
})
102103
if err != nil {
103-
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" {
104+
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
104105
resp = nil
105106
} else {
106107
log.Printf("Error on CustomerGatewayRefresh: %s", err)
@@ -130,7 +131,7 @@ func resourceAwsCustomerGatewayRead(d *schema.ResourceData, meta interface{}) er
130131
Filters: []*ec2.Filter{gatewayFilter},
131132
})
132133
if err != nil {
133-
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" {
134+
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
134135
d.SetId("")
135136
return nil
136137
} else {
@@ -172,7 +173,7 @@ func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{})
172173
CustomerGatewayID: aws.String(d.Id()),
173174
})
174175
if err != nil {
175-
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidCustomerGatewayID.NotFound" {
176+
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
176177
d.SetId("")
177178
return nil
178179
} else {

builtin/providers/aws/resource_aws_db_instance.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/awslabs/aws-sdk-go/aws"
10+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1011
"github.com/awslabs/aws-sdk-go/service/iam"
1112
"github.com/awslabs/aws-sdk-go/service/rds"
1213

@@ -275,7 +276,8 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
275276
}
276277

277278
log.Printf("[DEBUG] DB Instance create configuration: %#v", opts)
278-
_, err := conn.CreateDBInstance(&opts)
279+
var err error
280+
_, err = conn.CreateDBInstance(&opts)
279281
if err != nil {
280282
return fmt.Errorf("Error creating DB Instance: %s", err)
281283
}
@@ -558,8 +560,8 @@ func resourceAwsDbInstanceRetrieve(
558560
resp, err := conn.DescribeDBInstances(&opts)
559561

560562
if err != nil {
561-
dbinstanceerr, ok := err.(aws.APIError)
562-
if ok && dbinstanceerr.Code == "DBInstanceNotFound" {
563+
dbinstanceerr, ok := err.(awserr.Error)
564+
if ok && dbinstanceerr.Code() == "DBInstanceNotFound" {
563565
return nil, nil
564566
}
565567
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)

builtin/providers/aws/resource_aws_db_instance_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform/terraform"
1111

1212
"github.com/awslabs/aws-sdk-go/aws"
13+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1314
"github.com/awslabs/aws-sdk-go/service/rds"
1415
)
1516

@@ -57,6 +58,7 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
5758
}
5859

5960
// Try to find the Group
61+
var err error
6062
resp, err := conn.DescribeDBInstances(
6163
&rds.DescribeDBInstancesInput{
6264
DBInstanceIdentifier: aws.String(rs.Primary.ID),
@@ -70,11 +72,11 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
7072
}
7173

7274
// Verify the error
73-
newerr, ok := err.(*aws.APIError)
75+
newerr, ok := err.(awserr.Error)
7476
if !ok {
7577
return err
7678
}
77-
if newerr.Code != "InvalidDBInstance.NotFound" {
79+
if newerr.Code() != "InvalidDBInstance.NotFound" {
7880
return err
7981
}
8082
}

builtin/providers/aws/resource_aws_db_parameter_group.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform/helper/schema"
1313

1414
"github.com/awslabs/aws-sdk-go/aws"
15+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1516
"github.com/awslabs/aws-sdk-go/service/rds"
1617
)
1718

@@ -203,12 +204,12 @@ func resourceAwsDbParameterGroupDeleteRefreshFunc(
203204
}
204205

205206
if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
206-
rdserr, ok := err.(aws.APIError)
207+
rdserr, ok := err.(awserr.Error)
207208
if !ok {
208209
return d, "error", err
209210
}
210211

211-
if rdserr.Code != "DBParameterGroupNotFoundFault" {
212+
if rdserr.Code() != "DBParameterGroupNotFoundFault" {
212213
return d, "error", err
213214
}
214215
}

builtin/providers/aws/resource_aws_db_parameter_group_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/awslabs/aws-sdk-go/aws"
8+
"github.com/awslabs/aws-sdk-go/aws/awserr"
89
"github.com/awslabs/aws-sdk-go/service/rds"
910
"github.com/hashicorp/terraform/helper/resource"
1011
"github.com/hashicorp/terraform/terraform"
@@ -127,11 +128,11 @@ func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error {
127128
}
128129

129130
// Verify the error
130-
newerr, ok := err.(aws.APIError)
131+
newerr, ok := err.(awserr.Error)
131132
if !ok {
132133
return err
133134
}
134-
if newerr.Code != "InvalidDBParameterGroup.NotFound" {
135+
if newerr.Code() != "InvalidDBParameterGroup.NotFound" {
135136
return err
136137
}
137138
}

builtin/providers/aws/resource_aws_db_security_group.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/awslabs/aws-sdk-go/aws"
10+
"github.com/awslabs/aws-sdk-go/aws/awserr"
1011
"github.com/awslabs/aws-sdk-go/service/rds"
1112
"github.com/hashicorp/terraform/helper/hashcode"
1213
"github.com/hashicorp/terraform/helper/multierror"
@@ -170,8 +171,8 @@ func resourceAwsDbSecurityGroupDelete(d *schema.ResourceData, meta interface{})
170171
_, err := conn.DeleteDBSecurityGroup(&opts)
171172

172173
if err != nil {
173-
newerr, ok := err.(aws.APIError)
174-
if ok && newerr.Code == "InvalidDBSecurityGroup.NotFound" {
174+
newerr, ok := err.(awserr.Error)
175+
if ok && newerr.Code() == "InvalidDBSecurityGroup.NotFound" {
175176
return nil
176177
}
177178
return err

0 commit comments

Comments
 (0)