Prompt file imported from staticaland/ai (
.github/prompts/terraform-infrastructure.prompt.md). Fill in{{var_project_name}}before use. Copyright stays with the author.
Terraform Infrastructure
Your goal is to create, modify, or manage Terraform infrastructure following best practices and standards outlined in the .github/terraform.instructions.md file.
Requirements
Ask for infrastructure details if not provided:
- Cloud provider (AWS, Azure, GCP, etc.)
- Resources needed (compute, storage, networking, etc.)
- Environment (dev, staging, prod)
- Region/location preferences
- Specific requirements (high availability, security, compliance)
Implementation Guidelines
File Organization
- Follow standard module structure with logical file groupings
- Use descriptive filenames:
network.tf,compute.tf,security.tf - Separate variables, outputs, and provider configurations
- Include comprehensive documentation
Resource Configuration
- Use consistent naming conventions with underscores
- Implement proper resource tagging and labeling
- Enable deletion protection for stateful resources
- Follow security best practices (encryption, least privilege)
- Use data sources for environment-specific values
Variable Management
- Include units in numeric variable names (
disk_size_gb) - Provide descriptions and validation rules
- Set appropriate default values
- Use positive boolean naming (
enable_monitoring)
Code Quality
- Format with
terraform fmtstandards - Use local values for complex expressions
- Implement proper error handling
- Add meaningful comments for complex logic
Template Structure
# versions.tf
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
# variables.tf
variable "environment" {
description = "Environment name"
type = string
validation {
condition = contains(["dev", "staging", "prod"], var.environment)
error_message = "Environment must be dev, staging, or prod."
}
}
# locals.tf
locals {
common_tags = {
Environment = var.environment
ManagedBy = "terraform"
}
}
# main.tf
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = merge(local.common_tags, {
Name = "{{var_project_name}}-vpc"
})
}
# outputs.tf
output "vpc_id" {
description = "ID of the VPC"
value = aws_vpc.main.id
}
Security Considerations
- Never hardcode sensitive values
- Use external secret management
- Enable encryption at rest and in transit
- Implement network segmentation
- Follow least privilege principles
- Enable audit logging
Files to Generate
-
Core Configuration Files:
versions.tf- Provider versions and constraintsvariables.tf- Input variables with validationmain.tf- Primary resourcesoutputs.tf- Output valueslocals.tf- Local values (if needed)
-
Resource-Specific Files (as needed):
network.tf- VPC, subnets, routingcompute.tf- Instances, auto-scalingsecurity.tf- Security groups, IAMstorage.tf- Databases, storage bucketsdata.tf- Data sources
-
Documentation and Examples:
README.md- Module documentationexamples/- Usage examplesterraform.tfvars.example- Example variables
-
Supporting Files:
.terraform-version- Terraform version.gitignore- Git ignore patternsMakefile- Common commands (optional)
Validation and Testing
Before providing the infrastructure code:
- Validate syntax and logic
- Check for security best practices
- Ensure proper resource dependencies
- Verify naming conventions
- Test with
terraform planwhen possible
Common Patterns
Multi-Environment Setup
# Use workspace or separate directories
# Include environment-specific variable files
# Use consistent naming across environments
Module Composition
# Create reusable modules for common patterns
# Use module composition for complex infrastructure
# Follow single responsibility principle
State Management
# Configure remote backend
# Use state locking
# Implement proper backup strategies
Ensure all generated Terraform code is production-ready, secure, and follows infrastructure as code best practices.