Skip to content

Commit 8ec8c5f

Browse files
committed
feat(EC2_Prompt): Add aws_ami_from_instance resource to ec2 prompt
1 parent 82bbd85 commit 8ec8c5f

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

  • app/template_generators/terraform/aws

app/template_generators/terraform/aws/ec2.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
def IaC_template_generator_ec2(input) -> str:
2-
3-
ec2 = ['aws_key_pair', 'aws_security_group', 'aws_instance']
2+
3+
ec2 = ['aws_key_pair', 'aws_security_group', 'aws_instance', 'aws_ami_from_instance']
44

55
aws_ec2_create_key_pair = 'true' if input.key_pair else 'false'
66
aws_ec2_create_security_group = 'true' if input.security_group else 'false'
77
aws_ec2_create_instance = 'true' if input.aws_instance else 'false'
8+
aws_ec2_create_ami_from_instance = 'true' if input.ami_from_instance else 'false'
89

910

1011
prompt = f"""
@@ -21,6 +22,7 @@ def IaC_template_generator_ec2(input) -> str:
2122
}}
2223
```
2324
- Defines a module block that references "ec2" from a subdirectory within modules.
25+
Don't forget to use source parameter to call ec2 module. this is so important.
2426
This module block should expose all variables that {ec2} resources require, allowing
2527
configuration at the root level rather than directly within the module.
2628
- Every variable defined in {ec2} resources should be passed through the module block,
@@ -33,6 +35,8 @@ def IaC_template_generator_ec2(input) -> str:
3335
security_group_create(bool), security_group_name(string), security_group_ingress_rules(map(object)), security_group_egress_rule(object())
3436
- Sets these variables names for aws_instance resource:
3537
instance_create(bool), instance_type(string)
38+
- Sets these variables names for aws_ami_from_instance resource:
39+
ami_from_instance_create(bool), ami_name(string)
3640
- terraform.tfvars:
3741
- Structure as follows:
3842
key_pair_create = {aws_ec2_create_key_pair}
@@ -65,6 +69,9 @@ def IaC_template_generator_ec2(input) -> str:
6569
6670
instance_create = {aws_ec2_create_instance}
6771
instance_type = "t2.micro"
72+
73+
ami_from_instance_create = {aws_ec2_create_ami_from_instance}
74+
ami_name = "my-own-ami"
6875
- versions.tf:
6976
- Structure as follows:
7077
terraform {{
@@ -167,13 +174,28 @@ def IaC_template_generator_ec2(input) -> str:
167174
```
168175
vpc_security_group_ids = var.security_group_create ? [aws_security_group.security_group[0].id] : null
169176
```
177+
- Set the following parameters for aws_ami_from_instance resource (name its terraform resource to "ami") and avoid using any other parameters:
178+
- 1. count (type: number): follow the below syntax for count:
179+
```
180+
count = var.instance_create && var.ami_from_instance_create ? 1 : 0
181+
```
182+
- 2. name (type: string): follow the below syntax for name:
183+
```
184+
name = var.ami_name
185+
```
186+
- 3. source_instance_id: follow the below syntax for source_instance_id:
187+
```
188+
source_instance_id = aws_instance.instance[0].id
189+
```
170190
- variables.tf:
171191
- Sets these variables names for aws_key_pair resource:
172192
key_pair_create(bool), key_pair_name(string)
173193
- Sets these variables names for aws_security_group resource:
174194
security_group_create(bool), security_group_name(string), security_group_ingress_rules(map(object)), security_group_egress_rule(object())
175195
- Sets these variables names for aws_instance resource:
176196
instance_create(bool), instance_type(string)
197+
- Sets these variables names for aws_ami_from_instance resource:
198+
ami_from_instance_create(bool), ami_name(string)
177199
- terraform.tfvars:
178200
- Structure as follows:
179201
key_pair_create = {aws_ec2_create_key_pair}
@@ -206,6 +228,9 @@ def IaC_template_generator_ec2(input) -> str:
206228
207229
instance_create = {aws_ec2_create_instance}
208230
instance_type = "t2.micro"
231+
232+
ami_from_instance_create = {aws_ec2_create_ami_from_instance}
233+
ami_name = "my-own-ami"
209234
- versions.tf:
210235
- Structure as follows:
211236
terraform {{

0 commit comments

Comments
 (0)