From 23c0399500f7b20a821db55261b68c9f265396d6 Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 27 Jun 2016 18:56:12 -0600 Subject: [PATCH] provider/aws: Elastic Beanstalk scheduledaction (#7376) Add support for scheduled actions in Elastic Beanstalk option settings by adding optional `resource` attribute for option setting resource. --- ...ource_aws_elastic_beanstalk_environment.go | 28 ++++++++-- ..._aws_elastic_beanstalk_environment_test.go | 51 +++++++++++++++++++ ...stalk_configuration_template.html.markdown | 8 +-- ...lastic_beanstalk_environment.html.markdown | 8 +-- 4 files changed, 83 insertions(+), 12 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index bc764a3fc..bb2f5646d 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -32,6 +32,10 @@ func resourceAwsElasticBeanstalkOptionSetting() *schema.Resource { Type: schema.TypeString, Required: true, }, + "resource": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, } } @@ -458,6 +462,10 @@ func fetchAwsElasticBeanstalkEnvironmentSettings(d *schema.ResourceData, meta in return nil, fmt.Errorf("Error reading environment settings: option setting with no name: %v", optionSetting) } + if optionSetting.ResourceName != nil { + m["resource"] = *optionSetting.ResourceName + } + if optionSetting.Value != nil { switch *optionSetting.OptionName { case "SecurityGroups": @@ -600,8 +608,12 @@ func optionSettingValueHash(v interface{}) int { rd := v.(map[string]interface{}) namespace := rd["namespace"].(string) optionName := rd["name"].(string) + var resourceName string + if v, ok := rd["resource"].(string); ok { + resourceName = v + } value, _ := rd["value"].(string) - hk := fmt.Sprintf("%s:%s=%s", namespace, optionName, sortValues(value)) + hk := fmt.Sprintf("%s:%s%s=%s", namespace, optionName, resourceName, sortValues(value)) log.Printf("[DEBUG] Elastic Beanstalk optionSettingValueHash(%#v): %s: hk=%s,hc=%d", v, optionName, hk, hashcode.String(hk)) return hashcode.String(hk) } @@ -610,7 +622,11 @@ func optionSettingKeyHash(v interface{}) int { rd := v.(map[string]interface{}) namespace := rd["namespace"].(string) optionName := rd["name"].(string) - hk := fmt.Sprintf("%s:%s", namespace, optionName) + var resourceName string + if v, ok := rd["resource"].(string); ok { + resourceName = v + } + hk := fmt.Sprintf("%s:%s%s", namespace, optionName, resourceName) log.Printf("[DEBUG] Elastic Beanstalk optionSettingKeyHash(%#v): %s: hk=%s,hc=%d", v, optionName, hk, hashcode.String(hk)) return hashcode.String(hk) } @@ -626,11 +642,15 @@ func extractOptionSettings(s *schema.Set) []*elasticbeanstalk.ConfigurationOptio if s != nil { for _, setting := range s.List() { - settings = append(settings, &elasticbeanstalk.ConfigurationOptionSetting{ + optionSetting := elasticbeanstalk.ConfigurationOptionSetting{ Namespace: aws.String(setting.(map[string]interface{})["namespace"].(string)), OptionName: aws.String(setting.(map[string]interface{})["name"].(string)), Value: aws.String(setting.(map[string]interface{})["value"].(string)), - }) + } + if v, ok := setting.(map[string]interface{})["resource"].(string); ok && v != "" { + optionSetting.ResourceName = aws.String(v) + } + settings = append(settings, &optionSetting) } } diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go index ee4a3acfd..009560a20 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -140,6 +140,24 @@ func TestAccAWSBeanstalkEnv_config(t *testing.T) { }) } +func TestAccAWSBeanstalkEnv_resource(t *testing.T) { + var app elasticbeanstalk.EnvironmentDescription + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBeanstalkEnvDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBeanstalkResourceOptionSetting, + Check: resource.ComposeTestCheckFunc( + testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), + ), + }, + }, + }) +} + func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn @@ -414,3 +432,36 @@ resource "aws_elastic_beanstalk_configuration_template" "tftest" { } } ` +const testAccBeanstalkResourceOptionSetting = ` +resource "aws_elastic_beanstalk_application" "tftest" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_environment" "tfenvtest" { + name = "tf-test-name" + application = "${aws_elastic_beanstalk_application.tftest.name}" + solution_stack_name = "64bit Amazon Linux running Python" + + setting { + namespace = "aws:autoscaling:scheduledaction" + resource = "ScheduledAction01" + name = "MinSize" + value = "2" + } + + setting { + namespace = "aws:autoscaling:scheduledaction" + resource = "ScheduledAction01" + name = "MaxSize" + value = "6" + } + + setting { + namespace = "aws:autoscaling:scheduledaction" + resource = "ScheduledAction01" + name = "Recurrence" + value = "0 8 * * *" + } +} +` diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown index 4f2fcc993..1c74cdbaa 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown @@ -47,10 +47,10 @@ off of. Example stacks can be found in the [Amazon API documentation][1] The `setting` field supports the following format: -* `namespace` - (Optional) unique namespace identifying the option's - associated AWS resource -* `name` - (Optional) name of the configuration option -* `value` - (Optional) value for the configuration option +* `namespace` - unique namespace identifying the option's associated AWS resource +* `name` - name of the configuration option +* `value` - value for the configuration option +* `resource` - (Optional) resource name for [scheduled action](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalingscheduledaction) ## Attributes Reference diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown index 2c7523870..bdd008477 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown @@ -67,10 +67,10 @@ for supported options and examples. The `setting` and `all_settings` mappings support the following format: -* `namespace` - (Optional) unique namespace identifying the option's - associated AWS resource -* `name` - (Optional) name of the configuration option -* `value` - (Optional) value for the configuration option +* `namespace` - unique namespace identifying the option's associated AWS resource +* `name` - name of the configuration option +* `value` - value for the configuration option +* `resource` - (Optional) resource name for [scheduled action](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalingscheduledaction) ## Attributes Reference