Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logs for iam server certificate delete conflict #2533

Merged
merged 3 commits into from
Dec 10, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Do you mind changing the second argument to *elb.ELB instead of all meta?

log.Printf("[WARN] Conflict deleting server certificate: %s, retrying", awsErr.Message())
return resource.RetryableError(err)
}
Expand Down Expand Up @@ -209,6 +212,23 @@ func resourceAwsIAMServerCertificateImport(
return []*schema.ResourceData{d}, nil
}

func currentlyInUseBy(awsErr string, meta interface{}) {
r := regexp.MustCompile(`currently in use by ([a-z0-9:-]+)\/([a-z0-9-]+)\.`)
matches := r.FindStringSubmatch(awsErr)
if len(matches) > 0 {
lbName := matches[2]
conn := meta.(*AWSClient).elbconn
describeElbOpts := &elb.DescribeLoadBalancersInput{
LoadBalancerNames: []*string{aws.String(lbName)},
}
if _, err := conn.DescribeLoadBalancers(describeElbOpts); err != nil {
if elbErr, ok := err.(awserr.Error); ok && elbErr.Code() == "LoadBalancerNotFound" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: This error check here can be simplified to

if isAWSErr(err, "LoadBalancerNotFound", "") {

We unfortunately haven't changed it everywhere yet, since introducing this helper function - but that's the long-term goal.

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