The Single Source of Truth restored: detection of unmanaged resources outside the Terraform state

Research question and methodology

The main question is: How can you define, identify, and analyze resources outside the state in a Terraform-managed AWS environment, and what technical and governance measures structurally mitigate the risks? The study combines a literature review, an analysis of ten existing tools across five categories, and a proof of concept in an AWS sandbox.

Why unmanaged resources pose a risk

A resource outside the state may have improper network access, lack encryption or tagging policies, or incur costs without it being clear who owns it. During an audit, it cannot be demonstrated that it was created through the agreed-upon change management process.

Existing tools only ever address part of the problem. Terraform tools detect discrepancies within the state, but not outside of it. Inventory tools see everything, but without the IaC context. Reverse IaC tools are designed for migration, and CSPM tools lack the IaC perspective. Only gap analysis tools combine both, but Stategraph is expensive and proprietary, and driftctl is outdated.

Research design and techniques

The proof of concept retrieves the Terraform state, inventories AWS resources using Steampipe, and compares both datasets based on unique identifiers such as ARNs and resource IDs. Any resources that exist in AWS but are not in the state are listed as unmanaged resources in a JSON report and in a web interface that displays the discrepancies by resource type. The scan currently covers five resource types: EC2, S3, VPCs, subnets, and IAM users.

The scanner runs as a container on ECS Fargate and starts daily via EventBridge Scheduler or on demand. The results are sent as JSON to CloudWatch Logs, so no separate database is required. A parallel version hit the AWS API rate limits. Because the scan runs periodically, reliability takes precedence over speed, and the scanner operates sequentially.

Results: detection works, governance seals the deal

In the test environment, resources were intentionally created outside of Terraform. The scan detected them, included them in the JSON report, and displayed them by category in the web interface. This demonstrates that an additional monitoring mechanism can do what native Terraform cannot. In Cloud Cost Optimization, such a scan helps identify forgotten or unused resources.

Detection alone does not mitigate the risks. The study therefore links the tool to governance agreements: Terraform as the primary change management channel, restricted IAM permissions for manual changes, mandatory tagging, and an exception process with its own “exclude” tag, including the owner, reason, and expiration date. The tool does not automatically correct anything. A resource outside the state could be an error, but it could also be a deliberate emergency measure. A responsible party decides whether it should be deleted, imported, ignored, or investigated.

Roadmap: more accounts, more resource types, and risk classification

The proof of concept supports multiple state files, but has been tested in a single AWS account. For production, it needs to be expanded to support multiple accounts using cross-account IAM roles, to include resource types such as RDS, Lambda, load balancers, and security groups, and to support Azure and Google Cloud.

A risk classification is also included on the list. An empty test bucket carries less weight than a publicly accessible security group or an IAM user with broad permissions. Integrations with GitLab, Jira, Slack, or Teams can submit findings as tickets to the owner. The study recommends running the scan daily or weekly, and more frequently for production environments.

Download