Secure the Terraform GitHub Copilot writes
In our June 2026 study (one model, measured on engine v0.5.1, not re-run since), the gaps in AI-written AWS config 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.
Our June 2026 study scanned Terraform written by one model (Claude Opus 4.8). It was measured on engine v0.5.1 and has not been re-run on the current engine, so read its numbers on that page, with their date, and not as current figures.
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 June 2026 study found one model 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 — a summary comment on the 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?
Not the files themselves: they are parsed in memory and discarded when the response returns. audytx does keep a record of each finding (rule, message, resource, file and lines) for 90 days, then deletes it. File contents are never part of that record.
How is this different from Checkov or tfsec in the same repo?
Those tools mainly check one resource at a time, so a resource missing an attribute is flagged whether or not other resources make it harmless. audytx also looks at how resources relate and shows the reason when it holds a finding back. For an agent, that means less false-positive churn in the fix loop.
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. The Free plan includes 100 scans a month.