-
Notifications
You must be signed in to change notification settings - Fork 0
/
hs_single.tf
195 lines (153 loc) · 4.11 KB
/
hs_single.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
provider "aws" {
//region ="ca-central-1"
region = "us-west-2"
}
variable "azsinfo"{
description = "What Availablity Zone should this environment deploy to: ca-central-1a"
default = "us-west-2a"
}
variable "instance_type"{
default = "d3.4xlarge"
}
variable "volume_size"{
description = "How many GB of volume do you want?"
default = 200
}
//I've defined a variable to filter against so that I can find the VPC/SG/etc information from previous module
//The key variable here is awshybrid = true
//THIS SHOULD BE MOVED TO A MAP, but who has the time for that!
variable "filter_tag"{
type = string
default = "AWSVPC"
}
variable "filter_value"{
type = string
default = "true"
}
data "aws_subnet_ids" "awshybrid" {
vpc_id = data.aws_vpc.awshybrid.id
//this tag just takes the public subnet value
tags = {
Name = "*subnet-public1*"
}
}
data "aws_vpc" "awshybrid"{
//just filtering on the AWS API value here (in the docs!)
filter {
name = "tag:${var.filter_tag}"
values = [var.filter_value]
}
}
data "aws_security_group" "awshybridsg"{
//filtering on VPC ID
//vpc_id = data.aws_vpc.awshybrid.id
filter {
name = "tag:${var.filter_tag}"
values = [var.filter_value]
}
}
variable "numberofservers"{
description = "How many servers do you want?"
type = number
default = 1
}
variable "numberofebs"{
description = "How many block devices per server do you want?: "
type = list(string)
//default = ["b", "c", "d", "e"]
//default = ["b", "c", "d", "e", "f", "g", "h", "i"]
default = ["b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]
}
variable "default_tags" {
//type = map(string)
description = "These are the default tags for the whole TF kits"
default = {
awshybrid: "true"
Terraform: "true"
Environment: "Prod"
Name: "hyperstore-master"
IsControlMaster: "Yes"
}
}
variable "default_tags2" {
description = "These are the default tags for the whole TF kits"
default = [{
key = "awshybrid"
value = "true"
propagate_at_launch = true
},
{
key = "IsControlMaster"
value = "Yes"
propagate_at_launch = true
},
{
key ="Name"
value = "hyperstore-master"
propagate_at_launch = true
},
]
}
### THIS VARIABLE IS IMPORTANT!
variable "projectname"{
description = "What are we calling this project?"
default = "awshybrid"
}
resource "aws_launch_configuration" "awshybridlaunchconfig"{
//image_id = "ami-0e7bad923e8155ef5" //This is a CentOS 7 image in us-west1 (north cali)
image_id = "ami-0ab8084342cdd196e" //THIS IS MY CENTOS snapshot with CentOS already installed, dated April 26th, no EBS volume snapshots
//image_id = "ami-073c8a29db8f7d0bc" //This is the 196e AMI that's been copied over to West-1
//using default tenancy (NOT dedicated)
//placement_tenancy = "dedicated"
placement_tenancy = "default"
instance_type = var.instance_type
security_groups = [data.aws_security_group.awshybridsg.id]
name = var.default_tags.Name
//name = "tf-launch-config-min"
key_name ="hyperstore-awshybrid_oregon"
user_data = <<-EOF
#!/bin/bash
#making root login OK!!!
sed -i 's/.*sleep 10\" //' /root/.ssh/authorized_keys
EOF
root_block_device {
volume_type = "gp2"
volume_size = "400"
delete_on_termination = true
}
/*
//this piece of code is a fancy look that will work through my drive letters to make the launch_configuration aware of how many drives are needed for the ASG
dynamic "ebs_block_device" {
for_each = var.numberofebs
content {
device_name = "/dev/xvd${ebs_block_device.value}"
volume_type = "standard"
volume_size = var.volume_size
delete_on_termination = true
}
}
*/
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "awshybridgroup"{
launch_configuration = aws_launch_configuration.awshybridlaunchconfig.name
name = var.default_tags.Name
desired_capacity = var.numberofservers
max_size = var.numberofservers
min_size = 0
vpc_zone_identifier = data.aws_subnet_ids.awshybrid.ids
lifecycle {
create_before_destroy = true
}
tags = var.default_tags2
/*
tag {
key = "Name"
value = var.projectname
//value = "deployawshybridcluster_prod"
propagate_at_launch = true
}
*/
}