Error: [rds_db_instance_encryption_at_rest_enabled] RDS instances must have storage encryption enabled.
with aws_db_instance.non_compliant,
on main.tf line 25, in resource "aws_db_instance" "non_compliant":
25: storage_encrypted = false # deny
Fix: Set storage_encrypted = true.
Docs: https://compliance.tf/docs/controls/aws/rds_db_instance_encryption_at_rest_enabled/
This error came from terraform plan, from the compliance.tf provider for AWS in hard_fail mode. In the default mode the same finding is a warning. The resource is a plain aws_db_instance written by hand in a root module, with no module around it. Nothing was created or changed in AWS.
Hand-written resources skip every module control
Compliance.tf modules carry their controls inside the module. When you use soc2.compliance.tf/terraform-aws-modules/s3-bucket/aws, the module itself refuses a bucket that breaks a control. That covers everything that goes through a compliance.tf module.
It does not cover the aws_security_group, aws_db_instance or aws_lb_listener written by hand in a root module. No module control ever sees those resources. A scanner can report them, but each pipeline wires its own scanner, and a finding that shows only in a CI report is easy to merge past.
I saw teams fix Checkov and Trivy findings after the fact, and I wanted the code to be right before terraform plan finished. Modules gave me that for module resources. I built the compliance.tf provider for AWS to give the same check to the resources that no module wraps.
The provider is the one step every run already has
Every Terraform run that touches AWS goes through the AWS provider, on a laptop and in CI. Put the check there, and it runs wherever Terraform runs, with no new pipeline step, for every resource that uses the compliance.tf provider.
registry.compliance.tf/compliancetf/aws runs the official hashicorp/aws unmodified. When Terraform plans a resource, the provider takes the planned values from hashicorp/aws and checks them against the controls for that resource type. It checks again before it forwards the apply, which catches values that were unknown at plan time. On refresh and import it warns about what it reads back. It never changes a value you wrote.
The version numbers are identical to the upstream provider: compliancetf/aws 6.70.0 runs hashicorp/aws 6.70.0, so your resources, arguments and version pin stay the same. A release can change the built-in controls, so read the CHANGELOG before you upgrade.
The built-in baseline has 18 CIS controls on 11 resource types: encryption on RDS, EBS, EFS, ElastiCache and Redshift, public access on RDS, Redshift and S3, backup retention, deletion protection, secure load balancer listeners, and SSH and RDP open to the internet. 15 of them are deny and 3 are warn; the full list is in the reference. Set COMPLIANCETF_DIAGNOSTICS=full to print the CIS references with each finding.
It is free and needs no account or token. The code is on GitHub under MPL-2.0, the same license as hashicorp/aws. Release archives are signed with the compliance.tf release key. At run time the provider downloads hashicorp/aws from releases.hashicorp.com only when no verified copy is cached, checks the HashiCorp signature and the pinned checksum, and, with org_id and COMPLIANCETF_ORG_ID unset, does not contact compliance.tf at run time.
Switching is a source line and one state command per state
terraform {
required_providers {
aws = {
source = "registry.compliance.tf/compliancetf/aws" # was "hashicorp/aws"
version = "6.70.0" # the version you run today
}
}
}
Your provider "aws" block and every resource stay as they are. Before the next step, check each state you will switch. The command below rebinds every hashicorp/aws resource in the state and has no module or resource filter. Run it only on a state where every hashicorp/aws resource should move. Do not run it on a state that also holds resources that stay on hashicorp/aws, such as those of terraform-aws-modules, of an in-house module, or bound to a separate hashicorp/aws provider block; Which modules are checked lists what to do with those first. OpenTofu state usually records registry.opentofu.org/hashicorp/aws; use that address as the first argument when it does. Then rebind the state so that existing resources point at the new address:
terraform init
terraform state pull > "state-$(terraform workspace show).backup.tfstate" \
&& terraform state replace-provider registry.terraform.io/hashicorp/aws registry.compliance.tf/compliancetf/aws
# one backup file per state, with a new name per backend; it holds secrets: keep it private and out of git
terraform init
terraform plan
replace-provider changes only the address recorded in state. Nothing in AWS is created, changed or recreated. Repeat the backup, the check, and the command only where the check passes, in every workspace and every state of the configuration. The Quickstart covers lock file platforms and how to switch back.
Warn first, fail later
The default mode, soft_fail, only warns. You switch a configuration, plan it, and read what the provider says, and nothing breaks.
When a configuration plans with no deny warnings, turn on hard_fail. Every control has an action. In hard_fail, a violated deny control fails the plan, and the apply is never forwarded to hashicorp/aws. A violated warn control, such as deletion protection, still only warns.
The right-hand case matters most for an existing estate. An existing resource that breaks a deny control and has no planned change only warns, even in hard_fail, and any change that leaves the violation in place fails the plan. So you can turn on hard_fail over an old estate, and the old violations stay visible as warnings without failing plans for resources you are not touching. Exceptions are not available, so a resource you cannot fix yet blocks every change to it that does not fix it, a tag edit included. Keep that configuration on soft_fail until it is fixed, and leave COMPLIANCETF_ENFORCEMENT_MODE unset in both its plan and apply jobs, inherited settings included, because a hard_fail there overrides soft_fail in the configuration.
You can set the mode in two places, and the stricter one wins:
# set it in the plan job AND the apply job: each Terraform run reads its own variables
export COMPLIANCETF_ENFORCEMENT_MODE=hard_fail
terraform plan -input=false -out=tfplan
provider "aws" {
region = "us-east-1"
compliance {
enforcement_mode = "hard_fail" # applies on laptops too
}
}
A soft_fail in the configuration cannot lower a hard_fail set by the CI job. That gives a platform team one switch per pipeline. A pull request can still change the provider source line, move a resource into a local module that declares no provider, or edit the CI job that sets the variable, so protect those lines in code review.
Every check also writes a hash-chained record to .terraform/compliancetf/evidence: the control, the resource type and id, the operation, the result and the mode. Nothing is sent to compliance.tf. The chain shows a line edited or removed in the middle of a file, not a file cut short at the end. The files stay on the machine that ran Terraform, so copy them to write-once storage after each CI job if you want to keep them as evidence. The roll-out guide has the CI steps and the caches to keep.
What it does not check
Terraform installs one provider per source address, and each module asks for its own. Every terraform-aws-modules module requires hashicorp/aws, so its resources go to hashicorp/aws and the compliance.tf provider never sees them. The same goes for an in-house module that declares no provider. For terraform-aws-modules, use the compliance.tf modules, which carry their controls inside the module. For in-house modules, add the compliance.tf provider to their required_providers. Which modules are checked has the layouts, including the providers argument that fails.
It also does not do the following:
- There are no exceptions: a
denycontrol cannot be waived for one resource. Leaveorg_id,COMPLIANCETF_ORG_IDandCOMPLIANCETF_TOKENunset. With an organization id alone, the provider warns and applies ahard_failfloor to everydenycontrol (compliant resources still pass); with a token as well, provider configuration fails. - It checks one resource at a time, not how resources fit together.
- It sees a resource only when Terraform plans, applies, refreshes or imports it. Keep AWS Config or your scanner for changes made outside Terraform.
- It does not make you CIS compliant. It checks the controls it has.
Try it and tell me what breaks
Pick one configuration where every hashicorp/aws resource in the state should move: hand-written aws_* resources, and no terraform-aws-modules, in-house modules or separate provider blocks that stay on hashicorp/aws. terraform providers lists the modules that still require hashicorp/aws. Switch it with the Quickstart, plan in soft_fail and see what the provider finds, then try hard_fail in the plan and apply jobs of one pipeline. The Quickstart also shows how to switch back.
I want to hear the feedback (good and bad): a control that fires where it should not, a message that does not tell you what to fix, a resource type you expected to see covered, or a pipeline where the switch did not go as the docs say. Bugs and feature requests go to GitHub issues. For anything else, use the contact form.
