Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_globalaccelerator_*: Timeouts for Global Accelerator resources #17112

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions aws/resource_aws_globalaccelerator_accelerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func resourceAwsGlobalAcceleratorAccelerator() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -128,13 +133,13 @@ func resourceAwsGlobalAcceleratorAcceleratorCreate(d *schema.ResourceData, meta

d.SetId(aws.StringValue(resp.Accelerator.AcceleratorArn))

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id())
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id(), d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}

if v := d.Get("attributes").([]interface{}); len(v) > 0 {
err = resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn, d.Id(), v[0].(map[string]interface{}))
err = resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn, d.Id(), d.Timeout(schema.TimeoutUpdate), v[0].(map[string]interface{}))
if err != nil {
return err
}
Expand Down Expand Up @@ -279,15 +284,15 @@ func resourceAwsGlobalAcceleratorAcceleratorUpdate(d *schema.ResourceData, meta
return fmt.Errorf("Error updating Global Accelerator accelerator: %s", err)
}

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id())
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id(), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
}

if d.HasChange("attributes") {
if v := d.Get("attributes").([]interface{}); len(v) > 0 {
err := resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn, d.Id(), v[0].(map[string]interface{}))
err := resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn, d.Id(), d.Timeout(schema.TimeoutUpdate), v[0].(map[string]interface{}))
if err != nil {
return err
}
Expand All @@ -305,12 +310,12 @@ func resourceAwsGlobalAcceleratorAcceleratorUpdate(d *schema.ResourceData, meta
return resourceAwsGlobalAcceleratorAcceleratorRead(d, meta)
}

func resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn *globalaccelerator.GlobalAccelerator, acceleratorArn string) error {
func resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn *globalaccelerator.GlobalAccelerator, acceleratorArn string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: resourceAwsGlobalAcceleratorAcceleratorStateRefreshFunc(conn, acceleratorArn),
Timeout: 10 * time.Minute,
Timeout: timeout,
}

log.Printf("[DEBUG] Waiting for Global Accelerator accelerator (%s) availability", acceleratorArn)
Expand All @@ -322,7 +327,7 @@ func resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn *globalacc
return nil
}

func resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn *globalaccelerator.GlobalAccelerator, acceleratorArn string, attributes map[string]interface{}) error {
func resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn *globalaccelerator.GlobalAccelerator, acceleratorArn string, timeout time.Duration, attributes map[string]interface{}) error {
opts := &globalaccelerator.UpdateAcceleratorAttributesInput{
AcceleratorArn: aws.String(acceleratorArn),
FlowLogsEnabled: aws.Bool(attributes["flow_logs_enabled"].(bool)),
Expand All @@ -342,6 +347,10 @@ func resourceAwsGlobalAcceleratorAcceleratorUpdateAttributes(conn *globalacceler
if err != nil {
return fmt.Errorf("Error updating Global Accelerator accelerator attributes: %s", err)
}
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn, timeout)
if err != nil {
return err
}

return nil
}
Expand All @@ -362,7 +371,7 @@ func resourceAwsGlobalAcceleratorAcceleratorDelete(d *schema.ResourceData, meta
return fmt.Errorf("Error disabling Global Accelerator accelerator: %s", err)
}

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id())
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Id(), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion aws/resource_aws_globalaccelerator_accelerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"regexp"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/globalaccelerator"
Expand Down Expand Up @@ -71,7 +72,7 @@ func testSweepGlobalAcceleratorAccelerators(region string) error {

// Global Accelerator accelerators need to be in `DEPLOYED` state before they can be deleted.
// Removing listeners or disabling can both set the state to `IN_PROGRESS`.
if err := resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, arn); err != nil {
if err := resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, arn, 60*time.Minute); err != nil {
sweeperErr := fmt.Errorf("error waiting for Global Accelerator Accelerator (%s): %s", arn, err)
log.Printf("[ERROR] %s", sweeperErr)
sweeperErrs = multierror.Append(sweeperErrs, sweeperErr)
Expand Down
13 changes: 10 additions & 3 deletions aws/resource_aws_globalaccelerator_endpoint_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/globalaccelerator"
Expand All @@ -24,6 +25,12 @@ func resourceAwsGlobalAcceleratorEndpointGroup() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -199,7 +206,7 @@ func resourceAwsGlobalAcceleratorEndpointGroupCreate(d *schema.ResourceData, met
return err
}

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn)
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn, d.Timeout(schema.TimeoutCreate))

