Skip to content

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented Sep 26, 2025

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the library.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Description

Introduces a new internal actionwait package: a lightweight, action-focused polling helper tailored for asynchronous AWS operation actions (e.g., EC2 stop, CloudFront invalidation, CodeBuild build) where we need deterministic status progression tracking and periodic user-facing progress updates without the heavier resource lifecycle semantics of retry.StateChangeConf.

It provides a clear state taxonomy (success, transitional, failure, unexpected), pluggable interval strategies including fixed intervals and backoff integration via a bridge adapter to internal/backoff for sophisticated delay algorithms, throttled progress callbacks decoupled from poll cadence, typed errors (TimeoutError, FailureStateError, UnexpectedStateError) with dedicated helper functions for error type checking, and optional typed payloads via generics to return rich SDK objects without wrappers.

The package is organized into separate files (wait.go for core logic, errors.go for error types and helpers) for better maintainability. This refactor reduces duplicated bespoke loops (deadline math, sleep, transitional guards), improves safety by uniformly surfacing unexpected states, provides flexible polling strategies (fixed for predictable operations like EC2 instance transitions, backoff for variable-duration operations like CodeBuild), and future‑proofs consecutive success handling.

Comprehensive unit tests cover validation, success after transitions, failures, unexpected states, timeout, context cancel, fetch errors, progress throttling, consecutive success logic, and backoff adapter integration, ensuring behavior is well specified and stable for current and upcoming action implementations.

Relations

References

Output from Acceptance Testing

