-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathAbhimanyu-848468.tf.txt
109 lines (88 loc) · 2.17 KB
/
Abhimanyu-848468.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
Create a template for running a simple two-tier architecture on Amazon Web services. The premise is that you have stateless app servers running behind an ELB serving traffic.
#VARIABLE
variable "AWS_REGION" {
default = "eu-east-1"
}
variable "PRIVATEKEY" {
default = "pkey"
}
variable "PUBLICKEY" {
default = "pkey.pub"
}
variable "AMIS" {
type = "map"
default = {
us-west-2 = "ami-06b94666"
eu-west-1 = "ami-844e0bf7"
us-east-1 = "ami-13be557e"
}
}
#PROVIDER
provider "aws" {
region = "${var.AWS_REGION}"
}
#RESOURCE
resource "aws_key_pair" "pkeypair" {
key_name = "pkeypair"
public_key = "${file("${var.PUBLICKEY}")}"
}
#AUTOSCALING
resource "aws_launch_configuration" "aws-config" {
name = "AWSconfig"
image_id = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.pkeypair.key_name}"
}
resource "aws_autoscaling_group" "autoscaling" {
name = "autoscaling"
launch_configuration = "${aws_launch_configuration.aws-config.name}"
min_size = 2
max_size = 2
health_check_grace_period = 300
health_check_type = "ELB"
load_balancers = ["${aws_elb.a-elb.name}"]
force_delete = true
tag {
key = "Name"
value = "ec2 instance"
propagate_at_launch = true
}
}
#ELB
resource "aws_elb" "a-elb" {
name = "a-elb"
listener {
instance_port = 8080
instance_protocol = "http"
lb_port = 8080
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:8080/"
interval = 30
}
cross_zone_load_balancing = true
connection_draining = true
connection_draining_timeout = 400
tags {
Name = "a-elb"
}
}
#OUTPUT
output "ELB" {
value = "${aws_elb.a-elb.dns_name}"
}
# Internet VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
enable_dns_support = "true"
enable_dns_hostnames = "true"
enable_classiclink = "false"
tags {
Name = "main"
}
}