AI generated prompt for Terraform Infrastructure as Code
**Context**:
Terraform is an infrastructure as code (IaC) tool that allows users to define and manage cloud and on-premises resources using human-readable configuration files. The goal is to create a scalable, secure, and efficient infrastructure for a web application using Terraform.
**Detailed Instructions**:
Design a Terraform configuration to deploy a web application on Amazon Web Services (AWS). The infrastructure should include:
1. A Virtual Private Cloud (VPC) with a public subnet and a private subnet.
2. An Application Load Balancer (ALB) to distribute traffic to the web servers.
3. An Auto Scaling group with two EC2 instances running a Linux operating system and a Docker container with the web application.
4. A Relational Database Service (RDS) instance for data storage.
5. Security groups to control inbound and outbound traffic.
6. A key pair for secure access to the EC2 instances.
The configuration should be modular, reusable, and follow best practices for security and cost optimization. Use Terraform 1.3 or later and AWS provider version 4.0 or later.
**Output Format**:
The output should be a Terraform configuration file (`.tf` file) that includes all the necessary resources and modules to deploy the infrastructure. The file should be well-structured, readable, and include comments to explain each section.
**Examples**:
For reference, the following Terraform configuration snippet demonstrates how to create an EC2 instance:
```terraform
resource "aws_instance" "example" {
ami = "ami-abc123"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.example.id]
key_name = "example-key"
}
```
Similarly, the following snippet shows how to create an RDS instance:
```terraform
resource "aws_db_instance" "example" {
allocated_storage = 20
engine = "postgres"
engine_version = "13.4"
instance_class = "db.t2.micro"
name = "exampledb"
username = "exampleuser"
password = "examplepassword"
vpc_security_group_ids = [aws_security_group.example.id]
}
```
These examples illustrate the structure and syntax of Terraform configuration files, but the actual output should include all the required resources and modules to deploy the entire infrastructure.This coding prompt is designed to help you get better results from AI assistants like ChatGPT, Claude, and Gemini. Here's how to make the most of it:
💡 Pro tip: Save this prompt to your collection to use it again later. Well-crafted prompts can save hours of back-and-forth with AI.
Adjust the prompt to match your specific industry, audience, or use case. Adding relevant context improves output quality.
Specify your desired output length (e.g., "in 200 words" or "in 3 bullet points") to get more targeted responses.
Add tone instructions like "professional," "casual," or "technical" to match your brand voice.
Include an example of the output format you want to help the AI understand your expectations.
This prompt has been tested and optimized for all major AI models. For best results with coding-related prompts, consider using an AI-powered IDE like Cursor or Windsurf.
Learn more about using prompts effectively with our comprehensive guides:
0 people found this prompt helpful
Based on 0 reviews
Be the first to share your experience with this prompt!
This prompt was reviewed and verified to work with current AI models.
Tested with ChatGPT, Claude & Gemini. Reviewed by community users.
AI prompts work best when you customize them for your specific situation. Follow these steps to get the most out of Terraform Infrastructure As Code.