provider/aws: Add poll_interval to configure polling for ElasticBeanstalk

This commit is contained in:
clint shryock 2016-07-08 12:22:38 -05:00
parent d2c9cc338e
commit 533e7aca34
2 changed files with 54 additions and 19 deletions

View File

@ -134,6 +134,24 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource {
return return
}, },
}, },
"poll_interval": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "10s",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
duration, err := time.ParseDuration(value)
if err != nil {
errors = append(errors, fmt.Errorf(
"%q cannot be parsed as a duration: %s", k, err))
}
if duration < 10*time.Second || duration > 60*time.Second {
errors = append(errors, fmt.Errorf(
"%q must be between 10s and 60s", k))
}
return
},
},
"autoscaling_groups": &schema.Schema{ "autoscaling_groups": &schema.Schema{
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@ -182,10 +200,6 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i
settings := d.Get("setting").(*schema.Set) settings := d.Get("setting").(*schema.Set)
solutionStack := d.Get("solution_stack_name").(string) solutionStack := d.Get("solution_stack_name").(string)
templateName := d.Get("template_name").(string) templateName := d.Get("template_name").(string)
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
// TODO set tags // TODO set tags
// Note: at time of writing, you cannot view or edit Tags after creation // Note: at time of writing, you cannot view or edit Tags after creation
@ -243,13 +257,22 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i
// Assign the application name as the resource ID // Assign the application name as the resource ID
d.SetId(*resp.EnvironmentId) d.SetId(*resp.EnvironmentId)
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
pollInterval, err := time.ParseDuration(d.Get("poll_interval").(string))
if err != nil {
return err
}
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"Launching", "Updating"}, Pending: []string{"Launching", "Updating"},
Target: []string{"Ready"}, Target: []string{"Ready"},
Refresh: environmentStateRefreshFunc(conn, d.Id()), Refresh: environmentStateRefreshFunc(conn, d.Id()),
Timeout: waitForReadyTimeOut, Timeout: waitForReadyTimeOut,
Delay: 10 * time.Second, Delay: 10 * time.Second,
MinTimeout: 20 * time.Second, MinTimeout: pollInterval,
} }
_, err = stateConf.WaitForState() _, err = stateConf.WaitForState()
@ -271,10 +294,6 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
conn := meta.(*AWSClient).elasticbeanstalkconn conn := meta.(*AWSClient).elasticbeanstalkconn
envId := d.Id() envId := d.Id()
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
updateOpts := elasticbeanstalk.UpdateEnvironmentInput{ updateOpts := elasticbeanstalk.UpdateEnvironmentInput{
EnvironmentId: aws.String(envId), EnvironmentId: aws.String(envId),
@ -310,7 +329,16 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
// Get the current time to filter describeBeanstalkEvents messages // Get the current time to filter describeBeanstalkEvents messages
t := time.Now() t := time.Now()
log.Printf("[DEBUG] Elastic Beanstalk Environment update opts: %s", updateOpts) log.Printf("[DEBUG] Elastic Beanstalk Environment update opts: %s", updateOpts)
_, err = conn.UpdateEnvironment(&updateOpts) _, err := conn.UpdateEnvironment(&updateOpts)
if err != nil {
return err
}
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
pollInterval, err := time.ParseDuration(d.Get("poll_interval").(string))
if err != nil { if err != nil {
return err return err
} }
@ -321,7 +349,7 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
Refresh: environmentStateRefreshFunc(conn, d.Id()), Refresh: environmentStateRefreshFunc(conn, d.Id()),
Timeout: waitForReadyTimeOut, Timeout: waitForReadyTimeOut,
Delay: 10 * time.Second, Delay: 10 * time.Second,
MinTimeout: 20 * time.Second, MinTimeout: pollInterval,
} }
_, err = stateConf.WaitForState() _, err = stateConf.WaitForState()
@ -542,11 +570,6 @@ func resourceAwsElasticBeanstalkEnvironmentSettingsRead(d *schema.ResourceData,
func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticbeanstalkconn conn := meta.(*AWSClient).elasticbeanstalkconn
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
opts := elasticbeanstalk.TerminateEnvironmentInput{ opts := elasticbeanstalk.TerminateEnvironmentInput{
EnvironmentId: aws.String(d.Id()), EnvironmentId: aws.String(d.Id()),
TerminateResources: aws.Bool(true), TerminateResources: aws.Bool(true),
@ -555,19 +578,28 @@ func resourceAwsElasticBeanstalkEnvironmentDelete(d *schema.ResourceData, meta i
// Get the current time to filter describeBeanstalkEvents messages // Get the current time to filter describeBeanstalkEvents messages
t := time.Now() t := time.Now()
log.Printf("[DEBUG] Elastic Beanstalk Environment terminate opts: %s", opts) log.Printf("[DEBUG] Elastic Beanstalk Environment terminate opts: %s", opts)
_, err = conn.TerminateEnvironment(&opts) _, err := conn.TerminateEnvironment(&opts)
if err != nil { if err != nil {
return err return err
} }
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}
pollInterval, err := time.ParseDuration(d.Get("poll_interval").(string))
if err != nil {
return err
}
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"Terminating"}, Pending: []string{"Terminating"},
Target: []string{"Terminated"}, Target: []string{"Terminated"},
Refresh: environmentStateRefreshFunc(conn, d.Id()), Refresh: environmentStateRefreshFunc(conn, d.Id()),
Timeout: waitForReadyTimeOut, Timeout: waitForReadyTimeOut,
Delay: 10 * time.Second, Delay: 10 * time.Second,
MinTimeout: 20 * time.Second, MinTimeout: pollInterval,
} }
_, err = stateConf.WaitForState() _, err = stateConf.WaitForState()

View File

@ -51,10 +51,13 @@ The following arguments are supported:
off of. Example stacks can be found in the [Amazon API documentation][1] off of. Example stacks can be found in the [Amazon API documentation][1]
* `template_name` (Optional) The name of the Elastic Beanstalk Configuration * `template_name` (Optional) The name of the Elastic Beanstalk Configuration
template to use in deployment template to use in deployment
* `wait_for_ready_timeout` - (Default: "10m") The maximum * `wait_for_ready_timeout` - (Default: `10m`) The maximum
[duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should
wait for an Elastic Beanstalk Environment to be in a ready state before timing wait for an Elastic Beanstalk Environment to be in a ready state before timing
out. out.
* `poll_interval`  (Default: `10s`) The time between polling the AWS API to
check if changes have been applied. Use this to adjust the rate of API calls
for any `create` or `update` action. Minimum `10s`, maximum `60s`
* `tags`  (Optional) A set of tags to apply to the Environment. **Note:** at * `tags`  (Optional) A set of tags to apply to the Environment. **Note:** at
this time the Elastic Beanstalk API does not provide a programatic way of this time the Elastic Beanstalk API does not provide a programatic way of
changing these tags after initial application changing these tags after initial application