From 6d49dfac45dbd6c0e16c81f8d4cf16da07cac856 Mon Sep 17 00:00:00 2001 From: Marco Silva Date: Mon, 29 Jan 2024 15:54:12 +0000 Subject: [PATCH 1/5] Add 'timeout' attribute to Glue Trigger create, update and delete --- internal/service/glue/trigger.go | 6 +++--- internal/service/glue/wait.go | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/service/glue/trigger.go b/internal/service/glue/trigger.go index d6aeff8a86b..674c2263694 100644 --- a/internal/service/glue/trigger.go +++ b/internal/service/glue/trigger.go @@ -286,7 +286,7 @@ func resourceTriggerCreate(ctx context.Context, d *schema.ResourceData, meta int d.SetId(name) log.Printf("[DEBUG] Waiting for Glue Trigger (%s) to create", d.Id()) - if _, err := waitTriggerCreated(ctx, conn, d.Id()); err != nil { + if _, err := waitTriggerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { if tfawserr.ErrCodeEquals(err, glue.ErrCodeEntityNotFoundException) { return diags } @@ -407,7 +407,7 @@ func resourceTriggerUpdate(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "updating Glue Trigger (%s): %s", d.Id(), err) } - if _, err := waitTriggerCreated(ctx, conn, d.Id()); err != nil { + if _, err := waitTriggerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Glue Trigger (%s) to be Update: %s", d.Id(), err) } } @@ -453,7 +453,7 @@ func resourceTriggerDelete(ctx context.Context, d *schema.ResourceData, meta int } log.Printf("[DEBUG] Waiting for Glue Trigger (%s) to delete", d.Id()) - if _, err := waitTriggerDeleted(ctx, conn, d.Id()); err != nil { + if _, err := waitTriggerDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { if tfawserr.ErrCodeEquals(err, glue.ErrCodeEntityNotFoundException) { return diags } diff --git a/internal/service/glue/wait.go b/internal/service/glue/wait.go index 82594efa2a5..7e05190064b 100644 --- a/internal/service/glue/wait.go +++ b/internal/service/glue/wait.go @@ -21,8 +21,6 @@ const ( schemaAvailableTimeout = 2 * time.Minute schemaDeleteTimeout = 2 * time.Minute schemaVersionAvailableTimeout = 2 * time.Minute - triggerCreateTimeout = 5 * time.Minute - triggerDeleteTimeout = 5 * time.Minute ) // waitMLTransformDeleted waits for an MLTransform to return Deleted @@ -116,7 +114,7 @@ func waitSchemaVersionAvailable(ctx context.Context, conn *glue.Glue, registryID } // waitTriggerCreated waits for a Trigger to return Created -func waitTriggerCreated(ctx context.Context, conn *glue.Glue, triggerName string) (*glue.GetTriggerOutput, error) { //nolint:unparam +func waitTriggerCreated(ctx context.Context, conn *glue.Glue, triggerName string, timeout time.Duration) (*glue.GetTriggerOutput, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{ glue.TriggerStateActivating, @@ -128,7 +126,7 @@ func waitTriggerCreated(ctx context.Context, conn *glue.Glue, triggerName string glue.TriggerStateCreated, }, Refresh: statusTrigger(ctx, conn, triggerName), - Timeout: triggerCreateTimeout, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -141,12 +139,12 @@ func waitTriggerCreated(ctx context.Context, conn *glue.Glue, triggerName string } // waitTriggerDeleted waits for a Trigger to return Deleted -func waitTriggerDeleted(ctx context.Context, conn *glue.Glue, triggerName string) (*glue.GetTriggerOutput, error) { +func waitTriggerDeleted(ctx context.Context, conn *glue.Glue, triggerName string, timeout time.Duration) (*glue.GetTriggerOutput, error) { stateConf := &retry.StateChangeConf{ Pending: []string{glue.TriggerStateDeleting}, Target: []string{}, Refresh: statusTrigger(ctx, conn, triggerName), - Timeout: triggerDeleteTimeout, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) From 540c0249b2a9b4efb8f4ca9e5631e5ebe81027ac Mon Sep 17 00:00:00 2001 From: Marco Silva Date: Mon, 29 Jan 2024 16:04:02 +0000 Subject: [PATCH 2/5] Add changelog --- .changelog/35542.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35542.txt diff --git a/.changelog/35542.txt b/.changelog/35542.txt new file mode 100644 index 00000000000..b6518d0a568 --- /dev/null +++ b/.changelog/35542.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_glue_trigger: Add `timeouts` configuration +``` From 8a5be64fdc79532f4626eeba914275a98d3eb71b Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 9 Feb 2024 12:11:54 -0600 Subject: [PATCH 3/5] aws_glue_trigger: fix tests --- internal/service/glue/trigger.go | 3 ++- internal/service/glue/trigger_test.go | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/service/glue/trigger.go b/internal/service/glue/trigger.go index 674c2263694..8bc69f2008b 100644 --- a/internal/service/glue/trigger.go +++ b/internal/service/glue/trigger.go @@ -39,6 +39,7 @@ func ResourceTrigger() *schema.Resource { }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(5 * time.Minute), Delete: schema.DefaultTimeout(5 * time.Minute), }, @@ -407,7 +408,7 @@ func resourceTriggerUpdate(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "updating Glue Trigger (%s): %s", d.Id(), err) } - if _, err := waitTriggerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitTriggerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Glue Trigger (%s) to be Update: %s", d.Id(), err) } } diff --git a/internal/service/glue/trigger_test.go b/internal/service/glue/trigger_test.go index 3527f6777d6..707fbece224 100644 --- a/internal/service/glue/trigger_test.go +++ b/internal/service/glue/trigger_test.go @@ -185,7 +185,7 @@ func TestAccGlueTrigger_enabled(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ImportStateVerifyIgnore: []string{"enabled", "state"}, // adding state to igonre list because trigger state changes faster before test can verify what is in TF state }, }, }) @@ -729,7 +729,11 @@ resource "aws_glue_trigger" "test" { } func testAccTriggerConfig_crawler(rName, state string) string { - return acctest.ConfigCompose(testAccCrawlerConfig_s3Target(rName, "s3://test_bucket"), fmt.Sprintf(` + return acctest.ConfigCompose(testAccCrawlerConfig_s3Target(rName, "s3://${aws_s3_bucket.test.bucket}"), fmt.Sprintf(` +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} + resource "aws_glue_crawler" "test2" { depends_on = [aws_iam_role_policy_attachment.test-AWSGlueServiceRole] @@ -738,7 +742,7 @@ resource "aws_glue_crawler" "test2" { role = aws_iam_role.test.name s3_target { - path = "s3://test_bucket" + path = "s3://${aws_s3_bucket.test.bucket}" } } From ed9737c224311cf6d7a9f09fff251b1304f3cb58 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 9 Feb 2024 12:13:35 -0600 Subject: [PATCH 4/5] aws_glue_trigger: update documentation --- website/docs/r/glue_trigger.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/glue_trigger.html.markdown b/website/docs/r/glue_trigger.html.markdown index 3c837cae9b0..cc04a1906f7 100644 --- a/website/docs/r/glue_trigger.html.markdown +++ b/website/docs/r/glue_trigger.html.markdown @@ -164,6 +164,7 @@ This resource exports the following attributes in addition to the arguments abov [Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): - `create` - (Default `5m`) +- `update` - (Default `5m`) - `delete` - (Default `5m`) ## Import From 53b9b399aa8439f349d72e33cbcf8649359ec1f6 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 9 Feb 2024 12:15:03 -0600 Subject: [PATCH 5/5] tweak CHANGELOG entry --- .changelog/35542.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/35542.txt b/.changelog/35542.txt index b6518d0a568..07c1fd0edb6 100644 --- a/.changelog/35542.txt +++ b/.changelog/35542.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_glue_trigger: Add `timeouts` configuration +resource/aws_glue_trigger: Add configurable `timeouts` ```