File tree Expand file tree Collapse file tree 2 files changed +66
-22
lines changed Expand file tree Collapse file tree 2 files changed +66
-22
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,44 @@ terraform apply -var-file=../../../vars/dev/rds.tfvars
2727
2828terraform destroy -var-file=../../../vars/dev/rds.tfvars
2929
30+ ## Terraform EC2 Instance Deployment
31+
32+ 1 . Navigate to the ` environment/dev ` folder:
33+
34+ ``` bash
35+ cd environment/dev
36+ ```
37+
38+ 2 . Open the ` ec2.tfvars ` file and modify it with your desired details. This file contains variables used in the Terraform configuration.
39+
40+ ## Deployment
41+
42+ 1 . Initialize Terraform in the working directory:
43+
44+ ``` bash
45+ terraform init
46+ ```
47+
48+ 2 . Create an execution plan:
49+
50+ ``` bash
51+ terraform plan -var-file=../../../vars/dev/ec2.tfvars
52+ ```
53+
54+ 3 . Apply the changes to create the EC2 instance:
55+
56+ ``` bash
57+ terraform apply -var-file=../../../vars/dev/ec2.tfvars
58+ ```
59+
60+ 4 . To destroy the EC2 instance and associated resources:
61+
62+ ``` bash
63+ terraform destroy -var-file=../../../vars/dev/ec2.tfvars
64+ ```
65+
66+ ** Note** : Always review the execution plan (` terraform plan ` ) before applying changes to avoid unintended modifications.
67+
3068## Command Reference
3169
3270Update all outputs:
@@ -39,5 +77,3 @@ Show all outputs:
3977
4078
4179
42-
43-
Original file line number Diff line number Diff line change 1- # ec2 instance vars
2- region = " eu-north-1"
3- instance_name = " Instance"
4- ami_id = " ami-0989fb15ce71ba39e"
5- instance_type = " t3.micro"
6- key_name = " techiescamp"
7- instance_count = 1
8- subnet_ids = [" subnet-07fab58fa9620dfb9" , " subnet-051fbcbaa925b8c44" , " subnet-0c46e29a23c5ba3b8" ]
1+ # EC2 Instance Variables
2+ region = " eu-north-1"
3+ instance_name = " Instance"
4+ ami_id = " ami-0989fb15ce71ba39e"
5+ instance_type = " t3.micro"
6+ key_name = " techiescamp"
7+ instance_count = 1
8+ subnet_ids = [" subnet-07fab58fa9620dfb9" ,
9+ " subnet-051fbcbaa925b8c44" ,
10+ " subnet-0c46e29a23c5ba3b8" ]
911
10- # ec2_sg vars
11- sg_name = " Instance_sg"
12- from_port = [22 , 80 ]
13- to_port = [22 , 80 ]
14- protocol = [" tcp" , " tcp" ]
15- cidr_block = [" 0.0.0.0/0" ]
12+ # EC2 Security Group Variables
13+ sg_name = " Instance_sg"
14+ vpc_id = " vpc-07d73d0c9081754d0"
15+ ingress_from_port = [22 , 80 ]
16+ ingress_to_port = [22 , 80 ]
17+ ingress_protocol = [" tcp" , " tcp" ]
18+ ingress_cidr_block = [" 0.0.0.0/0" ]
19+ egress_from_port = [0 ]
20+ egress_to_port = [0 ]
21+ egress_protocol = [" -1" ]
22+ egress_cidr_block = [" 0.0.0.0/0" ]
23+
24+ # Tag Keys
25+ name = " Instance"
26+ owner = " Techiescamp"
27+ environment = [" dev" ]
28+ cost_center = " project"
29+ application = " web-app"
1630
17- # Tag keys
18- name = " Instance"
19- owner = " Techiescamp"
20- environment = [" dev" ]
21- cost_center = " project"
22- application = " web-app"
You can’t perform that action at this time.
0 commit comments