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

r/glue_partition_index - add timeouts #22941

Merged
merged 3 commits into from
Feb 4, 2022
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
3 changes: 3 additions & 0 deletions .changelog/22941.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_glue_partition_index: Add support for custom timeouts.
```
10 changes: 8 additions & 2 deletions internal/service/glue/partition_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package glue
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/glue"
Expand Down Expand Up @@ -68,6 +69,11 @@ func ResourcePartitionIndex() *schema.Resource {
},
},
},

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

Expand All @@ -92,7 +98,7 @@ func resourcePartitionIndexCreate(d *schema.ResourceData, meta interface{}) erro

d.SetId(createPartitionIndexID(catalogID, dbName, tableName, aws.StringValue(input.PartitionIndex.IndexName)))

if _, err := waitGluePartitionIndexCreated(conn, d.Id()); err != nil {
if _, err := waitGluePartitionIndexCreated(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("error while waiting for Glue Partition Index (%s) to become available: %w", d.Id(), err)
}

Expand Down Expand Up @@ -152,7 +158,7 @@ func resourcePartitionIndexDelete(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error deleting Glue Partition Index: %w", err)
}

if _, err := waitGluePartitionIndexDeleted(conn, d.Id()); err != nil {
if _, err := waitGluePartitionIndexDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return fmt.Errorf("error while waiting for Glue Partition Index (%s) to be deleted: %w", d.Id(), err)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/service/glue/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ func waitGlueDevEndpointDeleted(conn *glue.Glue, name string) (*glue.DevEndpoint
return nil, err
}

func waitGluePartitionIndexCreated(conn *glue.Glue, id string) (*glue.PartitionIndexDescriptor, error) {
func waitGluePartitionIndexCreated(conn *glue.Glue, id string, timeout time.Duration) (*glue.PartitionIndexDescriptor, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{glue.PartitionIndexStatusCreating},
Target: []string{glue.PartitionIndexStatusActive},
Refresh: statusGluePartitionIndex(conn, id),
Timeout: 2 * time.Minute,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()
Expand All @@ -213,12 +213,12 @@ func waitGluePartitionIndexCreated(conn *glue.Glue, id string) (*glue.PartitionI
return nil, err
}

func waitGluePartitionIndexDeleted(conn *glue.Glue, id string) (*glue.PartitionIndexDescriptor, error) {
func waitGluePartitionIndexDeleted(conn *glue.Glue, id string, timeout time.Duration) (*glue.PartitionIndexDescriptor, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{glue.PartitionIndexStatusDeleting},
Target: []string{},
Refresh: statusGluePartitionIndex(conn, id),
Timeout: 2 * time.Minute,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/glue_partition_index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ The following arguments are required:
* `index_name` - (Required) Name of the partition index.
* `keys` - (Required) Keys for the partition index.

### Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) for certain actions:

* `create` - (Defaults to 10 mins) Used when creating the partition index.
* `delete` - (Defaults to 10 mins) Used when deleting the partition index.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down