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.
This commit is contained in:
parent
ebb9b7a696
commit
23c0399500
|
@ -32,6 +32,10 @@ func resourceAwsElasticBeanstalkOptionSetting() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
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)
|
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 {
|
if optionSetting.Value != nil {
|
||||||
switch *optionSetting.OptionName {
|
switch *optionSetting.OptionName {
|
||||||
case "SecurityGroups":
|
case "SecurityGroups":
|
||||||
|
@ -600,8 +608,12 @@ func optionSettingValueHash(v interface{}) int {
|
||||||
rd := v.(map[string]interface{})
|
rd := v.(map[string]interface{})
|
||||||
namespace := rd["namespace"].(string)
|
namespace := rd["namespace"].(string)
|
||||||
optionName := rd["name"].(string)
|
optionName := rd["name"].(string)
|
||||||
|
var resourceName string
|
||||||
|
if v, ok := rd["resource"].(string); ok {
|
||||||
|
resourceName = v
|
||||||
|
}
|
||||||
value, _ := rd["value"].(string)
|
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))
|
log.Printf("[DEBUG] Elastic Beanstalk optionSettingValueHash(%#v): %s: hk=%s,hc=%d", v, optionName, hk, hashcode.String(hk))
|
||||||
return hashcode.String(hk)
|
return hashcode.String(hk)
|
||||||
}
|
}
|
||||||
|
@ -610,7 +622,11 @@ func optionSettingKeyHash(v interface{}) int {
|
||||||
rd := v.(map[string]interface{})
|
rd := v.(map[string]interface{})
|
||||||
namespace := rd["namespace"].(string)
|
namespace := rd["namespace"].(string)
|
||||||
optionName := rd["name"].(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))
|
log.Printf("[DEBUG] Elastic Beanstalk optionSettingKeyHash(%#v): %s: hk=%s,hc=%d", v, optionName, hk, hashcode.String(hk))
|
||||||
return hashcode.String(hk)
|
return hashcode.String(hk)
|
||||||
}
|
}
|
||||||
|
@ -626,11 +642,15 @@ func extractOptionSettings(s *schema.Set) []*elasticbeanstalk.ConfigurationOptio
|
||||||
|
|
||||||
if s != nil {
|
if s != nil {
|
||||||
for _, setting := range s.List() {
|
for _, setting := range s.List() {
|
||||||
settings = append(settings, &elasticbeanstalk.ConfigurationOptionSetting{
|
optionSetting := elasticbeanstalk.ConfigurationOptionSetting{
|
||||||
Namespace: aws.String(setting.(map[string]interface{})["namespace"].(string)),
|
Namespace: aws.String(setting.(map[string]interface{})["namespace"].(string)),
|
||||||
OptionName: aws.String(setting.(map[string]interface{})["name"].(string)),
|
OptionName: aws.String(setting.(map[string]interface{})["name"].(string)),
|
||||||
Value: aws.String(setting.(map[string]interface{})["value"].(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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
|
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 * * *"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -47,10 +47,10 @@ off of. Example stacks can be found in the [Amazon API documentation][1]
|
||||||
|
|
||||||
The `setting` field supports the following format:
|
The `setting` field supports the following format:
|
||||||
|
|
||||||
* `namespace` - (Optional) unique namespace identifying the option's
|
* `namespace` - unique namespace identifying the option's associated AWS resource
|
||||||
associated AWS resource
|
* `name` - name of the configuration option
|
||||||
* `name` - (Optional) name of the configuration option
|
* `value` - value for the configuration option
|
||||||
* `value` - (Optional) 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
|
## Attributes Reference
|
||||||
|
|
||||||
|
|
|
@ -67,10 +67,10 @@ for supported options and examples.
|
||||||
|
|
||||||
The `setting` and `all_settings` mappings support the following format:
|
The `setting` and `all_settings` mappings support the following format:
|
||||||
|
|
||||||
* `namespace` - (Optional) unique namespace identifying the option's
|
* `namespace` - unique namespace identifying the option's associated AWS resource
|
||||||
associated AWS resource
|
* `name` - name of the configuration option
|
||||||
* `name` - (Optional) name of the configuration option
|
* `value` - value for the configuration option
|
||||||
* `value` - (Optional) 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
|
## Attributes Reference
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue