Skip to content

Commit c3b3884

Browse files
committed
fix(docker_prompt): modify creation condition for docker resources
1 parent 0fa4008 commit c3b3884

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

app/template_generators/terraform/docker.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
def IaC_template_generator_docker(input) -> str:
22

33
docker = ['docker_container', 'docker_image']
4-
docker_image_count = 1 if input.docker_image else 0
5-
docker_container_count = 1 if input.docker_container else 0
4+
create_docker_image = 'true' if input.docker_image else 'false'
5+
create_docker_container = 'true' if input.docker_container else 'false'
66

77
prompt = f"""
88
Generate a Python code to generate a Terraform project (project name is app/media/MyTerraform)
@@ -25,25 +25,24 @@ def IaC_template_generator_docker(input) -> str:
2525
root main.tf. Avoid using any other parameters. just use the parameters of {docker} resources with the same keys
2626
- variables.tf:
2727
- Sets these variables names for docker_image resource:
28-
image_name(string), image_force_remove(bool), image_build(object), image_count(number)
28+
create_image(bool), image_name(string), image_force_remove(bool), image_build(object)
2929
- Sets these variables names for docker_container resource:
30-
container_image(string), container_name(string), container_hostname(string),
31-
container_restart(string), container_count(number)
30+
create_container(bool), container_image(string), container_name(string), container_hostname(string), container_restart(string)
3231
- terraform.tfvars:
3332
- Structure as follows:
33+
create_image = {create_docker_image}
3434
image_name = "my-image"
3535
image_force_remove = true
3636
image_build = {{
3737
context = "./"
3838
tag = ["my-image:latest"]
3939
}}
40-
image_count = {docker_image_count}
4140
41+
create_container = {create_docker_container}
4242
container_image = "my-image"
4343
container_name = "my-container"
4444
container_hostname = "my-host"
4545
container_restart = "always"
46-
container_count = {docker_container_count}
4746
- versions.tf:
4847
- Structure as follows:
4948
terraform {{
@@ -58,41 +57,46 @@ def IaC_template_generator_docker(input) -> str:
5857
}}
5958
2. Module Directory Structure (modules/docker):
6059
- main.tf:
61-
- Set the following parameters for docker_image resource and avoid using any other parameters:
62-
- 1. count (type: number) Specifies the number of images
60+
- Set the following parameters for docker_image resource (name its terraform resource to "image") and avoid using any other parameters:
61+
- 1. count (type: number): follow the below syntax for count:
62+
```
63+
count = var.create_image ? 1 : 0
64+
```
6365
- 2. name (type: string): Specifies the image name.
6466
- 3. force_remove (type: boolean): Determines whether to forcibly remove intermediate containers.
6567
- 4. build (block type): Includes the following required field:
6668
- context (type: string, required): Specifies the build context for the image.
6769
- tag(type: List of Strings, required): Specifices the image tag in the 'name:tag'
6870
format, (e.g., ["NAME:VERSION"])
69-
- Set the following parameters for docker_container resource and avoid using any other parameters:
70-
- 1. count (type: number): Specifies the number of containers
71+
- Set the following parameters for docker_container resource (name its terraform resource to "container") and avoid using any other parameters:
72+
- 1. count (type: number): follow the below syntax for count:
73+
```
74+
count = var.create_container ? 1 : 0
75+
```
7176
- 2. image (type: string): Specifies the container image.
7277
- 3. name (type: string): Sets the container name.
7378
- 4. hostname (type: string): Configures the container hostname.
7479
- 5. restart (type: string): Defines the container's restart policy (e.g., always, on-failure, no).
7580
- variables.tf:
7681
- Sets these variables names for docker_image resource:
77-
image_name(string), image_force_remove(bool), image_build(object), image_count(number)
82+
create_image(bool), image_name(string), image_force_remove(bool), image_build(object)
7883
- Sets these variables names for docker_container resource:
79-
container_image(string), container_name(string), container_hostname(string),
80-
container_restart(string), container_count(number)
84+
create_container(bool), container_image(string), container_name(string), container_hostname(string), container_restart(string)
8185
- terraform.tfvars:
8286
- Structure as follows:
87+
create_image = {create_docker_image}
8388
image_name = "my-image"
8489
image_force_remove = true
8590
image_build = {{
8691
context = "./"
8792
tag = ["my-image:latest"]
8893
}}
89-
image_count = {docker_image_count}
9094
95+
create_container = {create_docker_container}
9196
container_image = "my-image"
9297
container_name = "my-container"
9398
container_hostname = "my-host"
9499
container_restart = "always"
95-
container_count = {docker_container_count}
96100
- versions.tf:
97101
- Structure as follows:
98102
terraform {{

0 commit comments

Comments
 (0)