multicloud365
  • Home
  • Cloud Architecture
    • OCI
    • GCP
    • Azure
    • AWS
    • IAC
    • Cloud Networking
    • Cloud Trends and Innovations
    • Cloud Security
    • Cloud Platforms
  • Data Management
  • DevOps and Automation
    • Tutorials and How-Tos
  • Case Studies and Industry Insights
    • AI and Machine Learning in the Cloud
No Result
View All Result
  • Home
  • Cloud Architecture
    • OCI
    • GCP
    • Azure
    • AWS
    • IAC
    • Cloud Networking
    • Cloud Trends and Innovations
    • Cloud Security
    • Cloud Platforms
  • Data Management
  • DevOps and Automation
    • Tutorials and How-Tos
  • Case Studies and Industry Insights
    • AI and Machine Learning in the Cloud
No Result
View All Result
multicloud365
No Result
View All Result

Tidying up after failed Terraform exams

admin by admin
April 6, 2025
in AWS
0
Tidying up after failed Terraform exams
399
SHARES
2.3k
VIEWS
Share on FacebookShare on Twitter


Automated exams are making their means into Infrastructure as Code tasks. Just lately, I’ve carried out exams with Terraform’s check framework which was launched in October 2023. Nonetheless, I bumped into the problem that Terraform couldn’t take away all AWS assets on the finish of the check underneath uncommon circumstances.

The issue and resolution mentioned within the following additionally apply to OpenTofu.

Tidying up after failed Terraform tests

Right here is the standard message that terraform check will print out in case cleansing up all of the assets fails.

Terraform left the next assets in state after executing
exams/default.tftest.hcl/execute, and they want to be cleaned up manually:
- aws_subnet.non-public[0]
- aws_subnet.non-public[1]
- aws_subnet.public[0]
- aws_subnet.public[1]
- aws_vpc.this
- ...

Leftover AWS assets are a problem, particularly when operating exams in an automatic method, inflicting undesirable prices. Due to this fact, I used to be in search of an answer to tidy up AWS assets usually. The software aws-nuke, by rebuy, deletes all assets belonging to an AWS account.

The next snippet exhibits the configuration file nuke-config.yml for aws-nuke. First, outline which areas aws-nuke shall take away assets. world is required to delete world assets like IAM roles and insurance policies. For security causes, defining an account-blocklist with AWS account IDs that you just by no means wish to tidy up is important. Subsequent, you outline the accounts the place you wish to take away all assets. The filters are required to maintain some important assets, such because the IAM position and coverage utilized by aws-nuke to entry the AWS account.

areas:
- eu-west-1
- world
account-blocklist:
- '999999999999'
accounts:
'111111111111':
filters:
IAMRole:
- 'nuke'
IAMRolePolicy:
- sort: glob
worth: "nuke -> *"

My advice is to run aws-nuke with the dry run possibility activated – which is the default – and verify for assets you wish to maintain. Then, add a filter for these assets. Learn to set up aws-nuke.

aws-nuke -c nuke-config.yml

For instance, aws-nuke deletes the VPC and subnets left over from the Terraform check.

> aws-nuke-example

eu-west-1 - EC2Subnet - 'subnet-154d844e' - would take away
eu-west-1 - EC2Subnet - 'subnet-af12a261' - would take away
eu-west-1 - EC2Subnet - 'subnet-cd2fa222' - would take away
eu-west-1 - EC2Subnet - 'subnet-51223aff' - would take away
eu-west-1 - EC2VPC - 'vpc-c6159fa1' - would take away
Scan full: 13 complete, 5 nukeable, 10 filtered.

Whereas it’s doable to run aws-nuke out of your machine to make sure leftover AWS assets are usually cleaned up, a scheduled job is the best way to go. As I’m operating the command terraform check inside a CI/CD pipeline on GitHub, I made a decision to make use of a scheduled GitHub workflow to run aws-nuke as soon as a day. The next snippet illustrates find out how to outline a GitHub workflow to usually run aws-nuke to delete assets belonging to an AWS account.

