-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New action: aws_ec2_stop_instance
#43700
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
Conversation
Community GuidelinesThis 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
Pull Request Authors
|
d7b5734 to
636f7cb
Compare
aws_ec2_stop_instance
9e884a9 to
2020d3a
Compare
2020d3a to
bbf1826
Compare
bbf1826 to
a689ba9
Compare
aws_ec2_stop_instanceaws_ec2_stop_instance
|
Recent: % make t T=TestAccEC2StopInstanceAction_ K=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-ec2-instance-action-2 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2StopInstanceAction_' -timeout 360m -vet=off
2025/09/16 23:21:45 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/16 23:21:45 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN TestAccEC2StopInstanceAction_basic
=== PAUSE TestAccEC2StopInstanceAction_basic
=== RUN TestAccEC2StopInstanceAction_trigger
=== PAUSE TestAccEC2StopInstanceAction_trigger
=== CONT TestAccEC2StopInstanceAction_basic
=== CONT TestAccEC2StopInstanceAction_trigger
=== NAME TestAccEC2StopInstanceAction_basic
ec2_stop_instance_action_test.go:321: Progress: Starting stop operation for EC2 instance i-02805387ef8ba7f52...
ec2_stop_instance_action_test.go:321: Progress: Sending stop command to EC2 instance i-02805387ef8ba7f52...
ec2_stop_instance_action_test.go:321: Progress: Stop command sent to EC2 instance i-02805387ef8ba7f52, waiting for instance to stop...
ec2_stop_instance_action_test.go:321: Progress: EC2 instance i-02805387ef8ba7f52 is currently in state 'stopping', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:321: Progress: EC2 instance i-02805387ef8ba7f52 is currently in state 'stopping', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:321: Progress: EC2 instance i-02805387ef8ba7f52 has been successfully stopped
--- PASS: TestAccEC2StopInstanceAction_basic (134.99s)
--- PASS: TestAccEC2StopInstanceAction_trigger (141.83s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 147.577s |
|
After rebase: % make t T=TestAccEC2StopInstanceAction_ K=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-ec2-instance-action-2 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2StopInstanceAction_' -timeout 360m -vet=off
2025/09/17 12:11:08 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/17 12:11:08 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN TestAccEC2StopInstanceAction_basic
=== PAUSE TestAccEC2StopInstanceAction_basic
=== RUN TestAccEC2StopInstanceAction_trigger
=== PAUSE TestAccEC2StopInstanceAction_trigger
=== CONT TestAccEC2StopInstanceAction_basic
=== CONT TestAccEC2StopInstanceAction_trigger
=== NAME TestAccEC2StopInstanceAction_basic
ec2_stop_instance_action_test.go:328: Progress: Starting stop operation for EC2 instance i-07707afd411368dc3...
ec2_stop_instance_action_test.go:328: Progress: Sending stop command to EC2 instance i-07707afd411368dc3...
ec2_stop_instance_action_test.go:328: Progress: Stop command sent to EC2 instance i-07707afd411368dc3, waiting for instance to stop...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-07707afd411368dc3 is currently in state 'stopping', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-07707afd411368dc3 is currently in state 'stopped', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-07707afd411368dc3 has been successfully stopped
--- PASS: TestAccEC2StopInstanceAction_trigger (91.04s)
--- PASS: TestAccEC2StopInstanceAction_basic (114.35s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 120.180s |
jar-b
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
% TF_ACC_TERRAFORM_PATH=/Users/jaredbaker/go/bin/terraform make t K=ec2 T=TestAccEC2StopInstanceAction_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-ec2-instance-action-2 🌿...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2StopInstanceAction_' -timeout 360m -vet=off
2025/09/17 15:46:15 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/17 15:46:15 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN TestAccEC2StopInstanceAction_basic
=== PAUSE TestAccEC2StopInstanceAction_basic
=== RUN TestAccEC2StopInstanceAction_trigger
=== PAUSE TestAccEC2StopInstanceAction_trigger
=== CONT TestAccEC2StopInstanceAction_basic
=== CONT TestAccEC2StopInstanceAction_trigger
=== NAME TestAccEC2StopInstanceAction_basic
ec2_stop_instance_action_test.go:328: Progress: Starting stop operation for EC2 instance i-0c00d744db5856923...
ec2_stop_instance_action_test.go:328: Progress: Sending stop command to EC2 instance i-0c00d744db5856923...
ec2_stop_instance_action_test.go:328: Progress: Stop command sent to EC2 instance i-0c00d744db5856923, waiting for instance to stop...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-0c00d744db5856923 is currently in state 'stopping', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-0c00d744db5856923 is currently in state 'stopping', continuing to wait for 'stopped'...
ec2_stop_instance_action_test.go:328: Progress: EC2 instance i-0c00d744db5856923 has been successfully stopped
--- PASS: TestAccEC2StopInstanceAction_basic (125.10s)
--- PASS: TestAccEC2StopInstanceAction_trigger (131.65s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 138.603s|
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. |
|
This functionality has been released in v6.14.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! |
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
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
Since these actions may be merged in bulk, extra checklist to help:
terraform_datatriggerwebsite/docs/actions/fileregionpattern (framework.WithRegionModel)This PR introduces the very first Terraform Action in the AWS Provider:
aws_ec2_stop_instance! 🎉Terraform Actions are an exciting new feature in Terraform Core that allow users to model imperative, side-effecting operations—like stopping an EC2 instance—within the plan and apply lifecycle. Actions can be triggered directly via
terraform invokeor automatically as part of resource lifecycle events using the newlifecycle.action_triggerblock.This first Action provides support for stopping an EC2 instance by ID. It’s especially useful for cost-saving workflows, controlled shutdowns during infrastructure updates, and testing Terraform Actions in a real-world scenario. Here's an example of how to use it:
This will automatically stop the instance before any create or update operation on the
terraform_data.triggerresource, helping you integrate safe shutdown behavior into your infrastructure workflows.Big thanks to the Terraform Core and Plugin Framework teams for enabling this new model—we’re just getting started!
Relations
aws_lambda_invoke#43972aws_cloudfront_create_invalidation#43955aws_ses_send_email#44214aws_sns_publish#44232aws_ec2_stop_instance#43700 (this)References
Output from Acceptance Testing