Skip to content

Commit

Permalink
Add logs for iam server certificate delete conflict (#2533)
Browse files Browse the repository at this point in the history
* Query elb API for load balancer arn causing delete conflict

- For IAM server certificate.

* Use regex for lb name.

* Edits for #2533
  • Loading branch information
Genevieve L'Esperance authored and radeksimko committed Dec 10, 2017
1 parent 01e2af9 commit f901034
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions aws/resource_aws_iam_server_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"encoding/hex"
"fmt"
"log"
"regexp"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -180,6 +182,7 @@ func resourceAwsIAMServerCertificateDelete(d *schema.ResourceData, meta interfac
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "DeleteConflict" && strings.Contains(awsErr.Message(), "currently in use by arn") {
currentlyInUseBy(awsErr.Message(), meta.(*AWSClient).elbconn)
log.Printf("[WARN] Conflict deleting server certificate: %s, retrying", awsErr.Message())
return resource.RetryableError(err)
}
Expand Down Expand Up @@ -209,6 +212,22 @@ func resourceAwsIAMServerCertificateImport(
return []*schema.ResourceData{d}, nil
}

func currentlyInUseBy(awsErr string, conn *elb.ELB) {
r := regexp.MustCompile(`currently in use by ([a-z0-9:-]+)\/([a-z0-9-]+)\.`)
matches := r.FindStringSubmatch(awsErr)
if len(matches) > 0 {
lbName := matches[2]
describeElbOpts := &elb.DescribeLoadBalancersInput{
LoadBalancerNames: []*string{aws.String(lbName)},
}
if _, err := conn.DescribeLoadBalancers(describeElbOpts); err != nil {
if isAWSErr(err, "LoadBalancerNotFound", "") {
log.Printf("[WARN] Load Balancer (%s) causing delete conflict not found", lbName)
}
}
}
}

func normalizeCert(cert interface{}) string {
if cert == nil || cert == (*string)(nil) {
return ""
Expand Down

0 comments on commit f901034

Please sign in to comment.