-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
92 lines (68 loc) · 1.66 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
######..."data source for retrieve aws ami_id"...######
data "aws_ami" "amazonaminame" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-*-x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
############...............module for EC2.........############
resource "aws_instance" "web" {
ami = data.aws_ami.amazonaminame.id
vpc_security_group_ids = [aws_security_group.allow.id]
instance_type = var.OStype
tags = {
Name = var.tagname
}
}
variable "tagname" {
type = string
default = "os-by-terraform-remoteState_locking"
}
variable "OStype" {
default = "t2.micro"
}
########### "Module for security group which allow inbound rule" #########
resource "aws_security_group" "allow" {
name = "terra_allow_${var.security_grp_name}"
description = " allow inbound "
vpc_id = var.vpcID
dynamic "ingress" {
for_each = var.sgports
iterator = port
content {
description = "TLS from vpc"
from_port = port.value
to_port = port.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
variable "sgports" {
type = list(number)
default = [22, 8080, 80, 1234]
}
variable "security_grp_name" {
type = string
default = "pratik-sg"
}
### "varible for VPC id "
variable "vpcID" {
default = "vpc-071ddf3f50a17a539"
}