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

provider/aws: elastic beanstalk invalid setting crash #7222

Merged
Merged
Changes from all 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
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 {
Copy link
Member

Choose a reason for hiding this comment

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

A better name might be describeBeanstalkErrors since this only checks for ERRORs.

I'd also prefer a []string of the errors, (or even a []*elasticbeanstalk.EventDescription rather than concatenating them into an error value. A function returning an error generally indicated the call failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbardin Thanks for the feedback here, sorry it took a bit of time for me to get around to this.

  1. I agree with changing the name to describeBeanstalkErrors. Originally, I was contemplating having a parameter to set the level of events returned, but I think error is all we really need.
  2. I tried two approaches here, but ran into issues with both. Can you elaborate on how to do this? I tried both returning a slice of errors and a slice of strings. I pushed the slice of errors example to branch on my fork: dharrisio@950de0f
    What I ran into were type errors about returning []error as type error. There was a similar issue with using a slice of strings: []string as type string in argument to fmt.Errorf.

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
}