Skip to content

Commit eb4110a

Browse files
committed
feat(aws_s3_prompt): add s3
1 parent c3b3884 commit eb4110a

1 file changed

Lines changed: 130 additions & 3 deletions

File tree

  • app/template_generators/terraform/aws
Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,133 @@
11
def IaC_template_generator_s3(input) -> str:
22

3-
3+
s3 = ['aws_s3_bucket', 'aws_s3_bucket_versioning']
44

5-
prompt = f""" """
6-
return prompt
5+
aws_s3_create_bucket = 'true' if input.s3_bucket else 'false'
6+
aws_s3_create_bucket_versioning = 'true' if input.bucket_versioning else 'false'
7+
8+
prompt = f"""
9+
Generate a Python code to generate a Terraform project (project name is app/media/MyTerraform)
10+
that dynamically provisions {s3} resources ensuring a modular, flexible structure to enable users
11+
to configure all essential settings at the root level. Only provide Python code, no explanations or
12+
markdown formatting. The project should be organized as follows:
13+
1. Root Directory Structure:
14+
- main.tf:
15+
- Define the provider block as follows:
16+
```
17+
provider "aws" {{
18+
host = "us-east-1"
19+
}}
20+
```
21+
- Defines a module block that references "s3" from a subdirectory within modules.
22+
This module block should expose all variables that {s3} resources require, allowing
23+
configuration at the root level rather than directly within the module.
24+
- Every variable defined in {s3} resources should be passed through the module block,
25+
ensuring that users can adjust all critical parameters of {s3} resources by modifying
26+
root main.tf. Avoid using any other parameters. just use the parameters of {s3} resources with the same keys
27+
- variables.tf:
28+
- Sets these variables names for aws_s3_bucket resource:
29+
s3_create_bucket(bool), s3_bucket_name(string), s3_bucket_force_destroy(bool), s3_bucket_tags(map(string))
30+
- Sets these variables names for aws_s3_bucket_versioning resource:
31+
s3_create_bucket_versioning(bool), s3_bucket_versioning_status(string)
32+
- terraform.tfvars:
33+
- Structure as follows:
34+
s3_create_bucket = {aws_s3_create_bucket}
35+
s3_bucket_name = "UniqueName"
36+
s3_bucket_force_destroy = false
37+
s3_bucket_tags = {{
38+
Name = "My bucket"
39+
Environment = "Dev"
40+
}}
41+
s3_create_bucket_versioning = {aws_s3_create_bucket_versioning}
42+
s3_bucket_versioning_status = "Enabled"
43+
- versions.tf:
44+
- Structure as follows:
45+
terraform {{
46+
required_version = ">= 1.0"
47+
48+
required_providers {{
49+
aws = {{
50+
source = "hashicorp/aws"
51+
version = ">= 5.20"
52+
}}
53+
}}
54+
}}
55+
2. Module Directory Structure (modules/s3):
56+
- main.tf:
57+
- Set the following parameters for aws_s3_bucket resource (name its terraform resource to "s3_bucket")and avoid using any other parameters:
58+
- 1. count (type: number): follow the below syntax for count:
59+
```
60+
count = var.s3_create_bucket ? 1 : 0
61+
```
62+
- 2. bucket (type: string): Specifies the bucket name.
63+
- 3. force_destroy (type: boolean): Indicates all objects should be deleted from the bucket when the bucket is destroyed
64+
- 4. tags (map(string) type): Includes the following fields:
65+
- Name (type: string): A tag for the bucket.
66+
- Environment (type: string): A tag for the bucket
67+
- Set the following parameters for aws_s3_bucket_versioning resource (name its terraform resource to "s3_bucket_versioning")and avoid using any other parameters:
68+
- 1. count (type: number): follow the below syntax for count:
69+
```
70+
count = var.s3_create_bucket && var.s3_create_bucket_versioning ? 1 : 0
71+
```
72+
- 2. bucket: it must points to the s3_bucket resource like the following syntax:
73+
```
74+
bucket = aws_s3_bucket.s3_bucket[0].id
75+
```
76+
- 3. versioning_configuration: this is a block which has a key/value pair as follows:
77+
```
78+
versioning_configuration {{
79+
status = var.s3_bucket_versioning_status
80+
}}
81+
```
82+
- variables.tf:
83+
- Sets these variables names for aws_s3_bucket resource:
84+
s3_create_bucket(bool), s3_bucket_name(string), s3_bucket_force_destroy(bool), s3_bucket_tags(map(string))
85+
- Sets these variables names for aws_s3_bucket_versioning resource:
86+
s3_create_bucket_versioning(bool), s3_bucket_versioning_status(string)
87+
- terraform.tfvars:
88+
- Structure as follows:
89+
s3_create_bucket = {aws_s3_create_bucket}
90+
s3_bucket_name = "UniqueName"
91+
s3_bucket_force_destroy = false
92+
s3_bucket_tags = {{
93+
Name = "My bucket"
94+
Environment = "Dev"
95+
}}
96+
s3_create_bucket_versioning = {aws_s3_create_bucket_versioning}
97+
s3_bucket_versioning_status = "Enabled"
98+
- versions.tf:
99+
- Structure as follows:
100+
terraform {{
101+
required_version = ">= 1.0"
102+
103+
required_providers {{
104+
aws = {{
105+
source = "hashicorp/aws"
106+
version = ">= 5.20"
107+
}}
108+
}}
109+
}}
110+
Ensure this project structure supports {s3}’s configurability, extensibility, and
111+
reusability across diverse Terraform providers, empowering users to manage their resources through a
112+
single, customizable root configuration while keeping module internals robustly modular.
113+
114+
finally just give me a python code without any note that can generate a project folder with the given
115+
schema without ```python entry. and we dont need any base directory in the python code. the final
116+
terraform template must work very well without any error!
117+
118+
Python code you give me, must have structure like that:
119+
120+
import os
121+
project_name = "app/media/MyTerraform"
122+
modules_dir = os.path.join(project_name, "modules")
123+
s3_dir = os.path.join(modules_dir, "s3")
124+
125+
# Create project directories
126+
os.makedirs(s3_dir, exist_ok=True)
127+
128+
# Create main.tf
129+
with open(os.path.join(project_name, "main.tf"), "w") as main_file:
130+
# any thing you need
131+
132+
"""
133+
return prompt

0 commit comments

Comments
 (0)