-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy path850285-Harija.tf
97 lines (85 loc) · 2.03 KB
/
850285-Harija.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
93
94
95
96
97
provider "aws" {
access_key="${var.my_acess_key}"
secret_key="${var.my_secret_key}"
region="${lookup(var.aws_region}"
}
variable "my_access_key" {}
variable "my_secret_key" {}
variable "aws_region"{
type ="map"
aws_region{
"us-east-1"="North Virginia"
"us-west-1" = "LA"
"ap-west-1" = "mumbai"
}
}
variable "ami_ids"{
default="bm782689"
}
variable "def_env"{
default = "dev"
}
resource "aws_security_group" "my_security_grp"{
ingress{
to_port=0
from_port=22
protocol= "tcp"
cidr_block= [0.0.0.0/0]
}
egress{
to_port=0
from_port=0
protocol "-1"
cidr_block= [0.0.0.0/0]
}
}
resource "aws_key_pair" "my_key_pair"
{
key_value="bootstrap_Nginix"
private_key="${file("..\public_key")}"
}
output "key_pair"{
private_id="${aws_key_pair.my_key_pair.id}"
}
resource "aws_subnet" "subnet"{
name="web_Server"
}
output "subnet"{
subnet_id="${aws_subnet.subnet}"
}
provisioner "file"{
source= "\path\to\source"
destination="\moving\it\to\destination"
}
provisioner "remote-exec"{
inline=[
"sudo yum install Nginix"
".\Nginix"
"chmod -u 700 Nginix"
]
connection {
type="ssh"
user="ec2_user"
private_id="${file("..\private_id")}"
}
}
provisioner "file"{
source="hereNginix.html"
destination="host.Nginix.html"
}
resource "aws_load_balancer_policy" "my_load_balancer"{
to_port=0
from_port=22
protocol= "tcp"
cidr_block= "0.0.0.0/0"
}
resource "aws_instance" "web_server" {
ami="${var.ami_ids}"
instance_type="t2.micro"
region="us-east-1"
security_id="${aws_security_group.mysecurity_grp.id}"
key_name="${aws_key_pair.my_key_pair.key_name}"
private_ip="${provisioner.remote_exec_private_id}"
count="${var.def_env =="dev" ? 0:3}"
domain = "${aws_subnet.subnet.domain_name}"
}