Gemini Prompts for Terraform Configs: 5 Ready-to-Use Ideas

It is Thursday, a new environment has to exist by Monday, and your Terraform still lives in one main file that nobody wants to open. You know roughly what the config should look like. What you need is a second pair of hands to draft it, name it, and catch the parts that break on the second apply. That is what these five Gemini prompts for Terraform configs do, one job at a time.

Before you start: the variables

[Variable] What to put in
[cloud provider] The provider you deploy to, plus its version if it is pinned.
[resource list] The resources you need, one per line, in plain words.
[environment] Which environment this config targets, such as staging or production.
[state backend] Where remote state lives and how it is locked.
[naming convention] Your prefix and separator rules for resource and variable names.
[team size] How many people run apply on this stack.

The prompts

1. Turn a resource list into a config skeleton

I need Terraform for [resource list] on [cloud provider]. Draft a skeleton config with one resource block per item, mark every value that needs a human decision as TODO, and add a one-line comment above each block explaining what the resource does. Do not invent values for anything that should be decided by a person.

What it does: Gives you the shape of the config with the open questions visible instead of buried.

How to use: Replace [resource list] and [cloud provider]; work through the TODOs before you run plan.

2. Pin the state before anything else

About [team size] people run Terraform on this stack. Write the backend configuration for [state backend], including the locking setup that goes with it. Add comments explaining what happens when two people apply at the same time, and list the commands someone runs before their first plan.

What it does: Settles the part of Terraform that is painful to change later.

How to use: Replace [team size] and [state backend]; keep the command list next to the repo readme.

3. Review a config for plan-time surprises

Review this config for changes that would appear as a destroy and recreate on the next apply: [paste config]. Sort the findings into forced replacement, in-place update, and no change. For each forced replacement, say what to adjust so the resource is updated in place instead.

What it does: Surfaces the resource replacements that turn a small edit into an outage.

How to use: Replace [paste config] with the blocks you are about to change; verify each claim with a plan.

4. Split one file into environments

Here is a single-environment config: [paste config]. Split it into shared modules and per-environment values for [environment] deployments. Show the directory tree, list the inputs each module takes, and say where each environment's values live. Keep resource addresses stable so nothing is recreated by the move.

What it does: Produces a layout you can grow without copying the file three times.

How to use: Replace the config and [environment]; add only the environments you actually run.

5. Write variables with real validation

Write variable definitions for [resource list] on [cloud provider], following this convention: [naming convention]. For each variable, include a description, a type, and a validation rule that rejects obvious mistakes. Flag any variable that should carry a default instead of being required.

What it does: Catches bad input at plan time rather than halfway through an apply.

How to use: Replace the three variables; paste the convention exactly as your team writes it.

A quick worked example

Take prompt five. You have a bucket, a queue, and a function to deploy, on one provider, and your convention is a lowercase prefix with hyphens. Filled in, the request asks for three variable definitions with descriptions, types, and a rule that rejects a name containing an underscore. Gemini returns a block per variable, one of them marked as a candidate for a default because the queue timeout is the same everywhere. You copy the blocks into the variables file, delete the default you do not want, and run plan.

Keep going

These prompts are free to use. Copy them, tweak the [variables], ship something.

Leave a Comment