Home › IT ops & DevOps › Infrastructure-as-code changes: how to do it with AI
Infrastructure-as-code changes: how to do it with AI
From official vendor pages; selected tasks also include dated logged-out free-plan trials. Report an error.
Advanced Risk: High 🛠️ IT ops & DevOps
A coding agent can edit Terraform, Bicep or Kubernetes YAML for you, explain the change and open a pull request. It's useful for repetitive edits across many files, as long as a human reviews the plan before anything is applied.
Who it’s for: DevOps and platform engineers, and developers who maintain their team's infrastructure code.
Why high risk: A wrong change can delete resources, open network access or cause downtime when applied.
ChatGPT has the highest score on our published rubric (94/100) of the 4 tools listed for this task. Codex supports cloud coding tasks and PR review.
Step by step
- Work on a branch in a repo with CI that runs terraform plan or a dry run.
- Give the agent access to that repo only, never cloud credentials.
- Describe the change and the files involved, and ask for a plan before edits.
- Let it make the edit and open a pull request.
- Read the diff and the plan output: look for anything marked destroy or replace.
- Apply only through your normal pipeline after a second person approves.
AI prompts to make infrastructure-as-code changes
Replace the [brackets] with your details. See all prompt examples
In this repo, I want to [change, e.g. add a staging copy of the web app with smaller instance sizes]. Before editing, list the files you'll change and why. Don't run apply or any command that changes real infrastructure.
Make the change on a new branch, run terraform fmt and validate, and open a pull request. In the description, list every resource that will be created, changed or destroyed.
Review this infrastructure diff. Flag anything that destroys or replaces a resource, widens network or IAM access, or hard-codes a secret. [paste diff]
Illustrative example
You paste
Change: increase the web service replicas from 2 to 4 in k8s/web/deployment.yaml and add a 512Mi memory limit.
A good answer looks like
Edited k8s/web/deployment.yaml: replicas: 2 -> 4 resources.limits.memory: 512Mi (new) Nothing deleted. Opened PR #42 "web: 4 replicas, memory limit". Check before merging: is 512Mi above current peak memory use? Confirm in monitoring.
Illustrative example written for this guide, not output captured from a specific tool.
Safe practice
- Point the agent at a branch and a non-production environment; production changes go through your normal pipeline.
- Give the agent repo access only, never cloud admin credentials, state files or tenant secrets.
- Read every line in the plan marked destroy or replace before approving.
- Require a second human reviewer for anything that changes networking, IAM or data stores.
Which tool to pick, and why
- Cursor: Agent edits code and runs terminal commands; Cloud Agents run in isolated VMs and open PRs, away from your laptop's credentials. Free plan can do this Visit official website ↗
- GitHub Copilot: The cloud agent works in GitHub Actions on issues, branches and pull requests, so changes land as reviewable PRs. Free plan can do this Visit official website ↗
- Claude (incl. Claude Code): Claude Code runs in your terminal with permission prompts and integrates with GitHub Actions and GitLab CI. Visit official website ↗
- ChatGPT (incl. Work & Codex): Codex supports cloud coding tasks and PR review. Free plan can do this Visit official website ↗
Reasons come from the capabilities, free-plan details and prices we've checked on official pages (separate from any dated trial above). Sources: cursor.com/pricing · github.com/features/copilot/plans · claude.com/pricing · chatgpt.com/pricing
Common mistakes
- Giving the agent cloud admin credentials.
- Merging without reading the plan for destroy or replace.
- Letting the agent run apply.
- Large multi-purpose PRs that are hard to review.
Privacy tip
Keep cloud credentials and state files out of the agent's reach, and use secret references instead of values in code. In Cursor, turn on Privacy Mode; on Copilot individual plans, opt out of training at github.com/settings/copilot/features.
Cursor setting · GitHub Copilot setting · Claude (incl. Claude Code) setting · Sources: cursor.com/help/security-and-privacy/privacy · github.com/features/copilot/plans · privacy.claude.com/en/articles/12109829-how-do-i-change-my-model-improvement-privacy-settings