@@ -225,6 +225,8 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i
225225 createOpts .TemplateName = aws .String (templateName )
226226 }
227227
228+ // Get the current time to filter describeBeanstalkEvents messages
229+ t := time .Now ()
228230 log .Printf ("[DEBUG] Elastic Beanstalk Environment create opts: %s" , createOpts )
229231 resp , err := conn .CreateEnvironment (& createOpts )
230232 if err != nil {
@@ -250,6 +252,11 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i
250252 d .Id (), err )
251253 }
252254
255+ err = describeBeanstalkEvents (conn , d .Id (), t )
256+ if err != nil {
257+ return err
258+ }
259+
253260 return resourceAwsElasticBeanstalkEnvironmentRead (d , meta )
254261}
255262
@@ -293,6 +300,8 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
293300 updateOpts .TemplateName = aws .String (d .Get ("template_name" ).(string ))
294301 }
295302
303+ // Get the current time to filter describeBeanstalkEvents messages
304+ t := time .Now ()
296305 log .Printf ("[DEBUG] Elastic Beanstalk Environment update opts: %s" , updateOpts )
297306 _ , err = conn .UpdateEnvironment (& updateOpts )
298307 if err != nil {
@@ -315,6 +324,11 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
315324 d .Id (), err )
316325 }
317326
327+ err = describeBeanstalkEvents (conn , d .Id (), t )
328+ if err != nil {
329+ return err
330+ }
331+
318332 return resourceAwsElasticBeanstalkEnvironmentRead (d , meta )
319333}
320334
@@ -370,7 +384,7 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
370384 return err
371385 }
372386
373- if tier == "WebServer" {
387+ if tier == "WebServer" && env . CNAME != nil {
374388 beanstalkCnamePrefixRegexp := regexp .MustCompile (`(^[^.]+).\w{2}-\w{4,9}-\d.elasticbeanstalk.com$` )
375389 var cnamePrefix string
376390 cnamePrefixMatch := beanstalkCnamePrefixRegexp .FindStringSubmatch (* env .CNAME )
@@ -514,6 +528,8 @@ func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta i
514528 TerminateResources : aws .Bool (true ),
515529 }
516530
531+ // Get the current time to filter describeBeanstalkEvents messages
532+ t := time .Now ()
517533 log .Printf ("[DEBUG] Elastic Beanstalk Environment terminate opts: %s" , opts )
518534 _ , err = conn .TerminateEnvironment (& opts )
519535
@@ -537,6 +553,11 @@ func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta i
537553 d .Id (), err )
538554 }
539555
556+ err = describeBeanstalkEvents (conn , d .Id (), t )
557+ if err != nil {
558+ return err
559+ }
560+
540561 return nil
541562}
542563
@@ -642,3 +663,26 @@ func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string {
642663
643664 return strings .Join (legitGroups , "," )
644665}
666+
667+ func describeBeanstalkEvents (conn * elasticbeanstalk.ElasticBeanstalk , environmentId string , t time.Time ) error {
668+ beanstalkErrors , err := conn .DescribeEvents (& elasticbeanstalk.DescribeEventsInput {
669+ EnvironmentId : aws .String (environmentId ),
670+ Severity : aws .String ("ERROR" ),
671+ StartTime : aws .Time (t ),
672+ })
673+
674+ if err != nil {
675+ log .Printf ("[Err] Unable to get Elastic Beanstalk Evironment events: %s" , err )
676+ }
677+
678+ events := ""
679+ for _ , event := range beanstalkErrors .Events {
680+ events = events + "\n " + event .EventDate .String () + ": " + * event .Message
681+ }
682+
683+ if events != "" {
684+ return fmt .Errorf ("%s" , events )
685+ }
686+
687+ return nil
688+ }
0 commit comments