diff --git a/.gitignore b/.gitignore index f7fc7757..ba347277 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ venv data .pytest* +.env \ No newline at end of file diff --git a/app/__pycache__/main.cpython-311.pyc b/app/__pycache__/main.cpython-311.pyc index 8e47085e..468cef20 100644 Binary files a/app/__pycache__/main.cpython-311.pyc and b/app/__pycache__/main.cpython-311.pyc differ diff --git a/app/__pycache__/prompt_generators.cpython-311.pyc b/app/__pycache__/prompt_generators.cpython-311.pyc index fff2eb82..63a54764 100644 Binary files a/app/__pycache__/prompt_generators.cpython-311.pyc and b/app/__pycache__/prompt_generators.cpython-311.pyc differ diff --git a/app/directory_generators/terraform_generator.py b/app/directory_generators/terraform_generator.py index 1bc1ba99..1009a660 100644 --- a/app/directory_generators/terraform_generator.py +++ b/app/directory_generators/terraform_generator.py @@ -1,39 +1,44 @@ import os project_name = "app/media/MyTerraform" modules_dir = os.path.join(project_name, "modules") -docker_dir = os.path.join(modules_dir, "docker") +docker_container_dir = os.path.join(modules_dir, "docker_container") # Create project directories -os.makedirs(docker_dir, exist_ok=True) +os.makedirs(docker_container_dir, exist_ok=True) -# Create main.tf at root +# Create main.tf with open(os.path.join(project_name, "main.tf"), "w") as main_file: - main_file.write('''provider "docker" { + main_file.write(''' +provider "docker" { host = var.docker_host } -module "docker" { - source = "./modules/docker" - image = var.image - name = var.container_name - ports = var.ports +module "docker_container" { + source = "./modules/docker_container" + + image = var.image + name = var.name + ports = var.ports + env = var.env } + ''') -# Create variables.tf at root -with open(os.path.join(project_name, "variables.tf"), "w") as variables_file: - variables_file.write('''variable "docker_host" { - description = "The Docker host Uri." +# Create variables.tf +with open(os.path.join(project_name, "variables.tf"), "w") as vars_file: + vars_file.write(''' +variable "docker_host" { + description = "Docker host URL." type = string } variable "image" { - description = "The Docker image to use." + description = "Docker image to use." type = string } -variable "container_name" { - description = "The name of the Docker container." +variable "name" { + description = "Name of the container." type = string } @@ -41,103 +46,126 @@ description = "List of ports to expose." type = list(string) } + +variable "env" { + description = "Environment variables for the container." + type = map(string) +} ''') -# Create terraform.tfvars at root +# Create terraform.tfvars with open(os.path.join(project_name, "terraform.tfvars"), "w") as tfvars_file: - tfvars_file.write('''docker_host = "tcp://localhost:2375" -image = "nginx:latest" -container_name = "my_nginx" + tfvars_file.write(''' +docker_host = "tcp://localhost:2375" +image = "nginx:latest" +name = "my-nginx-container" ports = ["80:80"] +env = { "MY_ENV_VAR" = "value" } ''') -# Create versions.tf at root +# Create versions.tf with open(os.path.join(project_name, "versions.tf"), "w") as versions_file: - versions_file.write('''terraform { + versions_file.write(''' +terraform { required_version = ">= 1.0" required_providers { docker = { - source = "hashicorp/docker" - version = ">= 2.0" + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } + ''') -# Create outputs.tf at root +# Create outputs.tf with open(os.path.join(project_name, "outputs.tf"), "w") as outputs_file: - outputs_file.write('''output "container_id" { + outputs_file.write(''' +output "container_id" { description = "The ID of the Docker container." - value = module.docker.container_id + value = module.docker_container.container_id } output "container_ip" { description = "The IP address of the Docker container." - value = module.docker.container_ip + value = module.docker_container.container_ip } ''') -# Create main.tf in modules/docker -with open(os.path.join(docker_dir, "main.tf"), "w") as docker_main_file: - docker_main_file.write('''resource "docker_container" "this" { - name = var.name +# Create module files +# Create docker_container/main.tf +with open(os.path.join(docker_container_dir, "main.tf"), "w") as module_main_file: + module_main_file.write(''' +resource "docker_container" "app" { image = var.image + name = var.name ports { - internal = var.ports[0] - external = var.ports[1] + internal = 80 + external = var.ports[0] } + env = var.env } ''') -# Create variables.tf in modules/docker -with open(os.path.join(docker_dir, "variables.tf"), "w") as docker_variables_file: - docker_variables_file.write('''variable "image" { - description = "The Docker image to use." +# Create docker_container/variables.tf +with open(os.path.join(docker_container_dir, "variables.tf"), "w") as module_vars_file: + module_vars_file.write(''' +variable "image" { + description = "Docker image." type = string } variable "name" { - description = "The name of the Docker container." + description = "Container name." type = string } variable "ports" { - description = "List of ports for the container." + description = "List of exposed ports." type = list(string) } + +variable "env" { + description = "Map of environment variables." + type = map(string) +} ''') -# Create terraform.tfvars in modules/docker -with open(os.path.join(docker_dir, "terraform.tfvars"), "w") as docker_tfvars_file: - docker_tfvars_file.write('''image = "nginx:latest" -name = "my_nginx" -ports = ["80", "80"] +# Create docker_container/terraform.tfvars +with open(os.path.join(docker_container_dir, "terraform.tfvars"), "w") as module_tfvars_file: + module_tfvars_file.write(''' +image = "nginx:latest" +name = "my-nginx-container" +ports = ["80:80"] +env = { "MY_ENV_VAR" = "value" } ''') -# Create versions.tf in modules/docker -with open(os.path.join(docker_dir, "versions.tf"), "w") as docker_versions_file: - docker_versions_file.write('''terraform { +# Create docker_container/versions.tf +with open(os.path.join(docker_container_dir, "versions.tf"), "w") as module_versions_file: + module_versions_file.write(''' +terraform { required_version = ">= 1.0" required_providers { docker = { - source = "hashicorp/docker" - version = ">= 2.0" + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } ''') -# Create outputs.tf in modules/docker -with open(os.path.join(docker_dir, "outputs.tf"), "w") as docker_outputs_file: - docker_outputs_file.write('''output "container_id" { +# Create docker_container/outputs.tf +with open(os.path.join(docker_container_dir, "outputs.tf"), "w") as module_outputs_file: + module_outputs_file.write(''' +output "container_id" { description = "The ID of the Docker container." - value = docker_container.this.id + value = docker_container.app.id } output "container_ip" { description = "The IP address of the Docker container." - value = docker_container.this.ip_address + value = docker_container.app.ip_address } ''') \ No newline at end of file diff --git a/app/main.py b/app/main.py index 131be176..d4f40fca 100644 --- a/app/main.py +++ b/app/main.py @@ -7,14 +7,16 @@ from app.models import (IaCBasicInput, IaCBugfixInput, Output, - IaCInstallationInput,IaCTemplateGeneration,HelmTemplateGeneration) + IaCInstallationInput,IaCTemplateGenerationDocker,HelmTemplateGeneration) from fastapi import FastAPI, HTTPException,Response from fastapi.responses import FileResponse from .prompt_generators import (IaC_basics_generator, IaC_bugfix_generator, IaC_installation_generator, - IaC_template_generator,helm_template_generator) + helm_template_generator) + +from app.template_generators.terraform.docker import (IaC_template_generator_docker) import os app = FastAPI() @@ -42,10 +44,10 @@ async def IaC_install_generation(request:IaCInstallationInput) -> Output: output = gpt_service(generated_prompt) return Output(output=output) -@app.post("/IaC-template/") -async def IaC_template_generation(request:IaCTemplateGeneration) -> Output: +@app.post("/IaC-template/docker") +async def IaC_template_generation_docker(request:IaCTemplateGenerationDocker) -> Output: - generated_prompt = IaC_template_generator(request) + generated_prompt = IaC_template_generator_docker(request) output = gpt_service(generated_prompt) edit_directory_generator("terraform_generator",output) execute_pythonfile("MyTerraform","terraform_generator") diff --git a/app/media/MyTerraform/main.tf b/app/media/MyTerraform/main.tf index 24dc98d6..48b120be 100644 --- a/app/media/MyTerraform/main.tf +++ b/app/media/MyTerraform/main.tf @@ -1,10 +1,14 @@ + provider "docker" { host = var.docker_host } -module "docker" { - source = "./modules/docker" - image = var.image - name = var.container_name - ports = var.ports +module "docker_container" { + source = "./modules/docker_container" + + image = var.image + name = var.name + ports = var.ports + env = var.env } + diff --git a/app/media/MyTerraform/modules/docker/main.tf b/app/media/MyTerraform/modules/docker/main.tf deleted file mode 100644 index 39698800..00000000 --- a/app/media/MyTerraform/modules/docker/main.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "docker_container" "this" { - name = var.name - image = var.image - ports { - internal = var.ports[0] - external = var.ports[1] - } -} diff --git a/app/media/MyTerraform/modules/docker/terraform.tfvars b/app/media/MyTerraform/modules/docker/terraform.tfvars deleted file mode 100644 index da3445f5..00000000 --- a/app/media/MyTerraform/modules/docker/terraform.tfvars +++ /dev/null @@ -1,3 +0,0 @@ -image = "nginx:latest" -name = "my_nginx" -ports = ["80", "80"] diff --git a/app/media/MyTerraform/modules/docker/variables.tf b/app/media/MyTerraform/modules/docker/variables.tf deleted file mode 100644 index 91697644..00000000 --- a/app/media/MyTerraform/modules/docker/variables.tf +++ /dev/null @@ -1,14 +0,0 @@ -variable "image" { - description = "The Docker image to use." - type = string -} - -variable "name" { - description = "The name of the Docker container." - type = string -} - -variable "ports" { - description = "List of ports for the container." - type = list(string) -} diff --git a/app/media/MyTerraform/modules/docker_container/main.tf b/app/media/MyTerraform/modules/docker_container/main.tf new file mode 100644 index 00000000..86f7d39e --- /dev/null +++ b/app/media/MyTerraform/modules/docker_container/main.tf @@ -0,0 +1,10 @@ + +resource "docker_container" "app" { + image = var.image + name = var.name + ports { + internal = 80 + external = var.ports[0] + } + env = var.env +} diff --git a/app/media/MyTerraform/modules/docker/outputs.tf b/app/media/MyTerraform/modules/docker_container/outputs.tf similarity index 64% rename from app/media/MyTerraform/modules/docker/outputs.tf rename to app/media/MyTerraform/modules/docker_container/outputs.tf index 7e2f1ae9..863337be 100644 --- a/app/media/MyTerraform/modules/docker/outputs.tf +++ b/app/media/MyTerraform/modules/docker_container/outputs.tf @@ -1,9 +1,10 @@ + output "container_id" { description = "The ID of the Docker container." - value = docker_container.this.id + value = docker_container.app.id } output "container_ip" { description = "The IP address of the Docker container." - value = docker_container.this.ip_address + value = docker_container.app.ip_address } diff --git a/app/media/MyTerraform/modules/docker_container/terraform.tfvars b/app/media/MyTerraform/modules/docker_container/terraform.tfvars new file mode 100644 index 00000000..0c37cb09 --- /dev/null +++ b/app/media/MyTerraform/modules/docker_container/terraform.tfvars @@ -0,0 +1,5 @@ + +image = "nginx:latest" +name = "my-nginx-container" +ports = ["80:80"] +env = { "MY_ENV_VAR" = "value" } diff --git a/app/media/MyTerraform/modules/docker_container/variables.tf b/app/media/MyTerraform/modules/docker_container/variables.tf new file mode 100644 index 00000000..e6f48f3f --- /dev/null +++ b/app/media/MyTerraform/modules/docker_container/variables.tf @@ -0,0 +1,20 @@ + +variable "image" { + description = "Docker image." + type = string +} + +variable "name" { + description = "Container name." + type = string +} + +variable "ports" { + description = "List of exposed ports." + type = list(string) +} + +variable "env" { + description = "Map of environment variables." + type = map(string) +} diff --git a/app/media/MyTerraform/modules/docker/versions.tf b/app/media/MyTerraform/modules/docker_container/versions.tf similarity index 58% rename from app/media/MyTerraform/modules/docker/versions.tf rename to app/media/MyTerraform/modules/docker_container/versions.tf index 3b14c52c..b7acf232 100644 --- a/app/media/MyTerraform/modules/docker/versions.tf +++ b/app/media/MyTerraform/modules/docker_container/versions.tf @@ -1,10 +1,11 @@ + terraform { required_version = ">= 1.0" required_providers { docker = { - source = "hashicorp/docker" - version = ">= 2.0" + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } diff --git a/app/media/MyTerraform/outputs.tf b/app/media/MyTerraform/outputs.tf index c5196f76..38d081bc 100644 --- a/app/media/MyTerraform/outputs.tf +++ b/app/media/MyTerraform/outputs.tf @@ -1,9 +1,10 @@ + output "container_id" { description = "The ID of the Docker container." - value = module.docker.container_id + value = module.docker_container.container_id } output "container_ip" { description = "The IP address of the Docker container." - value = module.docker.container_ip + value = module.docker_container.container_ip } diff --git a/app/media/MyTerraform/terraform.tfvars b/app/media/MyTerraform/terraform.tfvars index e42cd5ea..48ee34d2 100644 --- a/app/media/MyTerraform/terraform.tfvars +++ b/app/media/MyTerraform/terraform.tfvars @@ -1,4 +1,6 @@ + docker_host = "tcp://localhost:2375" -image = "nginx:latest" -container_name = "my_nginx" +image = "nginx:latest" +name = "my-nginx-container" ports = ["80:80"] +env = { "MY_ENV_VAR" = "value" } diff --git a/app/media/MyTerraform/variables.tf b/app/media/MyTerraform/variables.tf index edfed105..7c02a3ad 100644 --- a/app/media/MyTerraform/variables.tf +++ b/app/media/MyTerraform/variables.tf @@ -1,15 +1,16 @@ + variable "docker_host" { - description = "The Docker host Uri." + description = "Docker host URL." type = string } variable "image" { - description = "The Docker image to use." + description = "Docker image to use." type = string } -variable "container_name" { - description = "The name of the Docker container." +variable "name" { + description = "Name of the container." type = string } @@ -17,3 +18,8 @@ variable "ports" { description = "List of ports to expose." type = list(string) } + +variable "env" { + description = "Environment variables for the container." + type = map(string) +} diff --git a/app/media/MyTerraform/versions.tf b/app/media/MyTerraform/versions.tf index 3b14c52c..fac08236 100644 --- a/app/media/MyTerraform/versions.tf +++ b/app/media/MyTerraform/versions.tf @@ -1,10 +1,12 @@ + terraform { required_version = ">= 1.0" required_providers { docker = { - source = "hashicorp/docker" - version = ">= 2.0" + source = "kreuzwerker/docker" + version = ">= 2.8.0" } } } + diff --git a/app/models/__pycache__/terraform_models.cpython-311.pyc b/app/models/__pycache__/terraform_models.cpython-311.pyc index a521d13f..10bb492f 100644 Binary files a/app/models/__pycache__/terraform_models.cpython-311.pyc and b/app/models/__pycache__/terraform_models.cpython-311.pyc differ diff --git a/app/models/terraform_models.py b/app/models/terraform_models.py index 8f5d0504..d8f80014 100644 --- a/app/models/terraform_models.py +++ b/app/models/terraform_models.py @@ -63,21 +63,8 @@ def validate_service(cls, value): raise ValueError(f"Service must be one of {allowed_services}.") return value -class IaCTemplateGeneration(BaseModel): - CI_integration:bool = True - base_config:str = 'ec2' - service:str = 'terraform' +class IaCTemplateGenerationDocker(BaseModel): + docker_image: bool = True + docker_container: bool = True - @validator("base_config") - def validate_base_config(cls, value): - allowed_configs = ['ec2','s3','rds','docker_image','docker_container'] - if value not in allowed_configs: - raise ValueError(f"Base config must be one of {allowed_configs}.") - return value - - @validator("service") - def validate_service(cls, value): - allowed_services = ['terraform'] - if value not in allowed_services: - raise ValueError(f"Service must be one of {allowed_services}.") - return value \ No newline at end of file + \ No newline at end of file diff --git a/app/prompt_generators.py b/app/prompt_generators.py index 7366cf82..ecd444f8 100644 --- a/app/prompt_generators.py +++ b/app/prompt_generators.py @@ -1,6 +1,6 @@ from .models import (IaCBasicInput, IaCBugfixInput, - IaCInstallationInput, IaCTemplateGeneration,HelmTemplateGeneration) + IaCInstallationInput,HelmTemplateGeneration) def IaC_basics_generator(input : IaCBasicInput) -> str: @@ -35,122 +35,6 @@ def IaC_installation_generator(input : IaCInstallationInput) -> str: return prompt -def IaC_template_generator(input : IaCTemplateGeneration) -> str: - - prompt = f""" - Generate a Python code to generate a Terraform project (project name is app/media/MyTerraform) - that dynamically provisions resources for {input.base_config} ensuring a modular, flexible structure - to enable users to configure all essential settings at the root level. Only provide Python code, - no explanations or markdown formatting. The project should be organized as follows: - 1. Root Directory Structure: - - main.tf: - - Contains a provider block, configured with flexible variables where required to allow - users to specify provider settings without hardcoding. - - Defines a module block that references {input.base_config} from a subdirectory within - modules. This module block should expose all variables that {input.base_config} requires, - allowing configuration at the root level rather than directly within the module. - - Every variable defined in {input.base_config} should be passed through the module block, - ensuring that users can adjust all critical parameters of {input.base_config} by - modifying root main.tf. - - variables.tf: - - Declares all variables that users might need to configure for {input.base_config}. - These should include any inputs required by the provider or the {input.base_config} - resource, as well as optional parameters that users may want to customize. - - Variable descriptions should clearly indicate their purpose, and default values should - be avoided unless there are reasonable, common defaults, to maintain flexibility and - encourage explicit configuration. - - All types of variables can be used such as (number, string, bool, list(string), - map(string), list(map(string)), map(map(string)), object(), any) - - terraform.tfvars: - - Provides default values for variables declared in the root `variables.tf`, making it easy - for users to define common configurations. - - This file should be structured to include any typical default settings without hardcoding - sensitive values. - - versions.tf: - - Contains the `terraform` and `provider` blocks, specifying required versions. - - - If {input.base_config} is a Docker resource, set kreuzwerker/docker as the provider with appropriate version constraints. - - If {input.base_config} is an AWS resource, set hashicorp/aws as the provider with suitable version constraints. - - - Structure the `terraform` block as: - terraform {{ - required_version = ">= 1.0" - - required_providers {{ - = {{ - source = "" - version = ">= " - }} - }} - }} - - outputs.tf: - - Exposes relevant outputs from {input.base_config}, retrieving them from the module output - and making them accessible at the root level. Each output should have a clear description, - making it easy for users to understand the value and purpose of the output data. - 2. Module Directory Structure (modules/{input.base_config}): - - main.tf: - - Defines the {input.base_config} resource, fully utilizing required and also some optional - parameters. Avoid any hardcoded values within the module to support full configurability - from the root level. - - Required parameters should cover the essentials for creating {input.base_config}, while - optional parameters should provide a range of additional settings that enable more - granular configuration if desired. - - variables.tf: - - Lists all variables necessary for configuring {input.base_config}, with descriptions and - types specified to improve usability. No default values should be set here unless - necessary for required fields. - - Variable names should be clear and consistent with naming conventions in the root - variables file, ensuring consistency in usage. - - terraform.tfvars: - - Includes default values for module-level variables to ensure that common parameters have - defaults. This `terraform.tfvars` file within the module should be structured to provide - typical configuration values, making it easier to set up and reducing the need for hardcoded values. - - versions.tf: - - Contains the `terraform` and `provider` blocks, specifying required versions. - - If {input.base_config} is a Docker resource, set kreuzwerker/docker as the provider with appropriate version constraints. - - If {input.base_config} is an AWS resource, set hashicorp/aws as the provider with suitable version constraints. - - - Structure the `terraform` block as: - terraform {{ - required_version = ">= 1.0" - - required_providers {{ - = {{ - source = "" - version = ">= " - }} - }} - }} - - outputs.tf: - - Specifies outputs for the {input.base_config} resource, selecting relevant data that users - might need to access from the root level. Each output should have an informative - description, so users can understand its purpose and utility. - Ensure this project structure supports {input.base_config}’s configurability, extensibility, and - reusability across diverse Terraform providers, empowering users to manage their resources through a - single, customizable root configuration while keeping module internals robustly modular. - - finally just give me a python code without any note that can generate a project folder with the given - schema without ```python entry. and we dont need any base directory in the python code. the final - terraform template must work very well without any error! - - Python code you give me, must have structure like that: - - import os - project_name = "app/media/MyTerraform" - moduels_dir = os.path.join(project_name, "modules") - - # Create project directories - - os.makedirs(moduels_dir, exist_ok=True) - - # Create main.tf (for example) - with open(os.path.join(project_name, "main.tf"), "w") as main_file: - # any thing you need - - - - """ - return prompt def helm_template_generator(input : HelmTemplateGeneration) -> str: diff --git a/app/template_generators/__init__.py b/app/template_generators/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/template_generators/__pycache__/__init__.cpython-311.pyc b/app/template_generators/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..88da656d Binary files /dev/null and b/app/template_generators/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/template_generators/terraform/__init__.py b/app/template_generators/terraform/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/template_generators/terraform/__pycache__/__init__.cpython-311.pyc b/app/template_generators/terraform/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..57e0d522 Binary files /dev/null and b/app/template_generators/terraform/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/template_generators/terraform/__pycache__/docker.cpython-311.pyc b/app/template_generators/terraform/__pycache__/docker.cpython-311.pyc new file mode 100644 index 00000000..ca0514bf Binary files /dev/null and b/app/template_generators/terraform/__pycache__/docker.cpython-311.pyc differ diff --git a/app/template_generators/terraform/docker.py b/app/template_generators/terraform/docker.py new file mode 100644 index 00000000..dc3342dc --- /dev/null +++ b/app/template_generators/terraform/docker.py @@ -0,0 +1,118 @@ + + +def IaC_template_generator_docker(input) -> str: + + prompt = f""" + Generate a Python code to generate a Terraform project (project name is app/media/MyTerraform) + that dynamically provisions resources for {input.base_config} ensuring a modular, flexible structure + to enable users to configure all essential settings at the root level. Only provide Python code, + no explanations or markdown formatting. The project should be organized as follows: + 1. Root Directory Structure: + - main.tf: + - Contains a provider block, configured with flexible variables where required to allow + users to specify provider settings without hardcoding. + - Defines a module block that references {input.base_config} from a subdirectory within + modules. This module block should expose all variables that {input.base_config} requires, + allowing configuration at the root level rather than directly within the module. + - Every variable defined in {input.base_config} should be passed through the module block, + ensuring that users can adjust all critical parameters of {input.base_config} by + modifying root main.tf. + - variables.tf: + - Declares all variables that users might need to configure for {input.base_config}. + These should include any inputs required by the provider or the {input.base_config} + resource, as well as optional parameters that users may want to customize. + - Variable descriptions should clearly indicate their purpose, and default values should + be avoided unless there are reasonable, common defaults, to maintain flexibility and + encourage explicit configuration. + - All types of variables can be used such as (number, string, bool, list(string), + map(string), list(map(string)), map(map(string)), object(), any) + - terraform.tfvars: + - Provides default values for variables declared in the root `variables.tf`, making it easy + for users to define common configurations. + - This file should be structured to include any typical default settings without hardcoding + sensitive values. + - versions.tf: + - Contains the `terraform` and `provider` blocks, specifying required versions. + + - If {input.base_config} is a Docker resource, set kreuzwerker/docker as the provider with appropriate version constraints. + - If {input.base_config} is an AWS resource, set hashicorp/aws as the provider with suitable version constraints. + + - Structure the `terraform` block as: + terraform {{ + required_version = ">= 1.0" + + required_providers {{ + = {{ + source = "" + version = ">= " + }} + }} + }} + - outputs.tf: + - Exposes relevant outputs from {input.base_config}, retrieving them from the module output + and making them accessible at the root level. Each output should have a clear description, + making it easy for users to understand the value and purpose of the output data. + 2. Module Directory Structure (modules/{input.base_config}): + - main.tf: + - Defines the {input.base_config} resource, fully utilizing required and also some optional + parameters. Avoid any hardcoded values within the module to support full configurability + from the root level. + - Required parameters should cover the essentials for creating {input.base_config}, while + optional parameters should provide a range of additional settings that enable more + granular configuration if desired. + - variables.tf: + - Lists all variables necessary for configuring {input.base_config}, with descriptions and + types specified to improve usability. No default values should be set here unless + necessary for required fields. + - Variable names should be clear and consistent with naming conventions in the root + variables file, ensuring consistency in usage. + - terraform.tfvars: + - Includes default values for module-level variables to ensure that common parameters have + defaults. This `terraform.tfvars` file within the module should be structured to provide + typical configuration values, making it easier to set up and reducing the need for hardcoded values. + - versions.tf: + - Contains the `terraform` and `provider` blocks, specifying required versions. + - If {input.base_config} is a Docker resource, set kreuzwerker/docker as the provider with appropriate version constraints. + - If {input.base_config} is an AWS resource, set hashicorp/aws as the provider with suitable version constraints. + + - Structure the `terraform` block as: + terraform {{ + required_version = ">= 1.0" + + required_providers {{ + = {{ + source = "" + version = ">= " + }} + }} + }} + - outputs.tf: + - Specifies outputs for the {input.base_config} resource, selecting relevant data that users + might need to access from the root level. Each output should have an informative + description, so users can understand its purpose and utility. + Ensure this project structure supports {input.base_config}’s configurability, extensibility, and + reusability across diverse Terraform providers, empowering users to manage their resources through a + single, customizable root configuration while keeping module internals robustly modular. + + finally just give me a python code without any note that can generate a project folder with the given + schema without ```python entry. and we dont need any base directory in the python code. the final + terraform template must work very well without any error! + + Python code you give me, must have structure like that: + + import os + project_name = "app/media/MyTerraform" + moduels_dir = os.path.join(project_name, "modules") + + # Create project directories + + os.makedirs(moduels_dir, exist_ok=True) + + # Create main.tf (for example) + with open(os.path.join(project_name, "main.tf"), "w") as main_file: + # any thing you need + + + + """ + return prompt \ No newline at end of file diff --git a/app/tests/__pycache__/test_helm_template.cpython-311-pytest-8.3.3.pyc b/app/tests/__pycache__/test_helm_template.cpython-311-pytest-8.3.3.pyc index a8889bfc..93abf41e 100644 Binary files a/app/tests/__pycache__/test_helm_template.cpython-311-pytest-8.3.3.pyc and b/app/tests/__pycache__/test_helm_template.cpython-311-pytest-8.3.3.pyc differ diff --git a/app/tests/__pycache__/test_iac_basic.cpython-311-pytest-8.3.3.pyc b/app/tests/__pycache__/test_iac_basic.cpython-311-pytest-8.3.3.pyc index 0a420fea..d6baa20e 100644 Binary files a/app/tests/__pycache__/test_iac_basic.cpython-311-pytest-8.3.3.pyc and b/app/tests/__pycache__/test_iac_basic.cpython-311-pytest-8.3.3.pyc differ diff --git a/app/tests/__pycache__/test_iac_bugfix.cpython-311-pytest-8.3.3.pyc b/app/tests/__pycache__/test_iac_bugfix.cpython-311-pytest-8.3.3.pyc index 3d488caa..2599f5e9 100644 Binary files a/app/tests/__pycache__/test_iac_bugfix.cpython-311-pytest-8.3.3.pyc and b/app/tests/__pycache__/test_iac_bugfix.cpython-311-pytest-8.3.3.pyc differ diff --git a/app/tests/__pycache__/test_iac_install.cpython-311-pytest-8.3.3.pyc b/app/tests/__pycache__/test_iac_install.cpython-311-pytest-8.3.3.pyc index 11a251a6..01040bac 100644 Binary files a/app/tests/__pycache__/test_iac_install.cpython-311-pytest-8.3.3.pyc and b/app/tests/__pycache__/test_iac_install.cpython-311-pytest-8.3.3.pyc differ diff --git a/app/tests/__pycache__/test_iac_template.cpython-311-pytest-8.3.3.pyc b/app/tests/__pycache__/test_iac_template.cpython-311-pytest-8.3.3.pyc index 467d4c21..68c252cf 100644 Binary files a/app/tests/__pycache__/test_iac_template.cpython-311-pytest-8.3.3.pyc and b/app/tests/__pycache__/test_iac_template.cpython-311-pytest-8.3.3.pyc differ