Skip to content

Commit 2a365ee

Browse files
authored
Merge pull request #85 from mohammadll/terraform
feat(argocd_prompt): add argocd resources
2 parents e12629c + 2957145 commit 2a365ee

1 file changed

Lines changed: 205 additions & 1 deletion

File tree

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,206 @@
11
def IaC_template_generator_argocd(input) -> str:
2-
pass
2+
3+
argocd = ['argocd_repository', 'argocd_application']
4+
5+
argocd_create_repository = 'true' if input.argocd_repository else 'false'
6+
if input.argocd_application != None:
7+
argocd_create_application = 'true'
8+
argocd_application_auto_prune = 'true' if input.argocd_application.sync_policy.auto_prune else 'false'
9+
argocd_application_selfheal = 'true' if input.argocd_application.sync_policy.self_heal else 'false'
10+
else:
11+
argocd_create_application = 'false'
12+
argocd_application_auto_prune = ""
13+
argocd_application_selfheal = ""
14+
15+
prompt = f"""
16+
Generate a Python code to generate a Terraform project (project name is app/media/MyTerraform)
17+
that dynamically provisions {argocd} resources ensuring a modular, flexible structure to enable users
18+
to configure all essential settings at the root level. Only provide Python code, no explanations or
19+
markdown formatting. The project should be organized as follows:
20+
1. Root Directory Structure:
21+
- main.tf:
22+
- Define the provider block as follows:
23+
```
24+
provider "argocd" {{
25+
server_addr = var.argocd_instance_info["server_addr"]
26+
username = var.argocd_instance_info["username"]
27+
password = var.argocd_instance_info["password"]
28+
insecure = var.argocd_instance_info["insecure "]
29+
}}
30+
```
31+
- Defines a module block that references "argocd" from a subdirectory within modules.
32+
This module block should expose all variables that {argocd} resources require, allowing
33+
configuration at the root level rather than directly within the module.
34+
- Every variable defined in {argocd} resources should be passed through the module block,
35+
ensuring that users can adjust all critical parameters of {argocd} resources by modifying
36+
root main.tf. Avoid using any other parameters. just use the parameters of {argocd} resources with the same keys
37+
- variables.tf:
38+
- Sets this variable name for argocd provider:
39+
argocd_instance_info(object()) as follows:
40+
```
41+
type = object({{
42+
server_addr = string
43+
username = string
44+
password = string
45+
insecure = bool
46+
}})
47+
```
48+
- Sets these variables names for argocd_repository resource:
49+
repository_create(bool), argocd_repository_info(map(string))
50+
- Sets these variables names for argocd_application resource:
51+
application_create(bool), argocd_application(map(string)), argocd_sync_options(list(string))
52+
- terraform.tfvars:
53+
- Structure as follows:
54+
argocd_instance_info = {{
55+
server_addr = "ARGOCD_DOMAIN"
56+
username = "admin"
57+
password = "ARGOCD_ADMIN_PASS"
58+
insecure = true
59+
}}
60+
61+
repository_create = {argocd_create_repository}
62+
argocd_repository_info = {{
63+
repo = "https://YOUR_REPO.git"
64+
username = "USERNAME"
65+
password = "CHANGE_ME_WITH_TOKEN"
66+
}}
67+
68+
application_create = {argocd_create_application}
69+
argocd_application = {{
70+
name = "APPLICATION_NAME"
71+
destination_server = "https://kubernetes.default.svc"
72+
destination_namespace = "DESTINATION_NAMESPACE"
73+
source_repo_url = "https://YOUR_REPO.git"
74+
source_path = "SOURCE_PATH"
75+
source_target_revision = "SOURCE_TARGET_REVISION"
76+
}}
77+
78+
argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"]
79+
- versions.tf:
80+
- Structure as follows:
81+
terraform {{
82+
required_version = ">= 1.0"
83+
84+
required_providers {{
85+
argocd = {{
86+
source = "oboukili/argocd"
87+
version = ">= 6.0.2"
88+
}}
89+
}}
90+
}}
91+
2. Module Directory Structure (modules/argocd):
92+
- main.tf:
93+
- Set the following parameters for argocd_repository resource (name its terraform resource to "repository") and avoid using any other parameters:
94+
- 1. count (type: number): follow the below syntax for count:
95+
```
96+
count = var.repository_create ? 1 : 0
97+
```
98+
- 2. repo (type: string): follow the below syntax for repo parameter:
99+
```
100+
repo = var.argocd_repository_info["repo"]
101+
```
102+
- 3. username (type: string): follow the below syntax for username parameter:
103+
```
104+
username = var.argocd_repository_info["username"]
105+
```
106+
- 4. password (type: string): follow the below syntax for password parameter:
107+
```
108+
password = var.argocd_repository_info["password"]
109+
```
110+
- Set the following parameters for argocd_application resource (name its terraform resource to "application") and avoid using any other parameters:
111+
- 1. count (type: number): follow the below syntax for count:
112+
```
113+
count = var.application_create ? 1 : 0
114+
```
115+
- 2. metadata (A block): Define a metadata block as follows:
116+
```
117+
metadata {{
118+
name = var.argocd_application["name"]
119+
namespace = argocd
120+
labels = {{
121+
using_sync_policy_options = "true"
122+
}}
123+
}}
124+
```
125+
- 3. spec (A block): Define a spec block as follows:
126+
```
127+
spec {{
128+
destination {{
129+
server = var.argocd_application["destination_server"]
130+
namespace = var.argocd_application["destination_namespace"]
131+
}}
132+
source {{
133+
repo_url = var.argocd_application["source_repo_url"]
134+
path = var.argocd_application["source_path"]
135+
target_revision = var.argocd_application["source_target_revision"]
136+
}}
137+
sync_policy {{
138+
automated {{
139+
prune = {argocd_application_auto_prune}
140+
self_heal = {argocd_application_selfheal}
141+
}}
142+
sync_options = var.argocd_sync_options
143+
}}
144+
}}
145+
```
146+
- variables.tf:
147+
- Sets these variables names for argocd_repository resource:
148+
repository_create(bool), argocd_repository_info(map(string))
149+
- Sets these variables names for argocd_application resource:
150+
application_create(bool), argocd_application(map(string)), argocd_sync_options(list(string))
151+
- terraform.tfvars:
152+
- Structure as follows:
153+
repository_create = {argocd_create_repository}
154+
argocd_repository_info = {{
155+
repo = "https://YOUR_REPO.git"
156+
username = "USERNAME"
157+
password = "CHANGE_ME_WITH_TOKEN"
158+
}}
159+
160+
application_create = {argocd_create_application}
161+
argocd_application = {{
162+
name = "APPLICATION_NAME"
163+
destination_server = "https://kubernetes.default.svc"
164+
destination_namespace = "DESTINATION_NAMESPACE"
165+
source_repo_url = "https://YOUR_REPO.git"
166+
source_path = "SOURCE_PATH"
167+
source_target_revision = "SOURCE_TARGET_REVISION"
168+
}}
169+
170+
argocd_sync_options = ["CreateNamespace=true", "ApplyOutOfSyncOnly=true", "FailOnSharedResource=true"]
171+
- versions.tf:
172+
- Structure as follows:
173+
terraform {{
174+
required_version = ">= 1.0"
175+
176+
required_providers {{
177+
argocd = {{
178+
source = "oboukili/argocd"
179+
version = ">= 6.0.2"
180+
}}
181+
}}
182+
}}
183+
Ensure this project structure supports {argocd}’s configurability, extensibility, and
184+
reusability across diverse Terraform providers, empowering users to manage their resources through a
185+
single, customizable root configuration while keeping module internals robustly modular.
186+
187+
finally just give me a python code without any note that can generate a project folder with the given
188+
schema without ```python entry. and we dont need any base directory in the python code. the final
189+
terraform template must work very well without any error!
190+
191+
Python code you give me, must have structure like that:
192+
193+
import os
194+
project_name = "app/media/MyTerraform"
195+
modules_dir = os.path.join(project_name, "modules")
196+
argocd_dir = os.path.join(modules_dir, "argocd")
197+
198+
# Create project directories
199+
os.makedirs(argocd_dir, exist_ok=True)
200+
201+
# Create main.tf
202+
with open(os.path.join(project_name, "main.tf"), "w") as main_file:
203+
# any thing you need
204+
205+
"""
206+
return prompt

0 commit comments

Comments
 (0)