Skip to content

r/aws_instance: prevent destroy if disable_api_termination is enabled#43722

Merged
johnsonaj merged 13 commits into
mainfrom
b-aws_instance_disable_api_termination
Aug 6, 2025
Merged

r/aws_instance: prevent destroy if disable_api_termination is enabled#43722
johnsonaj merged 13 commits into
mainfrom
b-aws_instance_disable_api_termination

Conversation

@johnsonaj

@johnsonaj johnsonaj commented Aug 5, 2025

Copy link
Copy Markdown
Member

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

When disable_api_termination is enabled terraform should fail to destroy the resource.

This PR prevents destruction of a resource with this enabled

  • add a new virtual attribute force_destroy to enable destroying an instance that has disable_api_termination enabled.
resource "aws_instance" "test" {
  ami            = data.aws_ami.test.id
  instance_type  = "t2.medium"
  subnet_id      = aws_subnet.test.id

  disable_api_termination = true
  force_destroy = true
}

Relations

References

Output from Acceptance Testing

% make testacc TESTARGS='-run=TestAccEC2Instance_disableAPITerminationFinal\|TestAccEC2Instance_basic\|TestAccEC2Instance_disappears' PKG=ec2

make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.5 test ./internal/service/ec2/... -v -count 1 -parallel 20  -run=TestAccEC2Instance_disableAPITerminationFinal\|TestAccEC2Instance_basic\|TestAccEC2Instance_disappears -timeout 360m -vet=off
2025/08/05 13:53:24 Creating Terraform AWS Provider (SDKv2-style)...
2025/08/05 13:53:24 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2Instance_basic
=== PAUSE TestAccEC2Instance_basic
=== RUN   TestAccEC2Instance_disappears
=== PAUSE TestAccEC2Instance_disappears
=== RUN   TestAccEC2Instance_disableAPITerminationFinalFalse
=== PAUSE TestAccEC2Instance_disableAPITerminationFinalFalse
=== RUN   TestAccEC2Instance_disableAPITerminationFinalTrue
=== PAUSE TestAccEC2Instance_disableAPITerminationFinalTrue
=== RUN   TestAccEC2Instance_basicWithSpot
=== PAUSE TestAccEC2Instance_basicWithSpot
=== CONT  TestAccEC2Instance_basic
=== CONT  TestAccEC2Instance_disableAPITerminationFinalTrue
=== CONT  TestAccEC2Instance_disableAPITerminationFinalFalse
=== CONT  TestAccEC2Instance_disappears
=== CONT  TestAccEC2Instance_basicWithSpot
--- PASS: TestAccEC2Instance_disappears (67.42s)
--- PASS: TestAccEC2Instance_basic (83.15s)
--- PASS: TestAccEC2Instance_basicWithSpot (83.20s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalTrue (86.98s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalFalse (92.23s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	98.673s

@github-actions

github-actions Bot commented Aug 5, 2025

Copy link
Copy Markdown
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 tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/ec2 Issues and PRs that pertain to the ec2 service. size/L Managed by automation to categorize the size of a PR. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Aug 5, 2025
@johnsonaj johnsonaj added the bug Addresses a defect in current functionality. label Aug 5, 2025
@github-actions github-actions Bot added the documentation Introduces or discusses updates to documentation. label Aug 5, 2025
@johnsonaj johnsonaj marked this pull request as ready for review August 6, 2025 14:29
@johnsonaj johnsonaj requested a review from a team as a code owner August 6, 2025 14:29
Comment thread .changelog/43722.txt Outdated
Comment thread internal/service/ec2/ec2_instance.go Outdated
@johnsonaj

Copy link
Copy Markdown
Member Author
% make testacc TESTARGS='-run=TestAccEC2Instance_disableAPITerminationFinal\|TestAccEC2Instance_basic\|TestAccEC2Instance_disappears\|TestAccEC2Instance_disableAPIStop' PKG=ec2

make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.5 test ./internal/service/ec2/... -v -count 1 -parallel 20  -run=TestAccEC2Instance_disableAPITerminationFinal\|TestAccEC2Instance_basic\|TestAccEC2Instance_disappears\|TestAccEC2Instance_disableAPIStop -timeout 360m -vet=off
2025/08/06 10:22:55 Creating Terraform AWS Provider (SDKv2-style)...
2025/08/06 10:22:55 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2Instance_basic
=== PAUSE TestAccEC2Instance_basic
=== RUN   TestAccEC2Instance_disappears
=== PAUSE TestAccEC2Instance_disappears
=== RUN   TestAccEC2Instance_disableAPIStop
=== PAUSE TestAccEC2Instance_disableAPIStop
=== RUN   TestAccEC2Instance_disableAPITerminationFinalFalse
=== PAUSE TestAccEC2Instance_disableAPITerminationFinalFalse
=== RUN   TestAccEC2Instance_disableAPITerminationFinalTrue
=== PAUSE TestAccEC2Instance_disableAPITerminationFinalTrue
=== RUN   TestAccEC2Instance_basicWithSpot
=== PAUSE TestAccEC2Instance_basicWithSpot
=== CONT  TestAccEC2Instance_basic
=== CONT  TestAccEC2Instance_disableAPITerminationFinalFalse
=== CONT  TestAccEC2Instance_basicWithSpot
=== CONT  TestAccEC2Instance_disableAPITerminationFinalTrue
=== CONT  TestAccEC2Instance_disableAPIStop
=== CONT  TestAccEC2Instance_disappears
--- PASS: TestAccEC2Instance_disappears (57.70s)
--- PASS: TestAccEC2Instance_basic (72.62s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalFalse (93.50s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalTrue (97.58s)
--- PASS: TestAccEC2Instance_basicWithSpot (106.21s)
--- PASS: TestAccEC2Instance_disableAPIStop (108.64s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	115.340s

@johnsonaj johnsonaj force-pushed the b-aws_instance_disable_api_termination branch from d0a1390 to dee4289 Compare August 6, 2025 15:32
Comment thread website/docs/r/instance.html.markdown Outdated

@ewbankkit ewbankkit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀.

@johnsonaj johnsonaj merged commit 90ac98d into main Aug 6, 2025
65 checks passed
@johnsonaj johnsonaj deleted the b-aws_instance_disable_api_termination branch August 6, 2025 16:49
@github-actions

github-actions Bot commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

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.8.0 milestone Aug 6, 2025
terraform-aws-provider Bot pushed a commit that referenced this pull request Aug 6, 2025
@github-actions

github-actions Bot commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

This functionality has been released in v6.8.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!

@github-actions github-actions Bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Aug 7, 2025
@github-actions

github-actions Bot commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Addresses a defect in current functionality. documentation Introduces or discusses updates to documentation. service/ec2 Issues and PRs that pertain to the ec2 service. size/L 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.

3 participants