From 9a2eeb824a36f4f630b84130c0d333b1efaa4de4 Mon Sep 17 00:00:00 2001 From: brent-au Date: Fri, 15 Jan 2021 02:17:02 +1100 Subject: [PATCH] Adds timeouts to Global Accelerator resources --- ...ource_aws_globalaccelerator_accelerator.go | 25 +++++++++++++------ ..._aws_globalaccelerator_accelerator_test.go | 3 ++- ...ce_aws_globalaccelerator_endpoint_group.go | 13 +++++++--- ...resource_aws_globalaccelerator_listener.go | 12 ++++++--- .../r/globalaccelerator_accelerator.markdown | 8 ++++++ ...alaccelerator_endpoint_group.html.markdown | 7 ++++++ .../r/globalaccelerator_listener.markdown | 7 ++++++ 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/aws/resource_aws_globalaccelerator_accelerator.go b/aws/resource_aws_globalaccelerator_accelerator.go index a1fefbd9d5a..8ce9f01801f 100644 --- a/aws/resource_aws_globalaccelerator_accelerator.go +++ b/aws/resource_aws_globalaccelerator_accelerator.go @@ -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, @@ -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 } @@ -279,7 +284,7 @@ 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 } @@ -287,7 +292,7 @@ func resourceAwsGlobalAcceleratorAcceleratorUpdate(d *schema.ResourceData, meta 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 } @@ -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) @@ -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)), @@ -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 } @@ -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 } diff --git a/aws/resource_aws_globalaccelerator_accelerator_test.go b/aws/resource_aws_globalaccelerator_accelerator_test.go index 096669879cb..9007ddcbf85 100644 --- a/aws/resource_aws_globalaccelerator_accelerator_test.go +++ b/aws/resource_aws_globalaccelerator_accelerator_test.go @@ -5,6 +5,7 @@ import ( "log" "regexp" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/globalaccelerator" @@ -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) diff --git a/aws/resource_aws_globalaccelerator_endpoint_group.go b/aws/resource_aws_globalaccelerator_endpoint_group.go index fc93313263b..dc74e2cf745 100644 --- a/aws/resource_aws_globalaccelerator_endpoint_group.go +++ b/aws/resource_aws_globalaccelerator_endpoint_group.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "strings" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/globalaccelerator" @@ -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, @@ -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 @@ -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 @@ -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 diff --git a/aws/resource_aws_globalaccelerator_listener.go b/aws/resource_aws_globalaccelerator_listener.go index 54d89e761df..3957e7d1b99 100644 --- a/aws/resource_aws_globalaccelerator_listener.go +++ b/aws/resource_aws_globalaccelerator_listener.go @@ -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, @@ -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()) @@ -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 } @@ -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 } diff --git a/website/docs/r/globalaccelerator_accelerator.markdown b/website/docs/r/globalaccelerator_accelerator.markdown index f58e2fbeca5..5249b087f96 100644 --- a/website/docs/r/globalaccelerator_accelerator.markdown +++ b/website/docs/r/globalaccelerator_accelerator.markdown @@ -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. diff --git a/website/docs/r/globalaccelerator_endpoint_group.html.markdown b/website/docs/r/globalaccelerator_endpoint_group.html.markdown index 629d59434af..d4bbc011aa8 100644 --- a/website/docs/r/globalaccelerator_endpoint_group.html.markdown +++ b/website/docs/r/globalaccelerator_endpoint_group.html.markdown @@ -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. diff --git a/website/docs/r/globalaccelerator_listener.markdown b/website/docs/r/globalaccelerator_listener.markdown index 259001aa4e0..24b3580c986 100644 --- a/website/docs/r/globalaccelerator_listener.markdown +++ b/website/docs/r/globalaccelerator_listener.markdown @@ -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.