Secure the Terraform GitHub Copilot writes
In our corpus study, agent-written AWS config landed on par with hand-written production modules. The gaps that remained were the cross-resource kind: rotation left unconfigured, escalation paths that only appear when you trace the trust graph. This guide wires audytx into Copilot's agent mode so those get caught before the pull request.
Review it while the context is still loaded
The best moment to review agent-written Terraform is while the agent still has the change in its head. Copilot generates the resources, calls audytx, reads the findings, and repairs them before a diff exists. For that to work, the findings have to deserve Copilot's trust — a scanner that cries wolf sends the agent off "hardening" code that was fine. audytx checks every finding against the resource graph first and prints the reason whenever it suppresses one, so what's left is worth fixing.
Numbers from the audytx AI-generated Terraform study.
Two steps
-
Add audytx to
.vscode/mcp.jsonIn VS Code, Copilot agent mode reads MCP servers from
.vscode/mcp.json. Use apromptStringinput so VS Code asks for the Client ID once and stores it as a secret — it never sits in the file:.vscode/mcp.json{ "inputs": [ { "type": "promptString", "id": "audytx-client-id", "description": "audytx Client ID (from audytx.com/dashboard)", "password": true } ], "servers": { "audytx": { "type": "http", "url": "https://audytx.com/mcp", "headers": { "X-Client-ID": "${input:audytx-client-id}" } } } }Get the free Client ID first. On the next agent-mode session, Copilot picks up
scan_terraform,autofix_terraform,scan_cloudformation, and the rest. -
Add repository custom instructions
GitHub Copilot reads
.github/copilot-instructions.md— a repository-wide instruction file that Copilot Chat, agent mode, and Copilot code review all honor. Put the standing scan policy there:.github/copilot-instructions.md## Terraform security Before opening a pull request that changes .tf files, call the audytx scan_terraform tool on the full set of Terraform files in the repository — not only the diff, because cross-resource reasoning needs the unchanged files too. Fix every High and Critical finding and re-scan. Use autofix_terraform for the mechanical ones.
Because
.github/copilot-instructions.mdis also read by Copilot code review on the pull request itself, the same policy reinforces the review even for changes an agent didn't write.
The gaps a single-file review can't see
Here's what tends to surface — the patterns our study found models ship by default:
- Secrets Manager rotation. A secret is created for a database password, but never the companion
aws_secretsmanager_secret_rotation. audytx finds the missing resource across the plan, not merely a missing attribute on one. - IAM privilege-escalation paths.
iam:PassRoleinto a compute service the same principal controls is an escalation even when each statement reads scoped. audytx traces the documented paths across the trust graph. - Operational debt. Dead-letter queues wired but never alarmed, encryption enabled but rotation omitted, loose provider pins. Reliability and observability gaps dominate the count — the quiet ones a resource-by-resource lint doesn't connect.
And the suppressions that stop the agent chasing ghosts — a DLQ not asked to have its own DLQ, a role that reads privileged but can't escalate — each printed with its reasoning, so the call is visible rather than silent.
Same engine on every other surface
The MCP loop is the pre-PR half. For the review, install the GitHub App — one comment per pull request, inline annotations, SARIF to GitHub Code Scanning — so anything the agent misses is caught on the PR alongside Copilot's own code review. Building CloudFormation? The same loop runs with scan_cloudformation, same rule ids and context.
Common questions
Where does the Client ID live so it isn't committed?
The promptString input tells VS Code to prompt for the Client ID once and store it as a secret in your profile — the .vscode/mcp.json in the repo references it as ${input:audytx-client-id} and never contains the value.
Does the repository-instructions file affect Copilot on github.com too?
Yes. .github/copilot-instructions.md is honored by Copilot Chat, agent mode in the editor, and Copilot code review on pull requests. So the same scan policy nudges the review even for human-authored changes — though the audytx GitHub App is what actually posts the findings.
Does audytx store the Terraform Copilot sends it?
No. Files are parsed in memory and discarded when the response returns — the same posture as the GitHub App path. Only aggregate scan metadata is recorded, never file contents.
How is this different from Checkov or tfsec in the same repo?
Those are single-resource pattern matchers — they flag a resource for a missing attribute regardless of whether context makes it benign. audytx pre-computes relationship graphs and suppresses findings context proves harmless, with the rationale shown. For an agent, that precision is a clean fix loop instead of false-positive churn. See the benchmark comparison.
Close the loop in your next Copilot session
Add the .vscode/mcp.json entry and the repository instructions, and let Copilot review its own Terraform — free during the beta.