Skip to content

Commit

Permalink
provider/aws: elastic beanstalk invalid setting crash (#7222)
Browse files Browse the repository at this point in the history
* Only check the `cnamePrefix` if the CNAME is not nil

* Get Elastic Beanstalk error messages
  • Loading branch information
dharrisio authored and catsby committed Jun 20, 2016
1 parent ecc455e commit c7eb8a2
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -370,7 +384,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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit c7eb8a2

Please sign in to comment.