provider/aws: Fix issue updating Elastic Beanstalk Environment variables (#8848)

* provider/aws: failing test case for updating env vars

* provider/aws: Fix issue with updating Elastic Beanstalk env vars
This commit is contained in:
Clint 2016-09-15 13:30:12 -05:00 committed by GitHub
parent e6310aa461
commit adea7563e5
2 changed files with 68 additions and 9 deletions

View File

@ -337,11 +337,10 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
// 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
// difference, and delete from the slice any items found in both `add` and
// `rm` above
if len(add) > 0 {
for _, r := range rm {
for i, r := range rm {
for _, a := range add {
// ResourceNames are optional. Some defaults come with it, some do
// not. We need to guard against nil/empty in state as well as
@ -355,16 +354,14 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
}
}
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
continue
log.Printf("[DEBUG] Removing Beanstalk setting: (%s::%s)", *a.Namespace, *a.OptionName)
rm = append(rm[:i], rm[i+1:]...)
}
remove = append(remove, r)
}
}
} else {
remove = rm
}
for _, elem := range remove {
for _, elem := range rm {
updateOpts.OptionsToRemove = append(updateOpts.OptionsToRemove, &elasticbeanstalk.OptionSpecification{
Namespace: elem.Namespace,
OptionName: elem.OptionName,

View File

@ -238,6 +238,13 @@ func TestAccAWSBeanstalkEnv_basic_settings_update(t *testing.T) {
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}),
),
},
resource.TestStep{
Config: testAccBeanstalkEnvConfig_settings_update(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}),
),
},
resource.TestStep{
Config: testAccBeanstalkEnvConfig_empty_settings(rInt),
Check: resource.ComposeTestCheckFunc(
@ -530,6 +537,61 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
}`, r, r)
}
func testAccBeanstalkEnvConfig_settings_update(r int) string {
return fmt.Sprintf(`
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name-%d"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name-%d"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
wait_for_ready_timeout = "15m"
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_LOG"
value = "true"
}
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_VAR"
value = "false"
}
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_NEW_VAR"
value = "true"
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "MinSize"
value = 2
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "MaxSize"
value = 3
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "StartTime"
value = "2016-07-28T04:07:02Z"
}
}`, r, r)
}
const testAccBeanstalkWorkerEnvConfig = `
resource "aws_iam_instance_profile" "tftest" {
name = "tftest_profile"