-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy path850488-Prajna.tf.txt
144 lines (102 loc) · 2.25 KB
/
850488-Prajna.tf.txt
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
variables.tf
variable aws_access_key{}
variable aws_secret_key{}
variable aws_region{
default="us-east-1"
}
#environment variables for access key and secret key
export TF_VAR_aws_access_key=" "
export TF_VAR_aws_secret_key=" "
provider.tf
provider "aws"{
access_key="${aws_access_key}"
secret_key="${aws_secret_key}"
region="${aws_region}"
}
data "aws_instance" "web"
{
instance_tags{
Role="web_server"
}
instance_state=["running". "stopped"]
}
resource "aws_vpc" "default" {
cidr_block = " "
}
resource "aws_internet_gateway" "default" {
vpc_id = " "
}
resource "aws_subnet" "default" {
vpc_id = " "
cidr_block = " "
}
resource "aws_security_group" "elb" {
name = " "
vpc_id = " "
ingress {
from_port = 80
to_port = 80
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"]
}
}
resource "aws_elb" "web" {
name = " "
subnets = ["${aws_subnet.default.id}"]
security_groups = ["${aws_security_group.elb.id}"]
instances = ["${aws_instance.web.id}"]
}
#generate key pair
ssh-keygen -t rsa -b 4096 -f aws_rsa
resource "aws_key_pair" "auth" {
key_name = "${var.env}-key"
public_key = "/path/to/key"
}
resource "aws_instance" "web" {
connection {
user = "ec2"
private_key = "${tls_private_key.two-tier.private_key_pem}"
}
instance_type = "t2.micro"
ami = ""
key_name = ""
vpc_security_group_ids = ["${aws_security_group.default.id}"]
subnet_id = "${aws_subnet.default.id}"
provisioner "remote-exec" {
inline = [
install nginix
]
}
}
resource "aws_default_subnet" "subnet_id"
{
}
#implicit dependency
subnet_id="${aws_default_subnet.subnet_id.id}
#to verify connection
ssh -i aws_rsa ec2user ip_address
terraform
{
backend "S3"
{
bucket="Bucket_name"
key="path/to/key"
region="us-east-1"
}
}
module "vpc"
{
scource=" "
name="vpc_module"
cidr=" "
private_subnet=[ ]
public_subnet=[ ]
enable_nat_gateway="true"
enable_vpn_gateway='true"
}