Skip to content

Commit 0e908be

Browse files
committed
provider/aws: Fix issue updating ElasticBeanstalk Environment Settings
Fixes the logic that updated settings for Elastic Beanstalk Environments. Because the update is done in the same API call, we need to split removals / additions. Fixes #6890
1 parent 0024358 commit 0e908be

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go

+33-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource {
9797
"setting": &schema.Schema{
9898
Type: schema.TypeSet,
9999
Optional: true,
100-
Computed: true,
101100
Elem: resourceAwsElasticBeanstalkOptionSetting(),
102101
Set: optionSettingValueHash,
103102
},
@@ -329,7 +328,39 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
329328
os := o.(*schema.Set)
330329
ns := n.(*schema.Set)
331330

332-
updateOpts.OptionSettings = extractOptionSettings(ns.Difference(os))
331+
rm := extractOptionSettings(os.Difference(ns))
332+
add := extractOptionSettings(ns.Difference(os))
333+
334+
// Additions and removals of options are done in a single API call, so we
335+
// can't do our normal "remove these" and then later "add these", re-adding
336+
// any updated settings.
337+
// Because of this, we need to remove any settings in the "removable"
338+
// settings that are also found in the "add" settings, otherwise they
339+
// conflict. Here we loop through all the initial removables from the set
340+
// difference, and we build up a slice of settings not found in the "add"
341+
// set
342+
var remove []*elasticbeanstalk.ConfigurationOptionSetting
343+
if len(add) > 0 {
344+
for _, r := range rm {
345+
for _, a := range add {
346+
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
347+
continue
348+
}
349+
remove = append(remove, r)
350+
}
351+
}
352+
} else {
353+
remove = rm
354+
}
355+
356+
for _, elem := range remove {
357+
updateOpts.OptionsToRemove = append(updateOpts.OptionsToRemove, &elasticbeanstalk.OptionSpecification{
358+
Namespace: elem.Namespace,
359+
OptionName: elem.OptionName,
360+
})
361+
}
362+
363+
updateOpts.OptionSettings = add
333364
}
334365

335366
if d.HasChange("template_name") {

0 commit comments

Comments
 (0)