File tree Expand file tree Collapse file tree 8 files changed +166
-0
lines changed Expand file tree Collapse file tree 8 files changed +166
-0
lines changed Original file line number Diff line number Diff line change @@ -39,3 +39,5 @@ Show all outputs:
3939
4040
4141
42+
43+
Original file line number Diff line number Diff line change 1+ provider "aws" {
2+ region = var. region
3+ }
4+
5+ module "ec2" {
6+ source = " ../../../modules/ec2"
7+ region = var. region
8+ instance_name = var. instance_name
9+ ami_id = var. ami_id
10+ instance_type = var. instance_type
11+ key_name = var. key_name
12+ instance_count = var. instance_count
13+ subnet_ids = var. subnet_ids
14+ security_group_ids = var. security_group_ids
15+ }
Original file line number Diff line number Diff line change 1+ output "instance_state" {
2+ description = " The state of the ec2 instance "
3+ value = module. ec2 . instance_state
4+ }
5+
6+ output "instance_public_dns" {
7+ description = " The Public DNS address of the ec2 instance"
8+ value = module. ec2 . instance_public_dns
9+ }
10+
11+ output "instance_public_ip" {
12+ description = " The Public Ip address of the ec2 instance"
13+ value = module. ec2 . instance_public_ip
14+ }
Original file line number Diff line number Diff line change 1+ variable "region" {
2+ type = string
3+ description = " Region of the ec2 instance"
4+ }
5+
6+ variable "instance_name" {
7+ type = string
8+ description = " Name of the ec2 instance"
9+ }
10+
11+ variable "ami_id" {
12+ type = string
13+ description = " AMI Id of the ec2 instance"
14+ }
15+
16+ variable "instance_type" {
17+ type = string
18+ description = " Instance type of the ec2 instance"
19+ }
20+
21+ variable "key_name" {
22+ type = string
23+ description = " Key name of the ec2 instance"
24+ }
25+
26+ variable "security_group_ids" {
27+ type = list (string )
28+ description = " Security group id of the ec2 instance"
29+ }
30+
31+ variable "instance_count" {
32+ type = number
33+ description = " Count of the ec2 instances"
34+ }
35+
36+ variable "subnet_ids" {
37+ type = list (string )
38+ description = " Subnet ids of the ec2 instance"
39+ }
Original file line number Diff line number Diff line change 1+ resource "aws_security_group" "instance-sg" {
2+ name = " instance-sg"
3+ description = " Security Group for Instance"
4+
5+ ingress {
6+ from_port = 22
7+ to_port = 22
8+ protocol = " tcp"
9+ cidr_blocks = [" 0.0.0.0/0" ]
10+ }
11+
12+ egress {
13+ from_port = 0
14+ to_port = 0
15+ protocol = " -1"
16+ cidr_blocks = [" 0.0.0.0/0" ]
17+ }
18+ }
19+
20+
21+ resource "aws_instance" "gitlab_instance" {
22+ count = var. instance_count
23+
24+ ami = var. ami_id
25+ instance_type = var. instance_type
26+ key_name = var. key_name
27+ vpc_security_group_ids = [aws_security_group . instance-sg . id ]
28+
29+ tags = {
30+ Name = " ${ var . instance_name } -${ count . index + 1 } "
31+ }
32+
33+ subnet_id = element (var. subnet_ids , count. index % length (var. subnet_ids ))
34+ }
Original file line number Diff line number Diff line change 1+ output "instance_state" {
2+ description = " The state of the ec2 instance "
3+ value = aws_instance. gitlab_instance . * . instance_state
4+ }
5+
6+ output "instance_public_dns" {
7+ description = " The Public DNS address of the ec2 instance"
8+ value = aws_instance. gitlab_instance . * . public_dns
9+ }
10+
11+ output "instance_public_ip" {
12+ description = " The Public Ip address of the ec2 instance"
13+ value = aws_instance. gitlab_instance . * . public_ip
14+ }
Original file line number Diff line number Diff line change 1+ variable "region" {
2+ type = string
3+ description = " Region of the ec2 instance"
4+ }
5+
6+ variable "instance_name" {
7+ type = string
8+ description = " Name of the ec2 instance"
9+ }
10+
11+ variable "ami_id" {
12+ type = string
13+ description = " AMI Id of the ec2 instance"
14+ }
15+
16+ variable "instance_type" {
17+ type = string
18+ description = " Instance type of the ec2 instance"
19+ }
20+
21+ variable "key_name" {
22+ type = string
23+ description = " Key name of the ec2 instance"
24+ }
25+
26+ variable "security_group_ids" {
27+ type = list (string )
28+ description = " Security group id of the ec2 instance"
29+ }
30+
31+ variable "instance_count" {
32+ type = number
33+ description = " Count of the ec2 instances"
34+ }
35+
36+ variable "subnet_ids" {
37+ type = list (string )
38+ description = " Subnet ids of the ec2 instance"
39+ }
Original file line number Diff line number Diff line change 1+ # ec2 instance vars
2+ region = " eu-north-1"
3+ instance_name = " GitLab-CI"
4+ ami_id = " ami-0989fb15ce71ba39e"
5+ instance_type = " t3.micro"
6+ key_name = " techiescamp"
7+ instance_count = 1
8+ security_group_ids = [" sg-0aa656667277a3e65" ]
9+ subnet_ids = [" subnet-07fab58fa9620dfb9" , " subnet-051fbcbaa925b8c44" , " subnet-0c46e29a23c5ba3b8" ]
You can’t perform that action at this time.
0 commit comments