diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 5ff3b3b28..63794fd2e 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -6,6 +6,7 @@ import ( "log" "regexp" "strings" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -256,8 +257,23 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error { } log.Printf("[DEBUG] ELB create configuration: %#v", elbOpts) - if _, err := elbconn.CreateLoadBalancer(elbOpts); err != nil { - return fmt.Errorf("Error creating ELB: %s", err) + err = resource.Retry(1*time.Minute, func() error { + _, err := elbconn.CreateLoadBalancer(elbOpts) + + if err != nil { + if awsErr, ok := err.(awserr.Error); ok { + // Check for IAM SSL Cert error, eventual consistancy issue + if awsErr.Code() == "CertificateNotFound" { + return fmt.Errorf("[WARN] Error creating ELB Listener with SSL Cert, retrying: %s", err) + } + } + return resource.RetryError{Err: err} + } + return nil + }) + + if err != nil { + return err } // Assign the elb's unique identifier for use later diff --git a/builtin/providers/aws/resource_aws_elb_test.go b/builtin/providers/aws/resource_aws_elb_test.go index 6dad03e56..6ccc5cd66 100644 --- a/builtin/providers/aws/resource_aws_elb_test.go +++ b/builtin/providers/aws/resource_aws_elb_test.go @@ -179,6 +179,33 @@ func TestAccAWSELB_tags(t *testing.T) { }) } +func TestAccAWSELB_iam_server_cert(t *testing.T) { + var conf elb.LoadBalancerDescription + // var td elb.TagDescription + testCheck := func(*terraform.State) error { + if len(conf.ListenerDescriptions) != 1 { + return fmt.Errorf( + "TestAccAWSELB_iam_server_cert expected 1 listener, got %d", + len(conf.ListenerDescriptions)) + } + return nil + } + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSELBDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccELBIAMServerCertConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSELBExists("aws_elb.bar", &conf), + testCheck, + ), + }, + }, + }) +} + func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription) resource.TestCheckFunc { return func(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elbconn @@ -1001,3 +1028,97 @@ resource "aws_security_group" "bar" { } } ` + +// This IAM Server config is lifted from +// builtin/providers/aws/resource_aws_iam_server_certificate_test.go +var testAccELBIAMServerCertConfig = ` +resource "aws_iam_server_certificate" "test_cert" { + name = "terraform-test-cert" + certificate_body = <