provider/aws: fix option updates to beanstalk
This commit is contained in:
parent
23009ec837
commit
826ff3f0f0
|
@ -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
|
||||
// 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"
|
||||
// Because of this, we need to exclude 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 delete from the slice any items found in both `add` and
|
||||
// `rm` above
|
||||
// difference, and create a new slice `remove` that contains those settings
|
||||
// found in `rm` but not in `add`
|
||||
var remove []*elasticbeanstalk.ConfigurationOptionSetting
|
||||
if len(add) > 0 {
|
||||
for i, r := range rm {
|
||||
for _, r := range rm {
|
||||
var update = false
|
||||
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
|
||||
|
@ -354,14 +356,21 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
|
|||
}
|
||||
}
|
||||
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
|
||||
log.Printf("[DEBUG] Removing Beanstalk setting: (%s::%s)", *a.Namespace, *a.OptionName)
|
||||
rm = append(rm[:i], rm[i+1:]...)
|
||||
log.Printf("[DEBUG] Updating Beanstalk setting (%s::%s) \"%s\" => \"%s\"", *a.Namespace, *a.OptionName, *r.Value, *a.Value)
|
||||
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{
|
||||
Namespace: elem.Namespace,
|
||||
OptionName: elem.OptionName,
|
||||
|
|
|
@ -235,14 +235,14 @@ func TestAccAWSBeanstalkEnv_basic_settings_update(t *testing.T) {
|
|||
Config: testAccBeanstalkEnvConfig_settings(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
|
||||
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}),
|
||||
testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}),
|
||||
),
|
||||
},
|
||||
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"}),
|
||||
testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
|
@ -280,7 +280,7 @@ func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription,
|
|||
cs := resp.ConfigurationSettings[0]
|
||||
|
||||
var foundEnvs []string
|
||||
testStrings := []string{"TF_LOG", "TF_SOME_VAR"}
|
||||
testStrings := []string{"ENV_STATIC", "ENV_UPDATE"}
|
||||
for _, os := range cs.OptionSettings {
|
||||
for _, k := range testStrings {
|
||||
if *os.OptionName == k {
|
||||
|
@ -504,13 +504,19 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
|
|||
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "TF_LOG"
|
||||
name = "ENV_STATIC"
|
||||
value = "true"
|
||||
}
|
||||
|
||||
setting {
|
||||
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"
|
||||
}
|
||||
|
||||
|
@ -553,19 +559,19 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
|
|||
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "TF_LOG"
|
||||
name = "ENV_STATIC"
|
||||
value = "true"
|
||||
}
|
||||
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "TF_SOME_VAR"
|
||||
name = "ENV_UPDATE"
|
||||
value = "false"
|
||||
}
|
||||
|
||||
setting {
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "TF_SOME_NEW_VAR"
|
||||
name = "ENV_ADD"
|
||||
value = "true"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue