12 Smart Prompts for Terraform and IaC: From Modules to Multi-Cloud
Infrastructure as Code (IaC) is no longer a luxury — it's a necessity for any team managing cloud resources at scale. Terraform, developed by HashiCorp, has become the de facto standard for provisioning infrastructure across AWS, Azure, GCP, and even on-premise environments. But even experienced engineers sometimes struggle with designing reusable modules, managing state files, or orchestrating multi-cloud deployments.
This article provides a curated collection of 12 ready-to-use prompts for Terraform and IaC. Each prompt is designed to solve a specific challenge: building modular infrastructure, handling remote state, implementing multi-cloud strategies, and more. You can copy these prompts directly into your AI assistant or use them as templates for your own automation workflows.
1. Prompt for Designing a Reusable Terraform Module
Task: Create a clean, parameterized Terraform module that follows best practices for input/output variables and versioning.
Prompt:
Generate a Terraform module for deploying an AWS VPC with public and private subnets across multiple availability zones. The module should:
- Accept input variables for vpc_cidr, environment, and az_count
- Use locals to compute subnet CIDRs
- Output the VPC ID, subnet IDs, and NAT gateway IDs
- Include a versions.tf file with required_providers
- Follow HashiCorp's standard module structure (variables.tf, outputs.tf, main.tf, versions.tf)
Why this works: This prompt forces the AI to produce production-ready code with proper separation of concerns. It includes version pinning and output standardization, which are often overlooked by beginners.
Usage example: A DevOps engineer can use this as a starter for any VPC deployment. Just replace the CIDR and region values.
2. Prompt for Migrating State from Local to Remote
Task: Move your Terraform state file from local storage to a remote backend (S3 with DynamoDB locking).
Prompt:
Write a step-by-step migration plan for moving an existing Terraform state from local to an S3 backend with DynamoDB state locking. Include:
1. The backend configuration block for terraform.tf
2. The AWS CLI commands to create the S3 bucket and DynamoDB table
3. The 'terraform init -reconfigure' command
4. How to handle existing resources without destroying them
5. A rollback plan if migration fails
Why this works: State management is critical. This prompt addresses the most common pain point — migrating without losing resources.
Usage example: A team currently using local state can follow this guidance to enable team collaboration via remote state.
3. Prompt for Multi-Cloud Network Peering
Task: Configure network peering between AWS and GCP using Terraform.
Prompt:
Provide Terraform configuration to establish a VPN tunnel between an AWS VPC and a Google Cloud VPC. Requirements:
- Use AWS VPN Gateway and GCP Cloud VPN
- Configure BGP dynamic routing on both sides
- Create firewall rules to allow traffic between subnets (10.0.0.0/16 and 172.16.0.0/16)
- Include variables for project IDs, region, and shared secret
- Output the tunnel IDs and BGP session status
Why this works: Multi-cloud connectivity is complex. This prompt guides the AI to generate a realistic configuration with BGP, which is the standard for hybrid networking.
Usage example: A cloud architect designing a multi-cloud disaster recovery setup can use this to automate the network link.
4. Prompt for Terraform Workspace Management
Task: Manage multiple environments (dev, staging, prod) using Terraform workspaces.
Prompt:
Explain how to use Terraform workspaces for a three-environment deployment (dev, staging, prod). Include:
- workspace-specific variable files (dev.tfvars, staging.tfvars, prod.tfvars)
- A CI/CD pipeline snippet that runs 'terraform workspace select' before apply
- How to handle resources that should only exist in prod (e.g., WAF, DDoS protection)
- A warning about workspace state isolation
Why this works: Workspaces are often misused. This prompt clarifies the correct pattern with variable separation.
Usage example: A platform team can standardize environment management across services.
5. Prompt for AWS EKS Cluster with Terraform
Task: Deploy a production-ready EKS cluster with node groups and IAM roles.
Prompt:
Generate Terraform code to create an AWS EKS cluster with:
- Managed node groups (two instance types for spot/flexibility)
- IRSA (IAM Roles for Service Accounts) enabled
- Cluster autoscaler permissions
- VPC CNI addon with custom networking
- Private endpoint access only
- Output the kubeconfig command and cluster endpoint
Why this works: EKS configuration is notoriously complex. This prompt covers security (private endpoint, IRSA) and scalability (autoscaler).
Usage example: A Kubernetes admin can bootstrap a secure cluster in under 30 minutes.
6. Prompt for Terraform Drift Detection
Task: Automatically detect and report infrastructure drift.
Prompt:
Create a GitHub Actions workflow that runs 'terraform plan' daily and posts drift detection results to a Slack webhook. The workflow should:
- Use OIDC for AWS authentication (no static keys)
- Compare the current state with the remote state file
- Only send a notification if changes are detected
- Include a link to the plan output
Why this works: Drift is a silent killer. This prompt automates the detection loop without manual intervention.
Usage example: A site reliability team can catch unauthorized changes before they cause outages.
7. Prompt for Azure Resource Naming Convention
Task: Enforce a consistent naming convention across Azure resources.
Prompt:
Write a Terraform module that generates Azure resource names following Microsoft's recommended naming conventions. The module should:
- Accept inputs: resource_type, environment, location, instance_number
- Output a standardized name (e.g., rg-dev-eastus-001)
- Validate that names are within Azure's length limits
- Support abbreviations for common resources (rg, vnet, nsg, pip, vm)
Why this works: Naming inconsistencies cause management headaches. This module centralizes the logic.
Usage example: An Azure administrator can enforce naming policies across all teams.
8. Prompt for Multi-Region Disaster Recovery
Task: Deploy infrastructure in two AWS regions with failover capabilities.
Prompt:
Design a Terraform configuration for active-passive disaster recovery across us-east-1 and us-west-2. Include:
- Route53 latency-based routing
- S3 cross-region replication for state files
- DynamoDB global tables for application data
- A failover script that updates Route53 records
- Cost estimation for both regions
Why this works: Disaster recovery requires careful orchestration. This prompt covers DNS, storage, and database replication.
Usage example: A fintech company can meet regulatory requirements for geographic redundancy.
9. Prompt for Terraform Policy as Code with Sentinel
Task: Enforce security policies using HashiCorp Sentinel (or OPA).
Prompt:
Write a Sentinel policy that prevents deploying EC2 instances without encryption and without tags. The policy should:
- Check that every aws_instance resource has 'encrypted = true' on the root block device
- Require mandatory tags: Name, Environment, Owner, CostCenter
- Block any resource that violates these rules
- Provide a clear error message listing which resources failed
Why this works: Policy as code prevents misconfigurations before they reach production.
Usage example: A security team can enforce encryption standards across hundreds of developers.
10. Prompt for GCP Cloud Run with Terraform
Task: Deploy a containerized application on GCP Cloud Run with IAM and custom domain.
Prompt:
Generate Terraform code for deploying a container on GCP Cloud Run with:
- Service account with minimal permissions (only access to Container Registry and Cloud Monitoring)
- Custom domain mapping with SSL certificate
- Traffic splitting (90% to latest revision, 10% to stable)
- Environment variables from Secret Manager
- VPC connector for private network access
Why this works: Cloud Run is serverless but still requires infrastructure setup. This prompt covers security and networking.
Usage example: A startup can deploy a production API without managing Kubernetes.
11. Prompt for Terraform Module Testing with Terratest
Task: Write automated tests for Terraform modules using Terratest (Go).
Prompt:
Create a Terratest test suite for the VPC module from Prompt #1. The tests should:
- Deploy the module in a temporary AWS account
- Assert that the VPC CIDR matches the input
- Check that subnet count equals the number of AZs
- Verify that NAT gateways are created in public subnets
- Destroy resources after tests pass
- Include parallel test execution for speed
Why this works: Testing infrastructure is rare but essential. This prompt provides a battle-tested pattern.
Usage example: A platform team can ensure module changes don't break existing deployments.
12. Prompt for Terraform Cost Estimation with Infracost
Task: Estimate cloud costs before applying Terraform changes.
Prompt:
Integrate Infracost into a Terraform CI/CD pipeline. Provide:
- Installation commands for Infracost CLI
- A GitHub Actions step that runs 'infracost breakdown' on pull requests
- A comment on the PR with the cost diff (before vs after)
- Tag filtering to only run cost estimation on production changes
- A warning if cost increase exceeds $500/month
Why this works: Cost surprises are common. This prompt gives teams visibility before deployment.
Usage example: A FinOps team can review cost impacts during code review.
Summary Table of Prompts
| # | Prompt Topic | Key Benefit |
|---|---|---|
| 1 | Reusable VPC Module | Standardized module structure |
| 2 | State Migration | Safe remote state setup |
| 3 | Multi-Cloud VPN | Hybrid connectivity with BGP |
| 4 | Workspace Management | Environment isolation |
| 5 | EKS Cluster | Production Kubernetes |
| 6 | Drift Detection | Automated compliance |
| 7 | Naming Convention | Consistent resource naming |
| 8 | Disaster Recovery | Multi-region failover |
| 9 | Policy as Code | Security enforcement |
| 10 | Cloud Run | Serverless deployment |
| 11 | Terratest Testing | Module quality assurance |
| 12 | Cost Estimation | Budget control |
Conclusion
Terraform and IaC are powerful, but they require discipline to manage effectively. The 12 prompts above address the most common challenges: module reuse, state safety, multi-cloud networking, security enforcement, and cost control. By using these prompts as templates, you can accelerate your infrastructure automation while following industry best practices.
Remember that the best IaC setup is one that your team can understand and maintain. Start with the prompts that address your most urgent pain point — whether that's migrating state to a remote backend or enforcing tagging policies — and iterate from there.
For teams looking to deepen their Terraform expertise, ASI Biont offers structured learning paths that cover module design, advanced state management, and multi-cloud orchestration. The platform provides hands-on exercises and real-world scenarios to build production-ready skills.
What's your biggest Terraform challenge right now? Try one of these prompts and see how it transforms your workflow.
Comments