From 975be5d6ed7c004bc8abf419831c415d22c6f386 Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 17 Jun 2016 13:13:43 -0600 Subject: [PATCH 1/2] Only check the `cnamePrefix` if the CNAME is not nil --- .../providers/aws/resource_aws_elastic_beanstalk_environment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 1a5edd6184fa..322df65c20ae 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -370,7 +370,7 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int return err } - if tier == "WebServer" { + if tier == "WebServer" && env.CNAME != nil { beanstalkCnamePrefixRegexp := regexp.MustCompile(`(^[^.]+).\w{2}-\w{4,9}-\d.elasticbeanstalk.com$`) var cnamePrefix string cnamePrefixMatch := beanstalkCnamePrefixRegexp.FindStringSubmatch(*env.CNAME) From d5e7dbbcbee5f46dc4687bdf44f8274280bc4e1d Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 17 Jun 2016 16:28:30 -0600 Subject: [PATCH 2/2] Get Elastic Beanstalk error messages --- ...ource_aws_elastic_beanstalk_environment.go | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 322df65c20ae..bc764a3fcee6 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -225,6 +225,8 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts.TemplateName = aws.String(templateName) } + // Get the current time to filter describeBeanstalkEvents messages + t := time.Now() log.Printf("[DEBUG] Elastic Beanstalk Environment create opts: %s", createOpts) resp, err := conn.CreateEnvironment(&createOpts) if err != nil { @@ -250,6 +252,11 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i d.Id(), err) } + err = describeBeanstalkEvents(conn, d.Id(), t) + if err != nil { + return err + } + return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) } @@ -293,6 +300,8 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i updateOpts.TemplateName = aws.String(d.Get("template_name").(string)) } + // Get the current time to filter describeBeanstalkEvents messages + t := time.Now() log.Printf("[DEBUG] Elastic Beanstalk Environment update opts: %s", updateOpts) _, err = conn.UpdateEnvironment(&updateOpts) if err != nil { @@ -315,6 +324,11 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i d.Id(), err) } + err = describeBeanstalkEvents(conn, d.Id(), t) + if err != nil { + return err + } + return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) } @@ -514,6 +528,8 @@ func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta i TerminateResources: aws.Bool(true), } + // Get the current time to filter describeBeanstalkEvents messages + t := time.Now() log.Printf("[DEBUG] Elastic Beanstalk Environment terminate opts: %s", opts) _, err = conn.TerminateEnvironment(&opts) @@ -537,6 +553,11 @@ func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta i d.Id(), err) } + err = describeBeanstalkEvents(conn, d.Id(), t) + if err != nil { + return err + } + return nil } @@ -642,3 +663,26 @@ func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string { return strings.Join(legitGroups, ",") } + +func describeBeanstalkEvents(conn *elasticbeanstalk.ElasticBeanstalk, environmentId string, t time.Time) error { + beanstalkErrors, err := conn.DescribeEvents(&elasticbeanstalk.DescribeEventsInput{ + EnvironmentId: aws.String(environmentId), + Severity: aws.String("ERROR"), + StartTime: aws.Time(t), + }) + + if err != nil { + log.Printf("[Err] Unable to get Elastic Beanstalk Evironment events: %s", err) + } + + events := "" + for _, event := range beanstalkErrors.Events { + events = events + "\n" + event.EventDate.String() + ": " + *event.Message + } + + if events != "" { + return fmt.Errorf("%s", events) + } + + return nil +}