From 9df2bf68cb06ce48aecc2757dd868802d83a45ed Mon Sep 17 00:00:00 2001 From: TANABE Ken-ichi Date: Thu, 30 Apr 2015 01:31:23 +0900 Subject: [PATCH] providers/aws: use isLoadBalancerNotFound --- builtin/providers/aws/resource_aws_elb.go | 9 +++++++-- .../providers/aws/resource_aws_proxy_protocol_policy.go | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 419dc74f6a..f6b2e95ad9 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -243,7 +243,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts) if err != nil { - if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" { + if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil @@ -260,7 +260,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error { } describeAttrsResp, err := elbconn.DescribeLoadBalancerAttributes(describeAttrsOpts) if err != nil { - if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" { + if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil @@ -502,3 +502,8 @@ func resourceAwsElbListenerHash(v interface{}) int { return hashcode.String(buf.String()) } + +func isLoadBalancerNotFound(err error) bool { + elberr, ok := err.(aws.APIError) + return ok && elberr.Code == "LoadBalancerNotFound" +} diff --git a/builtin/providers/aws/resource_aws_proxy_protocol_policy.go b/builtin/providers/aws/resource_aws_proxy_protocol_policy.go index 2b988097d3..bdd5a8a5a4 100644 --- a/builtin/providers/aws/resource_aws_proxy_protocol_policy.go +++ b/builtin/providers/aws/resource_aws_proxy_protocol_policy.go @@ -81,7 +81,7 @@ func resourceAwsProxyProtocolPolicyRead(d *schema.ResourceData, meta interface{} } resp, err := elbconn.DescribeLoadBalancers(req) if err != nil { - if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" { + if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil @@ -111,7 +111,7 @@ func resourceAwsProxyProtocolPolicyUpdate(d *schema.ResourceData, meta interface } resp, err := elbconn.DescribeLoadBalancers(req) if err != nil { - if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" { + if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil @@ -167,7 +167,7 @@ func resourceAwsProxyProtocolPolicyDelete(d *schema.ResourceData, meta interface } resp, err := elbconn.DescribeLoadBalancers(req) if err != nil { - if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "LoadBalancerNotFound" { + if isLoadBalancerNotFound(err) { // The ELB is gone now, so just remove it from the state d.SetId("") return nil