diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 419dc74f6..f6b2e95ad 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 2b988097d..bdd5a8a5a 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