-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy path852115-Shaurya Sharma.tf.txt
77 lines (49 loc) · 1.14 KB
/
852115-Shaurya Sharma.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
VARIABLES :
variables :
variables "aws_access_key" {}
variables "aws_secret_key" {}
resource :
resources "aws_instance" "my_instance"{
ami = " ami id here "
instance = "t2.micro"
connection{
type = "ssh"
user="ec2_user"
private_key="your private key"
}
resource "aws_elb" "load_balancer{
name = "test_elb"
instance = ["$(instance1)","$(instance2)"]
security_group = ["$(aws_security_group.elb_security_group.id)"]
}
resource "aws_key_pair" "key pair here"
{
key_name ="aws-key"
private_key= "${file("path of the file")}"
}
}
resource "aws_security_group" "grp"
{
" here we define the aws security group"
}
provider :
provider "aws"{
aws_access_key="${var.aws_access_key}"
aws_secret_key="${var.aws_secret_key}"
aws_region="us-east-2"
}
provisioner :
provisioner " remote-exec"{
script = [
apt-getinstall apache-2
apt-get update
service apache2 start
" here we have the commands for installing apache server "
]
}
shell commands:
$export TF_VAR_aws_access_key="access key "
$export TF_var_aws_secret_key="secret key "
terraform init
terraform plan
terraform apply