if err != nil {
return err
Expand Down Expand Up @@ -311,7 +318,7 @@ func resourceAwsGlobalAcceleratorEndpointGroupUpdate(d *schema.ResourceData, met
return err
}

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn)
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
Expand Down Expand Up @@ -343,7 +350,7 @@ func resourceAwsGlobalAcceleratorEndpointGroupDelete(d *schema.ResourceData, met
return err
}

err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn)
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, acceleratorArn, d.Timeout(schema.TimeoutDelete))

if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions aws/resource_aws_globalaccelerator_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func resourceAwsGlobalAcceleratorListener() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*schema.Schema{
"accelerator_arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -96,7 +102,7 @@ func resourceAwsGlobalAcceleratorListenerCreate(d *schema.ResourceData, meta int
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: resourceAwsGlobalAcceleratorAcceleratorStateRefreshFunc(conn, d.Get("accelerator_arn").(string)),
Timeout: 5 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
}

log.Printf("[DEBUG] Waiting for Global Accelerator listener (%s) availability", d.Id())
Expand Down Expand Up @@ -211,7 +217,7 @@ func resourceAwsGlobalAcceleratorListenerUpdate(d *schema.ResourceData, meta int
}

// Creating a listener triggers the accelerator to change status to InPending
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Get("accelerator_arn").(string))
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Get("accelerator_arn").(string), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand All @@ -236,7 +242,7 @@ func resourceAwsGlobalAcceleratorListenerDelete(d *schema.ResourceData, meta int

// Deleting a listener triggers the accelerator to change status to InPending
// }
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Get("accelerator_arn").(string))
err = resourceAwsGlobalAcceleratorAcceleratorWaitForDeployedState(conn, d.Get("accelerator_arn").(string), d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/globalaccelerator_accelerator.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ In addition to all arguments above, the following attributes are exported:

[1]: https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html

## Timeouts

`aws_globalaccelerator_accelerator` provides the following
[Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

* `create` - (Default `30 minutes`) How long to wait for the Global Accelerator Accelerator to be created.
* `update` - (Default `30 minutes`) How long to wait for the Global Accelerator Accelerator to be updated.

## Import

Global Accelerator accelerators can be imported using the `id`, e.g.
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/globalaccelerator_endpoint_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ In addition to all arguments above, the following attributes are exported:
* `id` - The Amazon Resource Name (ARN) of the endpoint group.
* `arn` - The Amazon Resource Name (ARN) of the endpoint group.

`aws_globalaccelerator_endpoint_group` provides the following
[Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

* `create` - (Default `30 minutes`) How long to wait for the Global Accelerator Endpoint Group to be created.
* `update` - (Default `30 minutes`) How long to wait for the Global Accelerator Endpoint Group to be updated.
* `delete` - (Default `30 minutes`) How long to wait for the Global Accelerator Endpoint Group to be deleted.

## Import

Global Accelerator endpoint groups can be imported using the `id`, e.g.
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/globalaccelerator_listener.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The Amazon Resource Name (ARN) of the listener.

`aws_globalaccelerator_listener` provides the following
[Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

* `create` - (Default `30 minutes`) How long to wait for the Global Accelerator Listener to be created.
* `update` - (Default `30 minutes`) How long to wait for the Global Accelerator Listener to be updated.
* `delete` - (Default `30 minutes`) How long to wait for the Global Accelerator Listener to be deleted.

## Import

Global Accelerator listeners can be imported using the `id`, e.g.
Expand Down