Skip to content

Commit 059a9d0

Browse files
authored
r/aws_scheduler_schedule: add action_after_completion argument (#44264)
This argument aligns with the `ActionAfterCompletion` field in the Create and Update APIs. When unset, the value defaults to `NONE`. - https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html#scheduler-CreateSchedule-request-ActionAfterCompletion ```console % make testacc PKG=scheduler TESTS=TestAccSchedulerSchedule_ make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... make: Running acceptance tests on branch: 🌿 tmp1 🌿... TF_ACC=1 go1.24.6 test ./internal/service/scheduler/... -v -count 1 -parallel 20 -run='TestAccSchedulerSchedule_' -timeout 360m -vet=off 2025/09/12 12:02:05 Creating Terraform AWS Provider (SDKv2-style)... 2025/09/12 12:02:05 Initializing Terraform AWS Provider (SDKv2-style)... --- PASS: TestAccSchedulerSchedule_basic (69.73s) === CONT TestAccSchedulerSchedule_targetECSParameters --- PASS: TestAccSchedulerSchedule_nameGenerated (72.83s) === CONT TestAccSchedulerSchedule_disappears --- PASS: TestAccSchedulerSchedule_namePrefix (75.09s) === CONT TestAccSchedulerSchedule_targetARN --- PASS: TestAccSchedulerSchedule_groupName (80.71s) === CONT TestAccSchedulerSchedule_state --- PASS: TestAccSchedulerSchedule_targetInput (98.37s) --- PASS: TestAccSchedulerSchedule_scheduleExpression (102.96s) --- PASS: TestAccSchedulerSchedule_targetRoleARN (105.14s) --- PASS: TestAccSchedulerSchedule_actionAfterCompletion (108.99s) --- PASS: TestAccSchedulerSchedule_startDate (119.81s) --- PASS: TestAccSchedulerSchedule_flexibleTimeWindow (120.33s) --- PASS: TestAccSchedulerSchedule_scheduleExpressionTimezone (121.86s) --- PASS: TestAccSchedulerSchedule_targetRetryPolicy (123.36s) --- PASS: TestAccSchedulerSchedule_kmsKeyARN (124.96s) --- PASS: TestAccSchedulerSchedule_description (125.05s) --- PASS: TestAccSchedulerSchedule_endDate (125.43s) --- PASS: TestAccSchedulerSchedule_disappears (53.28s) --- PASS: TestAccSchedulerSchedule_targetSQSParameters (126.52s) --- PASS: TestAccSchedulerSchedule_targetEventBridgeParameters (127.22s) --- PASS: TestAccSchedulerSchedule_targetDeadLetterConfig (127.23s) --- PASS: TestAccSchedulerSchedule_targetKinesisParameters (136.70s) --- PASS: TestAccSchedulerSchedule_targetARN (68.21s) --- PASS: TestAccSchedulerSchedule_targetSageMakerPipelineParameters (146.42s) --- PASS: TestAccSchedulerSchedule_state (76.45s) --- PASS: TestAccSchedulerSchedule_targetECSParameters (124.94s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/scheduler 201.405s ```
1 parent 772315d commit 059a9d0

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

.changelog/44264.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_scheduler_schedule: Add `action_after_completion` argument
3+
```

internal/service/scheduler/schedule.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func resourceSchedule() *schema.Resource {
4545
},
4646

4747
Schema: map[string]*schema.Schema{
48+
"action_after_completion": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Computed: true,
52+
ValidateDiagFunc: enum.Validate[types.ActionAfterCompletion](),
53+
},
4854
names.AttrARN: {
4955
Type: schema.TypeString,
5056
Computed: true,
@@ -442,6 +448,10 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, meta an
442448
ScheduleExpression: aws.String(d.Get(names.AttrScheduleExpression).(string)),
443449
}
444450

451+
if v, ok := d.Get("action_after_completion").(string); ok && v != "" {
452+
in.ActionAfterCompletion = types.ActionAfterCompletion(v)
453+
}
454+
445455
if v, ok := d.Get(names.AttrDescription).(string); ok && v != "" {
446456
in.Description = aws.String(v)
447457
}
@@ -532,6 +542,7 @@ func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, meta any)
532542
return create.AppendDiagError(diags, names.Scheduler, create.ErrActionReading, ResNameSchedule, d.Id(), err)
533543
}
534544

545+
d.Set("action_after_completion", out.ActionAfterCompletion)
535546
d.Set(names.AttrARN, out.Arn)
536547
d.Set(names.AttrDescription, out.Description)
537548

@@ -579,6 +590,10 @@ func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, meta an
579590
Target: expandTarget(ctx, d.Get(names.AttrTarget).([]any)[0].(map[string]any)),
580591
}
581592

593+
if v, ok := d.Get("action_after_completion").(string); ok && v != "" {
594+
in.ActionAfterCompletion = types.ActionAfterCompletion(v)
595+
}
596+
582597
if v, ok := d.Get(names.AttrDescription).(string); ok && v != "" {
583598
in.Description = aws.String(v)
584599
}

internal/service/scheduler/schedule_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212

1313
"github.com/YakDriver/regexache"
1414
"github.com/aws/aws-sdk-go-v2/service/scheduler"
15+
awstypes "github.com/aws/aws-sdk-go-v2/service/scheduler/types"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
1617
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1719
"github.com/hashicorp/terraform-plugin-testing/terraform"
1820
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1921
"github.com/hashicorp/terraform-provider-aws/internal/create"
@@ -201,6 +203,7 @@ func TestAccSchedulerSchedule_basic(t *testing.T) {
201203
Check: resource.ComposeTestCheckFunc(
202204
testAccCheckScheduleExists(ctx, t, resourceName, &schedule),
203205
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "scheduler", regexache.MustCompile(regexp.QuoteMeta(`schedule/default/`+name))),
206+
resource.TestCheckResourceAttr(resourceName, "action_after_completion", string(awstypes.ActionAfterCompletionNone)),
204207
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
205208
resource.TestCheckResourceAttr(resourceName, "end_date", ""),
206209
resource.TestCheckResourceAttr(resourceName, "flexible_time_window.0.maximum_window_in_minutes", "0"),
@@ -261,12 +264,62 @@ func TestAccSchedulerSchedule_disappears(t *testing.T) {
261264
testAccCheckScheduleExists(ctx, t, resourceName, &schedule),
262265
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfscheduler.ResourceSchedule(), resourceName),
263266
),
267+
ConfigPlanChecks: resource.ConfigPlanChecks{
268+
PostApplyPostRefresh: []plancheck.PlanCheck{
269+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
270+
},
271+
},
264272
ExpectNonEmptyPlan: true,
265273
},
266274
},
267275
})
268276
}
269277

278+
func TestAccSchedulerSchedule_actionAfterCompletion(t *testing.T) {
279+
ctx := acctest.Context(t)
280+
if testing.Short() {
281+
t.Skip("skipping long-running test in short mode")
282+
}
283+
284+
var schedule scheduler.GetScheduleOutput
285+
name := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
286+
resourceName := "aws_scheduler_schedule.test"
287+
288+
acctest.ParallelTest(ctx, t, resource.TestCase{
289+
PreCheck: func() {
290+
acctest.PreCheck(ctx, t)
291+
acctest.PreCheckPartitionHasService(t, names.SchedulerEndpointID)
292+
testAccPreCheck(ctx, t)
293+
},
294+
ErrorCheck: acctest.ErrorCheck(t, names.SchedulerServiceID),
295+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
296+
CheckDestroy: testAccCheckScheduleDestroy(ctx, t),
297+
Steps: []resource.TestStep{
298+
{
299+
Config: testAccScheduleConfig_actionAfterCompletion(name, string(awstypes.ActionAfterCompletionNone)),
300+
Check: resource.ComposeTestCheckFunc(
301+
testAccCheckScheduleExists(ctx, t, resourceName, &schedule),
302+
resource.TestCheckResourceAttr(resourceName, "action_after_completion", string(awstypes.ActionAfterCompletionNone)),
303+
),
304+
},
305+
{
306+
Config: testAccScheduleConfig_actionAfterCompletion(name, string(awstypes.ActionAfterCompletionDelete)),
307+
Check: resource.ComposeTestCheckFunc(
308+
testAccCheckScheduleExists(ctx, t, resourceName, &schedule),
309+
resource.TestCheckResourceAttr(resourceName, "action_after_completion", string(awstypes.ActionAfterCompletionDelete)),
310+
),
311+
},
312+
{
313+
Config: testAccScheduleConfig_actionAfterCompletion(name, string(awstypes.ActionAfterCompletionNone)),
314+
Check: resource.ComposeTestCheckFunc(
315+
testAccCheckScheduleExists(ctx, t, resourceName, &schedule),
316+
resource.TestCheckResourceAttr(resourceName, "action_after_completion", string(awstypes.ActionAfterCompletionNone)),
317+
),
318+
},
319+
},
320+
})
321+
}
322+
270323
func TestAccSchedulerSchedule_description(t *testing.T) {
271324
ctx := acctest.Context(t)
272325
if testing.Short() {
@@ -1695,6 +1748,32 @@ resource "aws_scheduler_schedule" "test" {
16951748
)
16961749
}
16971750

1751+
func testAccScheduleConfig_actionAfterCompletion(rName, actionAfterCompletion string) string {
1752+
return acctest.ConfigCompose(
1753+
testAccScheduleConfig_base,
1754+
fmt.Sprintf(`
1755+
resource "aws_sqs_queue" "test" {}
1756+
1757+
resource "aws_scheduler_schedule" "test" {
1758+
name = %[1]q
1759+
1760+
action_after_completion = %[2]q
1761+
1762+
flexible_time_window {
1763+
mode = "OFF"
1764+
}
1765+
1766+
schedule_expression = "rate(1 hour)"
1767+
1768+
target {
1769+
arn = aws_sqs_queue.test.arn
1770+
role_arn = aws_iam_role.test.arn
1771+
}
1772+
}
1773+
`, rName, actionAfterCompletion),
1774+
)
1775+
}
1776+
16981777
func testAccScheduleConfig_description(name, description string) string {
16991778
return acctest.ConfigCompose(
17001779
testAccScheduleConfig_base,

website/docs/r/scheduler_schedule.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ The following arguments are required:
7272

7373
The following arguments are optional:
7474

75-
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
75+
* `action_after_completion` - (Optional) Action that applies to the schedule after completing invocation of the target. Valid values are `NONE` and `DELETE`. Defaults to `NONE`.
7676
* `description` - (Optional) Brief description of the schedule.
7777
* `end_date` - (Optional) The date, in UTC, before which the schedule can invoke its target. Depending on the schedule's recurrence expression, invocations might stop on, or before, the end date you specify. EventBridge Scheduler ignores the end date for one-time schedules. Example: `2030-01-01T01:00:00Z`.
7878
* `group_name` - (Optional, Forces new resource) Name of the schedule group to associate with this schedule. When omitted, the `default` schedule group is used.
7979
* `kms_key_arn` - (Optional) ARN for the customer managed KMS key that EventBridge Scheduler will use to encrypt and decrypt your data.
8080
* `name` - (Optional, Forces new resource) Name of the schedule. If omitted, Terraform will assign a random, unique name. Conflicts with `name_prefix`.
8181
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`.
82+
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
8283
* `schedule_expression_timezone` - (Optional) Timezone in which the scheduling expression is evaluated. Defaults to `UTC`. Example: `Australia/Sydney`.
8384
* `start_date` - (Optional) The date, in UTC, after which the schedule can begin invoking its target. Depending on the schedule's recurrence expression, invocations might occur on, or after, the start date you specify. EventBridge Scheduler ignores the start date for one-time schedules. Example: `2030-01-01T01:00:00Z`.
8485
* `state` - (Optional) Specifies whether the schedule is enabled or disabled. One of: `ENABLED` (default), `DISABLED`.

0 commit comments

Comments
 (0)