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: Fix issue updating ElasticBeanstalk Configuraiton Templates #6307

Merged
merged 1 commit into from
Apr 22, 2016
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 @@ -3,10 +3,12 @@ package aws
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
)

Expand Down Expand Up @@ -101,17 +103,16 @@ func resourceAwsElasticBeanstalkConfigurationTemplateRead(d *schema.ResourceData
})

if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "InvalidParameterValue" && strings.Contains(awsErr.Message(), "No Configuration Template named") {
log.Printf("[WARN] No Configuration Template named (%s) found", d.Id())
d.SetId("")
return nil
}
}
return err
}

// if len(resp.ConfigurationSettings) > 1 {

// settings := make(map[string]map[string]string)
// for _, setting := range resp.ConfigurationSettings {
// k := fmt.Sprintf("%s.%s", setting.)
// }
// }

if len(resp.ConfigurationSettings) != 1 {
log.Printf("[DEBUG] Elastic Beanstalk unexpected describe configuration template response: %+v", resp)
return fmt.Errorf("Error reading application properties: found %d applications, expected 1", len(resp.ConfigurationSettings))
Expand Down Expand Up @@ -171,11 +172,29 @@ func resourceAwsElasticBeanstalkConfigurationTemplateOptionSettingsUpdate(conn *
}

os := o.(*schema.Set)
ns := o.(*schema.Set)
ns := n.(*schema.Set)

remove := extractOptionSettings(os.Difference(ns))
rm := extractOptionSettings(os.Difference(ns))
add := extractOptionSettings(ns.Difference(os))

// Additions and removals of options are done in a single API call, so we
// can't do our normal "remove these" and then later "add these", re-adding
// any updated settings.
// Because of this, we need to remove any settings in the "removable"
// settings that are also found in the "add" settings, otherwise they
// conflict. Here we loop through all the initial removables from the set
// difference, and we build up a slice of settings not found in the "add"
// set
var remove []*elasticbeanstalk.ConfigurationOptionSetting
for _, r := range rm {
for _, a := range add {
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
continue
}
remove = append(remove, r)
}
}

req := &elasticbeanstalk.UpdateConfigurationTemplateInput{
ApplicationName: aws.String(d.Get("application").(string)),
TemplateName: aws.String(d.Get("name").(string)),
Expand All @@ -189,6 +208,7 @@ func resourceAwsElasticBeanstalkConfigurationTemplateOptionSettingsUpdate(conn *
})
}

log.Printf("[DEBUG] Update Configuration Template request: %s", req)
if _, err := conn.UpdateConfigurationTemplate(req); err != nil {
return err
}
Expand Down