Fix the compliance audit of an RDS database
Your task
An assistant's Terraform for a customer database left encryption off, put the password in the file and made the database public. Compliance review is in 2 days, so the team now audits every aws_db_instance from its attributes.
An assistant wrote audit_db_instance(attributes). It is in the editor. It has a bug. Find it and fix it.
Input and output:
attributes: the resource's settings, one string per line, each meant to bekey=value. The list can be empty.- Return the findings as a list of strings, sorted in ascending order. Each finding appears at most once. No findings returns an empty list.
Rules the tests check:
- Split each line at its first
=, so a value can hold more=signs. Ignore a line with no=. Keys are case sensitive, and unknown keys are ignored. When a key repeats, the last line wins. - A setting is true only when its value is exactly
true.True,yesand an empty value are not true. "encryption_at_rest_off":storage_encryptedis not true. A missingstorage_encryptedcounts, because AWS leaves storage unencrypted by default."hardcoded_password":passwordis present, not empty, and does not start with one ofvar.,local.,data.orrandom_password.. Those prefixes mean the value is a reference to a secret kept elsewhere. Anything else is a literal password that lands in the state file and the repo. The prefix check is case sensitive."public_endpoint":publicly_accessibleis true."no_final_snapshot":skip_final_snapshotis true."deletion_protection_off":deletion_protectionis not true. A missingdeletion_protectioncounts.
Examples
audit_db_instance(attributes: list[str]) -> list[str]Example 1
Input
audit_db_instance(["identifier=prod-customers", "engine=postgres", "username=admin", "password=ChangeMe123!", "publicly_accessible=true", "skip_final_snapshot=true"])Output
["deletion_protection_off", "encryption_at_rest_off", "hardcoded_password", "no_final_snapshot", "public_endpoint"]Example 2
Input
audit_db_instance(["storage_encrypted=true", "password=var.db_password", "publicly_accessible=false", "skip_final_snapshot=false", "deletion_protection=true"])Output
[]Example 3
Input
audit_db_instance([])Output
["deletion_protection_off", "encryption_at_rest_off"]