% go test ./internal/actionwait         
ok  	github.com/hashicorp/terraform-provider-aws/internal/actionwait	0.235s
% make t T=TestAccCloudFrontCreateInvalidationAction_basic K=cloudfront    
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/cloudfront/... -v -count 1 -parallel 20 -run='TestAccCloudFrontCreateInvalidationAction_basic'  -timeout 360m -vet=off
2025/09/25 20:54:37 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/25 20:54:37 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccCloudFrontCreateInvalidationAction_basic
=== PAUSE TestAccCloudFrontCreateInvalidationAction_basic
=== CONT  TestAccCloudFrontCreateInvalidationAction_basic
--- PASS: TestAccCloudFrontCreateInvalidationAction_basic (467.02s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudfront	472.441s
% make t T=TestAccCodeBuildStartBuildAction_basic K=codebuild       
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/codebuild/... -v -count 1 -parallel 20 -run='TestAccCodeBuildStartBuildAction_basic'  -timeout 360m -vet=off
2025/09/25 20:51:07 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/25 20:51:07 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccCodeBuildStartBuildAction_basic
=== PAUSE TestAccCodeBuildStartBuildAction_basic
=== CONT  TestAccCodeBuildStartBuildAction_basic
--- PASS: TestAccCodeBuildStartBuildAction_basic (68.17s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/codebuild	73.697s
% make t T=TestAccEC2StopInstanceAction_basic K=ec2          
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2StopInstanceAction_basic'  -timeout 360m -vet=off
2025/09/25 20:57:18 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/25 20:57:18 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2StopInstanceAction_basic
=== PAUSE TestAccEC2StopInstanceAction_basic
=== CONT  TestAccEC2StopInstanceAction_basic
    ec2_stop_instance_action_test.go:328: Progress: Starting stop operation for EC2 instance i-02812c4aac946f11e...
    ec2_stop_instance_action_test.go:328: Progress: Sending stop command to EC2 instance i-02812c4aac946f11e...
    ec2_stop_instance_action_test.go:328: Progress: Stop command sent to EC2 instance i-02812c4aac946f11e, waiting for instance to stop...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-02812c4aac946f11e is currently in state 'running', continuing to wait for 'stopped'...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-02812c4aac946f11e is currently in state 'stopping', continuing to wait for 'stopped'...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-02812c4aac946f11e is currently in state 'stopping', continuing to wait for 'stopped'...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-02812c4aac946f11e has been successfully stopped
--- PASS: TestAccEC2StopInstanceAction_basic (115.45s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	120.987s

@YakDriver YakDriver requested a review from a team as a code owner September 26, 2025 04:01
Copy link
Contributor

Community Guidelines

This comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀

Voting for Prioritization

  • Please vote on this Pull Request by adding a 👍 reaction to the original post to help the community and maintainers prioritize it.
  • Please see our prioritization guide for additional information on how the maintainers handle prioritization.
  • Please do not leave +1 or other comments that do not add relevant new information or questions; they generate extra noise for others following the Pull Request and do not help prioritize the request.

Pull Request Authors

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. labels Sep 26, 2025
@github-actions github-actions bot added service/ec2 Issues and PRs that pertain to the ec2 service. service/codebuild Issues and PRs that pertain to the codebuild service. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Sep 26, 2025
@YakDriver YakDriver added the no-changelog-needed Indicates that a changelog entry is not necessary label Sep 26, 2025
@YakDriver
Copy link
Member Author

YakDriver commented Sep 29, 2025

I'm thinking this could be genericized to reduce waiter boilerplate at the same time. That might be too much for one side project PR though.

@YakDriver
Copy link
Member Author

Most recent:

% make t T=TestAccEC2StopInstanceAction_basic K=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2StopInstanceAction_basic'  -timeout 360m -vet=off
2025/09/30 17:45:05 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/30 17:45:05 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2StopInstanceAction_basic
=== PAUSE TestAccEC2StopInstanceAction_basic
=== CONT  TestAccEC2StopInstanceAction_basic
    ec2_stop_instance_action_test.go:328: Progress: Starting stop operation for EC2 instance i-04068524d01beb19b...
    ec2_stop_instance_action_test.go:328: Progress: Sending stop command to EC2 instance i-04068524d01beb19b...
    ec2_stop_instance_action_test.go:328: Progress: Stop command sent to EC2 instance i-04068524d01beb19b, waiting for instance to stop...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-04068524d01beb19b is currently in state 'running', continuing to wait for 'stopped'...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-04068524d01beb19b is currently in state 'stopping', continuing to wait for 'stopped'...
    ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-04068524d01beb19b has been successfully stopped
--- PASS: TestAccEC2StopInstanceAction_basic (93.68s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	99.190s
% make t T=TestAccCodeBuildStartBuildAction_ K=codebuild               
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/codebuild/... -v -count 1 -parallel 20 -run='TestAccCodeBuildStartBuildAction_'  -timeout 360m -vet=off
2025/09/30 17:16:16 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/30 17:16:16 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccCodeBuildStartBuildAction_basic
=== PAUSE TestAccCodeBuildStartBuildAction_basic
=== RUN   TestAccCodeBuildStartBuildAction_withEnvironmentVariables
=== PAUSE TestAccCodeBuildStartBuildAction_withEnvironmentVariables
=== CONT  TestAccCodeBuildStartBuildAction_basic
=== CONT  TestAccCodeBuildStartBuildAction_withEnvironmentVariables
--- PASS: TestAccCodeBuildStartBuildAction_withEnvironmentVariables (62.24s)
--- PASS: TestAccCodeBuildStartBuildAction_basic (62.26s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/codebuild	67.772s
% make t T=TestAccCloudFrontCreateInvalidationAction_basic K=cloudfront
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-polling-library-for-actions 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/cloudfront/... -v -count 1 -parallel 20 -run='TestAccCloudFrontCreateInvalidationAction_basic'  -timeout 360m -vet=off
2025/09/30 16:57:24 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/30 16:57:24 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccCloudFrontCreateInvalidationAction_basic
=== PAUSE TestAccCloudFrontCreateInvalidationAction_basic
=== CONT  TestAccCloudFrontCreateInvalidationAction_basic
--- PASS: TestAccCloudFrontCreateInvalidationAction_basic (449.17s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudfront	454.859s

Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

@YakDriver YakDriver merged commit a73675d into main Oct 3, 2025
54 checks passed
@YakDriver YakDriver deleted the f-polling-library-for-actions branch October 3, 2025 19:43
Copy link
Contributor

github-actions bot commented Oct 3, 2025

Warning

This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v6.16.0 milestone Oct 3, 2025
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 9, 2025
Copy link
Contributor

github-actions bot commented Oct 9, 2025

This functionality has been released in v6.16.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog-needed Indicates that a changelog entry is not necessary service/cloudfront Issues and PRs that pertain to the cloudfront service. service/codebuild Issues and PRs that pertain to the codebuild service. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants