Home › IT ops & DevOps › Infrastructure-as-code changes: how to do it with AI

Infrastructure-as-code changes: how to do it with AI

Last checked

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.

Best pick

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

  1. Work on a branch in a repo with CI that runs terraform plan or a dry run.
  2. Give the agent access to that repo only, never cloud credentials.
  3. Describe the change and the files involved, and ask for a plan before edits.
  4. Let it make the edit and open a pull request.
  5. Read the diff and the plan output: look for anything marked destroy or replace.
  6. 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

Plan first
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
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 a diff
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

Which tool to pick, and why

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

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

Related tasks

Report an error on this page