title: 'nuke'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
concurrency:
group: 'nuke'
cancel-in-progress: false
permissions:
id-token: write
contents: learn
jobs:
nuke:
runs-on: ubuntu-latest
steps:
- makes use of: actions/checkout@v4
- title: 'Assuming IAM position'
makes use of: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::111111111111:position/nuke
role-session-name: nuke
aws-region: eu-west-1
- title: 'Tidying up AWS assets'
run: |
docker run -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} -e AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN} --rm -v ./nuke-config.yml:/house/aws-nuke/config.yml quay.io/rebuy/aws-nuke:v2.25.0 --config /house/aws-nuke/config.yml --force --no-dry-run

By the best way, have you ever heard about our resolution HyperEnv for GitHub Actions Runner to spin up EC2 cases on-demand for executing GitHub workflow jobs?

Abstract

Be careful for leftover AWS assets after executing Terraform exams. Periodically operating aws-nuke ensures all AWS assets are deleted to keep away from undesirable prices.

Tags: failedTerraformtestsTidying
Previous Post

Intro to IBM Cloud Safety and Compliance

Next Post

So There Received’t Be A Wiz IPO — What Does That Imply For Cyber IPOs In 2025?

Next Post
So There Received’t Be A Wiz IPO — What Does That Imply For Cyber IPOs In 2025?

So There Received’t Be A Wiz IPO — What Does That Imply For Cyber IPOs In 2025?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending

In S3 simplicity is desk stakes

In S3 simplicity is desk stakes

March 20, 2025
When Predictors Collide: Mastering VIF in Multicollinear Regression

When Predictors Collide: Mastering VIF in Multicollinear Regression

April 17, 2025
[Podcast] How To Successfully Goal B2B Patrons in 2024

[Podcast] How To Successfully Goal B2B Patrons in 2024

January 30, 2025
Tips on how to plan a profitable Microsoft 365 (Workplace 365) migration

Tips on how to plan a profitable Microsoft 365 (Workplace 365) migration

January 26, 2025
Speed up the switch of knowledge from an Amazon EBS snapshot to a brand new EBS quantity

Speed up the switch of knowledge from an Amazon EBS snapshot to a brand new EBS quantity

May 11, 2025
The Compelling Case For Naked Metallic Cloud

The Compelling Case For Naked Metallic Cloud

May 12, 2025

MultiCloud365

Welcome to MultiCloud365 — your go-to resource for all things cloud! Our mission is to empower IT professionals, developers, and businesses with the knowledge and tools to navigate the ever-evolving landscape of cloud technology.

Category

  • AI and Machine Learning in the Cloud
  • AWS
  • Azure
  • Case Studies and Industry Insights
  • Cloud Architecture
  • Cloud Networking
  • Cloud Platforms
  • Cloud Security
  • Cloud Trends and Innovations
  • Data Management
  • DevOps and Automation
  • GCP
  • IAC
  • OCI

Recent News

Safe & Environment friendly File Dealing with in Spring Boot: Learn, Write, Compress, and Defend | by Rishi | Mar, 2025

Safe & Environment friendly File Dealing with in Spring Boot: Learn, Write, Compress, and Defend | by Rishi | Mar, 2025

May 15, 2025
Bitwarden vs Dashlane: Evaluating Password Managers

Bitwarden vs Dashlane: Evaluating Password Managers

May 15, 2025
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact

© 2025- https://multicloud365.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Cloud Architecture
    • OCI
    • GCP
    • Azure
    • AWS
    • IAC
    • Cloud Networking
    • Cloud Trends and Innovations
    • Cloud Security
    • Cloud Platforms
  • Data Management
  • DevOps and Automation
    • Tutorials and How-Tos
  • Case Studies and Industry Insights
    • AI and Machine Learning in the Cloud

© 2025- https://multicloud365.com/ - All Rights Reserved