Merge pull request #6307 from hashicorp/b-aws-beanstalk-options-set-fix

provider/aws: Fix issue updating ElasticBeanstalk Configuraiton Templates
This commit is contained in:
Clint 2016-04-22 12:07:06 -05:00
commit 8f90078cd5
1 changed files with 30 additions and 10 deletions

View File

@ -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"
)
@ -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))
@ -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)),
@ -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
}