Skip to content

Backend audit checks ​

tfcensus audit backend runs 25 checks on the state buckets, lock tables and states its units use. Every finding carries the check ID as its rule, a severity and a reason. --fail-on takes the lowest severity that fails the run. Keys under audit.policy set the thresholds, and audit.suppress hides findings with a reason and an optional expires date (configuration).

State buckets ​

Run once per state bucket.

CheckSeverityPasses whenFixSet by
S3-VERhighState bucket versioning is enabledEnable versioning, so an overwritten or deleted state can be restored.
S3-MFAlowState bucket has MFA deleteInformational: MFA delete needs the root user's MFA device and is rarely practical.
S3-ENCmediumState bucket encrypts with a customer-managed KMS keySet default encryption to SSE-KMS with a customer-managed key, so key policy controls who can decrypt state.
S3-KMSPOLhighState key policy doesn't let every principal decryptRemove kms:Decrypt for Principal "*", or restrict it with aws:PrincipalAccount or aws:PrincipalOrgID.
S3-PABhighBucket and account public access block are all onTurn on all four public access block settings on the bucket and the account.
S3-TLShighState bucket policy denies requests without TLSAdd a Deny for Principal "*", Action s3:*, the bucket and bucket/* resources, with Bool aws:SecureTransport false as the only condition.
S3-OWNmediumObject ownership is BucketOwnerEnforcedSet object ownership to BucketOwnerEnforced, which turns ACLs off.
S3-REPLmediumState is replicated to another regionConfigure cross-region replication to a versioned, KMS-encrypted bucket.
S3-LCmediumNoncurrent state versions expire after a bounded timeAdd a lifecycle rule with NoncurrentVersionExpiration of at least the policy's noncurrent_days.audit.policy.noncurrent_days
S3-LOGlowState access is loggedTurn on server access logging or CloudTrail S3 data events for the bucket.
S3-LEGACYlowNo legacy RootAccess statementRemove the RootAccess statement that terragrunt before 1.2 added; the account root has access through IAM.

Locks ​

Run once per unit backend and lock table.

CheckSeverityPasses whenFixSet by
LK-MODElowUnit locks with S3 lock filesSet use_lockfile = true: dynamodb_table is deprecated since Terraform 1.11. Keep both during the migration.
LK-BOTHinfoUnit uses one lock mechanismBoth lock files and DynamoDB are configured, which is fine while migrating. Remove dynamodb_table afterwards.
LK-PITRmediumLock table has point-in-time recovery and KMS encryptionTurn on point-in-time recovery and encrypt the table with a KMS key.
LK-STALEhighNo stale locksCheck that no run holds the lock, then release it with terraform force-unlock.audit.policy.stale_lock_hours
LK-MD5lowNo orphaned digest itemsDelete the -md5 item: its state object no longer exists.

Fleet and states ​

Run over the states and the units that point at them.

CheckSeverityPasses whenFixSet by
FL-ORPHANmediumEvery state key belongs to a unitDelete or archive the state, or add the unit that owns it to the scanned repos.
FL-ABSENTlowEvery unit's state existsApply the unit, or fix its backend key.
FL-EMPTYlowState manages resourcesDestroy the unit's code and state, or check that the key is right.
FL-LINEAGEhighEach lineage lives under one keyOne of the states is a copy. Keep the one the unit applies to and archive the other.
FL-DOUBLEhighEach resource is managed by one stateRemove the resource from all but one state with terraform state rm, or a removed block.
FL-TFVERmediumState was written by a supported versionUpgrade the unit's terraform or tofu to at least the policy's min_terraform_version.audit.policy.min_terraform_version
FL-PROVlowProvider versions meet the policyUpgrade the provider in .terraform.lock.hcl with terraform init -upgrade.audit.policy.min_provider_versions
FL-SIZElowState is small enough for fast plansSplit the unit.audit.policy.max_state_mb
FL-SECRETinfoNo secrets stored in plain stateUse write-only arguments or ephemeral resources, or keep the secret in a secrets manager.

Suppress a finding ​

yaml
audit:
  suppress:
    - check: S3-MFA
      reason: MFA delete needs the root user's device
    - check: LK-*
      bucket: acme-legacy-tfstate
      reason: the legacy fleet moves to lock files in Q1
      expires: "2027-03-31"