Merge pull request #8983 from 987poiuytrewq/b-aws-beanstalk-option-updates

provider/aws: fix option updates to beanstalk
This commit is contained in:
Clint 2016-10-21 11:43:43 -05:00 committed by GitHub
commit 34b21083ee
2 changed files with 31 additions and 16 deletions

View File

@ -334,13 +334,15 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
// Additions and removals of options are done in a single API call, so we // 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 // can't do our normal "remove these" and then later "add these", re-adding
// any updated settings. // any updated settings.
// Because of this, we need to remove any settings in the "removable" // Because of this, we need to exclude any settings in the "removable"
// settings that are also found in the "add" settings, otherwise they // settings that are also found in the "add" settings, otherwise they
// conflict. Here we loop through all the initial removables from the set // conflict. Here we loop through all the initial removables from the set
// difference, and delete from the slice any items found in both `add` and // difference, and create a new slice `remove` that contains those settings
// `rm` above // found in `rm` but not in `add`
var remove []*elasticbeanstalk.ConfigurationOptionSetting
if len(add) > 0 { if len(add) > 0 {
for i, r := range rm { for _, r := range rm {
var update = false
for _, a := range add { for _, a := range add {
// ResourceNames are optional. Some defaults come with it, some do // ResourceNames are optional. Some defaults come with it, some do
// not. We need to guard against nil/empty in state as well as // not. We need to guard against nil/empty in state as well as
@ -354,14 +356,21 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
} }
} }
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName { if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
log.Printf("[DEBUG] Removing Beanstalk setting: (%s::%s)", *a.Namespace, *a.OptionName) log.Printf("[DEBUG] Updating Beanstalk setting (%s::%s) \"%s\" => \"%s\"", *a.Namespace, *a.OptionName, *r.Value, *a.Value)
rm = append(rm[:i], rm[i+1:]...) update = true
break
} }
} }
// Only remove options that are not updates
if !update {
remove = append(remove, r)
}
} }
} else {
remove = rm
} }
for _, elem := range rm { for _, elem := range remove {
updateOpts.OptionsToRemove = append(updateOpts.OptionsToRemove, &elasticbeanstalk.OptionSpecification{ updateOpts.OptionsToRemove = append(updateOpts.OptionsToRemove, &elasticbeanstalk.OptionSpecification{
Namespace: elem.Namespace, Namespace: elem.Namespace,
OptionName: elem.OptionName, OptionName: elem.OptionName,

View File

@ -235,14 +235,14 @@ func TestAccAWSBeanstalkEnv_basic_settings_update(t *testing.T) {
Config: testAccBeanstalkEnvConfig_settings(rInt), Config: testAccBeanstalkEnvConfig_settings(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}), testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccBeanstalkEnvConfig_settings_update(rInt), Config: testAccBeanstalkEnvConfig_settings_update(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}), testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -280,7 +280,7 @@ func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription,
cs := resp.ConfigurationSettings[0] cs := resp.ConfigurationSettings[0]
var foundEnvs []string var foundEnvs []string
testStrings := []string{"TF_LOG", "TF_SOME_VAR"} testStrings := []string{"ENV_STATIC", "ENV_UPDATE"}
for _, os := range cs.OptionSettings { for _, os := range cs.OptionSettings {
for _, k := range testStrings { for _, k := range testStrings {
if *os.OptionName == k { if *os.OptionName == k {
@ -504,13 +504,19 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
setting { setting {
namespace = "aws:elasticbeanstalk:application:environment" namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_LOG" name = "ENV_STATIC"
value = "true" value = "true"
} }
setting { setting {
namespace = "aws:elasticbeanstalk:application:environment" namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_VAR" name = "ENV_UPDATE"
value = "true"
}
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "ENV_REMOVE"
value = "true" value = "true"
} }
@ -553,19 +559,19 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
setting { setting {
namespace = "aws:elasticbeanstalk:application:environment" namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_LOG" name = "ENV_STATIC"
value = "true" value = "true"
} }
setting { setting {
namespace = "aws:elasticbeanstalk:application:environment" namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_VAR" name = "ENV_UPDATE"
value = "false" value = "false"
} }
setting { setting {
namespace = "aws:elasticbeanstalk:application:environment" namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_NEW_VAR" name = "ENV_ADD"
value = "true" value = "true"
} }